• Sometimes deactivating of a snippet fails. That might cause that the it is not possible to active/deactivate a problematic snippet.
    That can be easily tested.

    1. Create a snippet, which has your own function definition.
    2. Make duplicate of it.
    3. Activate the duplicate
    4. Try to deactive the original snippet or duplicate

    Trying to deactivate the original snippet or a duplicate fails always. I have always needed cPanel > phpMyAdmin in order to deactive a snippet by editing single database record.

    If user don’t have direct database access, this is a serious problem. With some way it should be possible always to deactivate plugin without needing to use direct database access.

    https://www.sanaristikkofoorumi.net/wordpress/wp-content/uploads/2019-11-25-09.37.33-www.sanaristikkofoorumi.net-42c6cbb126f7.png

    is very risky way to change between activate/deactivate because deactivating can easily fails, which cause much problems. This kind of button looks nice but two buttons would be much smaller risk, because two buttons works much more reliable.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    If you create a snippet with a named function definition in it, then you shouldn’t duplicate and activate it without modification. Named functions can very easily cause collisions, and an exact duplicate will definitely cause an error.

    The button style is purely for aesthetic purposes. In reality it’s still just a link to a HTTP URL which will perform the activation or deactivation. A simple button or link would perform exactly the same.

    Additionally, direct database access is not required – there are multiple ways built into the plugin to temporarily prevent problematic snippets from executing to regain site access. You can even do this without editing any sites at all, as is explained in the pinned thread.

    The solution here is twofold:

    1. Don’t blindly duplicate and activate snippets without ensuring that they will not cause code errors.
    2. Avoid using named functions wherever possible – in most cases, anonymous functions are a better choice.

    Thread Starter tapiohuuhaa

    (@tapiohuuhaa)

    setting define(‘CODE_SNIPPETS_SAFE_MODE’, true);

    is easier than accessing database.
    It would be however nice, if it would be possible to deactive a snippet, which was by accident activated.

    Plugin Author Shea Bunge

    (@bungeshea)

    I’m not really sure what you mean. How would the site know whether a snippet has been activated by accident?

    An easier method than setting the constant is just appending &snippets-safe-mode=1 to the current URL, ideal for a quick fix.

    Thread Starter tapiohuuhaa

    (@tapiohuuhaa)

    In the single button, which has round corners, changing deactivate/activate can easily fail, why by accident an unwanted snippet is activated.

    Plugin Author Shea Bunge

    (@bungeshea)

    Ah okay, I see what you’re saying. How would you improve on the current design to make it a little more user-friendly?

    Thread Starter tapiohuuhaa

    (@tapiohuuhaa)

    I just don’t know. The current method looks good but it does have disadvantage.

    Plugin Author Shea Bunge

    (@bungeshea)

    Hi @tapiohuuhaa,

    I thought a bit more about your suggestions and I think I’ve found what is hopefully a helpful solution. I’ve written a basic validator which essentially goes through the snippet code and looks to see if it defines any functions or classes which already exist.

    Now when you click on an activate button it will run the code through this validator before doing the activation. If it fails, you’ll see an error icon instead of the snippet being activated.

    Here’s a demo of how that looks:

    View post on imgur.com

    Thread Starter tapiohuuhaa

    (@tapiohuuhaa)

    ok

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Problem with deactivate and activate a snippet’ is closed to new replies.