• Resolved peopleinside

    (@peopleinside)


    Hi, thank you for this nice plugin.
    I found a defect for me and is that if I create a snippet, switch the toggle to activate and save and an error is generated the snippet is lost. Going back on the browser never help to recovery it.

    Also WordPress send an email of fatal error. Could you not improve the plugin behavior in the case of a problematic snippet that has a code issue avoiding loosing all code and maybe avoid WordPress send a recovery email? I’m migrating from another snippet plugin that if I was not wrong, never do if the code i wrong, it imply alert you with an error message in the admin backend without change page and made your code lost.

    Thank you

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

    (@markomiljanovic)

    Hi @peopleinside,

    Thank you for contacting us, and I’m sorry to hear you’re experiencing this issue.

    WPCode actually does have built-in protection for this. When you activate a snippet, it runs an activation check that executes the code first, and if it detects a fatal error, it blocks activation so the bad code can’t take your site down. The catch is the order of operations in your workflow: when you toggle the snippet to active and save at the same moment, the code runs during that same save request, so the fatal error can interrupt the request before the snippet finishes saving, which is why it feels like the code is lost.

    The simple fix is to save first, activate second. Create your snippet, leave the toggle set to inactive, and click Save. That stores your code safely no matter what. Then flip the toggle to active, at that point, WPCode runs its check, and if the code has a fatal error, it will refuse to activate and show you the error right in the admin. Your code stays intact and editable so you can fix it.

    As for the email, that’s actually WordPress core’s own “recovery mode” notification, not something WPCode sends.

    Let me know if I can provide more info.

    Thanks,

    Thread Starter peopleinside

    (@peopleinside)

    Hi, thank you for the reply!
    The workflow suggested by you seems to me not very logic.

    While I’m creating a snippet if I just switch the toggle to have the snippet active this will be not affected without a saving so if the snippet is not existent and has not been saved.

    You suggest to save the snippet then activate it but so need to save again, if not I still consider this workflow not very logic.

    Plugin Support markomiljanovic

    (@markomiljanovic)

    Hi @peopleinside,

    Thanks for following up.

    The reason it can’t simply save your code when there’s an error comes down to how our protection works. When you save an active snippet, WPCode runs the code to ensure it won’t break your site. If that code would cause a fatal error, the execution is stopped right there to protect your site. Since this is a brand-new snippet that hasn’t been written to the database yet, stopping that process also interrupts the save itself. It’s the safety mechanism doing its job, albeit with the unfortunate side effect you encountered.

    That said, we fully agree this experience can be better. Ideally, the snippet should save regardless and simply show you the error in the admin, ensuring nothing is ever lost. We’ll look into it and consider making this change. In the meantime, saving the snippet inactive first will reliably keep your code safe since saving without activating skips the code execution entirely.

    Let me know if I can help with anything else!

    Thanks,

    Thread Starter peopleinside

    (@peopleinside)

    Thank you, that’s it!
    The protection is a good things but maybe the error should not made all input done lost because an error on the code that sometimes can be just a PHP aperture forget that should be not there.

    Thank you for the workaround at the moment, I was thought about save then activate by myself but just decided to report the behavior here so maybe the code of the plugin can be improved.

    Thank you!

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

You must be logged in to reply to this topic.