• Hello,

    For automation purposes, I’m parsing the code of theme files using the theme editor at
    /wp-admin/theme-editor.php

    I see that there are two interesting elements inside the HTML code of the theme editor with a theme file loaded.

    The first being the textarea:
    <textarea cols="70" rows="30" name="newcontent" id="newcontent" aria-describedby="editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4" style="display: none;">

    The second is a mirror wrapper, as I understand, it is here to replicate the code of the textarea and put in form with colors, etc.
    <div class="CodeMirror cm-s-default CodeMirror-wrap">

    I’ve tried editing directly the code inside the textarea tag but after clicking save, it does say it is successfully updated, but after a refresh the old code is still there, the new code isn’t sent out inside the HTTP request (I checked it).

    So I thought that, even though it is a pain, I might need to edit both the textarea and the mirror wrapper with the new code, but even then it’s not changing anything.

    I feel like I’m missing something.

    Does someone have an idea of how the theme editor is doing things on the backside exactly?

    I was actually wondering if there were some sort of protection against unwanted modifications and that would be what is preventing me to do the changes directly into the HTML code.

    Thanks a lot!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    The editor screen does validate changes before committing them to the file. Assuming your changes were done correctly, I don’t know why they wouldn’t be committed to file.

    If you want to automate some sort of change in file content, you will be better off using native PHP file and string handling functions instead of working through the theme editor. You do have to be sure your changes are rock solid. If any sort of syntax error is introduced to an active theme file, it will crash the entire site.

    What is it that you want to automate? There are few good reasons to alter theme files. There is usually a better way to accomplish something.

    Thread Starter xhat

    (@xhat)

    Can you get a bit more into details about what kinds of validation it does before committing them? If you can refer to a piece of Javascript code I should be able to understand it.

    Well because of NDA I sadly can’t get into the details but the customer needs to automate some processes as he manages quite a lot of WordPress based website as I understood.

    Of course it would be easier to do it with PHP but the customer requirement is to do everything from the administration panel.

    Any help is really appreciated. I tried looking at the Javascript code of the theme editor but couldn’t find where is the validation occurring.

    Moderator bcworkz

    (@bcworkz)

    All I know is an implementation of CodeMirror is used, which has various linting modules (for CSS, JS and PHP in the case of theme editor) that ensures there are no syntax errors.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How WordPress handles code edition inside the Theme Editor ?’ is closed to new replies.