• Using WP 7.0.2 and now WP Code 2.3.8 as of last night.

    Today, after updating a Snippet, it saves, shows correctly for a second, and then turns into HTML soup impossible to read or update thereafter.

    When trying to leave the page, I get asked “Leave or Stay on Page”, so clearly WPCode thinks it’s dirty and wants me to save the HTML mangled version, instead of the straight, correct, text version.

    I began SEEING that HTML rendering for the first time a version or two ago. But it would restore itself to regular text thereafter. Now it’s changing to HTML and staying that way!

    Brad

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support markomiljanovic

    (@markomiljanovic)

    Hi @bradfriedman,

    Thank you for reaching out and I’m sorry about the trouble here.

    That’s not expected behavior, after a save the editor should reload the snippet exactly as you stored it. What you’re describing looks like the snippet body getting HTML-encoded on its way back into the editor after the save response.

    To reproduce this on our end, could you send me the snippet code that triggers it along with the code type it’s set to (HTML, Text, JavaScript, PHP)? It would also help if you can share list of the other plugins active on the site, in case something else is contributing to this.

    If you’d prefer not to share the code here, you can send it privately through our contact form at https://wpcode.com/contact/ and just reference this conversation.

    Thanks,

    Thread Starter bradfriedman

    (@bradfriedman)

    Thanks, Marco. It’s happening with ALL of my Snippets. Not just one in particular. It began happening after the latest update of WP Code over the weekend. In a previous version, I began SEEING the HTML (versus the straight text) *briefly* appear after saving a snippet, though it would revert to the proper straight text thereafter.

    NOW, it is changing into HTML and staying that way.

    These are ALL PHP snippets.

    If you still need me to send a snippet, I can. Let me know. But, as noted, there is nothing unusual about the Snippets themselves, to my knowledge. Especially since it happens with ALL of them that I have updated in some way since upping to the latest WP Code.

    Thread Starter bradfriedman

    (@bradfriedman)

    Further update!

    I was curious as to whether one of our specific Snippets — which worked perfectly before, and that modified the Admin Editor page for our contributors — might be causing or part of the problem.

    I want to emphasize that all had been working perfectly UNTIL the latest WP Code update. So, it’s not like a snippet we just wrote caused the problem. But, rather, something that changed there conflicted with something we already had in place here.

    I asked Claude to look at that Admin Editor snippet and he saw what COULD be part of the problem. We made a change to it, and it fixed the display issue on SOME snippets (the simplest ones that were PHP only). But the more complex ones with mixed PHP, CSS, JS etc. were still garbled.

    I then asked Claude to put together a more fullsome explanation of all of that that would hopefully be more helpful on your end. Here’s what he put together for us:

    Bug Report for WPCode Support/Developers

    Summary: After updating WPCode to the latest version this past weekend, our snippet editor began displaying garbled/malformed HTML markup wrapped around our PHP snippet content (e.g., snippet code appearing wrapped in stray <p>, <li>, <blockquote> tags, with <, >, & HTML-entity-encoded). The underlying saved PHP is not corrupted — retrieving it via other means (e.g., pasting the “garbled” display text back to a text parser) confirms the actual code is intact; this is purely a display/rendering bug in the snippet editor itself.

    What we ruled out (and how):

    We initially suspected one of our own custom snippets — “BB WP Admin Editor Tools” — might be contributing, since it applies CSS overrides and JS to any WordPress post/post-new admin screen, and we realized WPCode’s own snippet-edit screen also registers as $screen->base === 'post' under the hood (since WPCode snippets are a custom post type using the same post.php admin page). That meant our snippet’s CodeMirror CSS overrides (forcing light theme, hiding line numbers/gear icon, custom syntax colors) and our admin_footer JS (Quicktags buttons, keyboard shortcuts) were very likely firing unintentionally on WPCode’s own snippet editor, not just our actual WordPress Post/Page editors.

    Our fix: We added a $screen->post_type check (in addition to the existing $screen->base check) so our overrides only fire when post_type is post or page — explicitly excluding WPCode’s snippet post type. Example of the change:

    php

    // BEFORE:
    add_action( 'admin_head', function() {
        $screen = get_current_screen();
        if ( ! $screen || ! in_array( $screen->base, array( 'post', 'post-new' ) ) ) return;
        // ... CodeMirror CSS overrides ...
    } );
    
    // AFTER:
    add_action( 'admin_head', function() {
        $screen = get_current_screen();
        if ( ! $screen || ! in_array( $screen->base, array( 'post', 'post-new' ) ) || ! in_array( $screen->post_type, array( 'post', 'page' ) ) ) return;
        // ... CodeMirror CSS overrides ...
    } );

    Result of our fix: This resolved the garbling on a simple, PHP-only snippet (our “BB WP Admin Editor Tools” snippet itself) — it now displays cleanly in the WPCode editor. However, it did not resolve the garbling on a separate, much larger snippet of ours (“BB Media Player Tool”) that mixes PHP with embedded HTML, <style> blocks, and <script> blocks, deeply nested with ob_start() output buffering and PHP short-echo tags inside HTML attributes. That snippet still displays with the same garbling symptoms even with our conflicting CSS/JS now properly scoped away from your editor screen.

    What this suggests: The remaining bug appears to be content-dependent — specifically correlated with snippet complexity/size and the mix of PHP + HTML + CSS + JS in a single snippet, rather than caused by any conflicting admin CSS on our end.

    Possible lead: Your recent changelog entry — “Tweak: You can now resize the code editor on the Live CSS Preview screen by dragging the divider between it and the preview, and it remembers the size you set” — introduces new resize-handling JS wired to the CodeMirror instance. It’s plausible that resize/refresh logic (e.g., recalculating line-wrapping, re-tokenizing visible content, or re-initializing the editor’s rendering on resize) behaves correctly on small/simple snippets but hits an edge case on large snippets with deeply mixed PHP/HTML/CSS/JS content — which would explain why our simple PHP-only snippet now renders fine while our large mixed-content snippet doesn’t.

    Suggested reproduction steps for your team:

    1. Create a WPCode PHP snippet containing multiple nested PHP functions that each echo or output-buffer large blocks of HTML, including inline <style> and <script> tags with their own nested quotes/brackets (i.e., a snippet in the 300+ line range mixing all four languages).
    2. Open it in the WPCode snippet editor.
    3. Observe whether the display renders correctly on load, then re-renders with stray HTML tags wrapped around the code and HTML entities in place of </>/& shortly after — this “renders correctly for a moment, then corrupts” behavior is what we’re seeing.
    4. Compare against a simple, PHP-only snippet of similar total length but without embedded HTML/CSS/JS, to see if the simple one is unaffected.

    We’re happy to provide the exact snippet content privately if it would help you reproduce this.

    Thread Starter bradfriedman

    (@bradfriedman)

    Was that info useful? Do you need me to send you one of the Snippets that is still mis-rendering after save?

    Plugin Support markomiljanovic

    (@markomiljanovic)

    Hi @bradfriedman,

    That’s really helpful, and you don’t need to send a snippet. I reproduced this on WordPress 7.0.2 here, so I can tell you exactly what’s going on.

    Alongside the code editor, our snippet screen also loads WordPress’s standard visual editor, invisible in the background, holding a copy of your snippet. It’s there for Text-type snippets. The problem is that whenever that hidden editor reports a change, we copy its contents into the code editor, and because it’s an HTML editor, it hands back an HTML version of your code. That’s the garbling you’re seeing: the stray <p> and <li> tags, and the <, > and & turned into entities.

    What makes it report a change on your site is your Admin Editor Tools snippet. Its admin JavaScript still runs on our screen, so it nudges that hidden editor, and we then overwrite your code with the HTML version. Your fix covered the admin_head part but not the admin_footer JavaScript, which is why some snippets still break. The snippets being garbled are not at fault, and their complexity makes no difference.

    We’re fixing it on our side by only allowing that hidden editor to write into the code editor when the snippet type is actually Text. For PHP, JavaScript, and CSS snippets, it will be disconnected entirely, so nothing on your site or anyone else’s can trigger this again. That’ll go out in an upcoming release.

    One thing to watch until then: don’t save while a snippet looks garbled, because that saves the mangled version over your working code. Reloading the page without saving is always safe.

    Thanks,

    Thread Starter bradfriedman

    (@bradfriedman)

    Thanks, Marko. Really appreciate the detailed reply.

    A few things worth flagging back to you. Before your message, we had already added $screen->post_type scoping to all three of our snippet’s functions — including the admin_footer block, not just admin_head — precisely because we suspected it could be nudging your snippet screen the way you describe. So that fix was already in place site-wide (Sandbox and on the Live site) when the Media Player Tool snippet started garbling.

    To test further, following your reply, we deactivated the Admin Editor Tools snippet entirely (not just scoped it) to test your theory that our tool was triggering the prob — and the Media Player Tool snippet *still* garbles on open/save. We also ruled out browser caching (hard refresh, no change) and I even pasted a fresh/clean copy of the Media Player Tool snippet, just in case I had accidentally saved a garbled version or something previously. (Which, of course, I have been trying NOT to do!)

    So it seems something other than our admin_footer JS is triggering this for us. Can you say more about what else might nudge that hidden Text-editor instance? Or is your upcoming release (disconnecting it entirely for non-Text snippet types) the real fix here regardless of root cause?

    Given the above, are you still confident that our snippet was the/a cause? We just want to make sure we’re not chasing the wrong lead on our end while waiting for your release.

    Thanks again for all!
    Brad

    Plugin Support markomiljanovic

    (@markomiljanovic)

    Hi @bradfriedman,

    Thanks for testing that so carefully!

    I also went back through the 2.3.8 code. Nothing in that release fires this, and the resize change can’t even reach the snippet editor screen, so the update didn’t introduce the trigger either.

    What it did change is timing. Our screen has two handlers racing each other: one copies the hidden HTML editor’s version into your code editor, the other copies the correct stored code back. Whichever runs last wins. That would explain why you used to see HTML flash and then revert, and why it now sticks, meaning the trigger was already present on your site before the update, and only the order changed.

    As for what can nudge it: any admin JavaScript that fires an input or change event on that hidden editor. Another plugin is possible, but browser extensions that attach to editable fields are a common source of exactly that kind of event, Grammarly, password managers and translation extensions all do it. Worth a quick test: open one of the garbling snippets in a private window with extensions disabled and see if it behaves.

    And to your main question, yes. Disconnecting that editor for non-Text snippets fixes this regardless of what’s triggering it on your site.

    Thanks,

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.