After searching for hours trying to figure out why the WordPress WYSIWYG code editor TinyMCE kept changing my PHP code I came upon a thread that was a somewhat helpful. Basically it let me set TinyMCE’s configuration in the WordPress theme which is great for all kinds of things, like if you want more HTML tags in your posts.
It’s got room for improvement, the line breaks don’t always line up correctly. For the <?php one for some reason you need to put an > on the first line. So for example the opening line of code would be <?php //> after doing this the editor doesn’t touch the line breaks.
This was tested on WordPress 4.5.3, your mileage may vary for versions further from this.
I just created a plugin based on this you can access here. Please note that you cannot use the plugin and this fix at the same time.