But the code is not highlighting and throws an error when hitting "Enter":

I think this error happens because of the incorrect mode calls order. "clike" mode should be loaded first and only after that "php" mode should be loaded. So I tried to change the order in CodeLanguage class:

XenForo developer

I'm not totally sure I understand exactly how this was working with any of the modes, such as the ones you identified that work without issue. There's nothing in the JS that explicitly sets the mode so there must be some sort of magic that happens with some modes but not others, otherwise code editing/syntax highlighting will never have worked. The exception perhaps being when using the rich text editor code editor, which dynamically loads the selected modes in anyway.

Regardless, the solution is mostly to just add mode: this.options.mode into the Code Mirror initialisation and that sorts it. Though I have made some other changes.

I consciously decided that the PHP mode should only be PHP syntax highlighting, rather than being mixed, but I think that decision was perhaps a bit harsh (after all, a lot of people do still use HTML inline within PHP) so the PHP mode now loads all of these, with a different mime type: