Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code_snippets/before_execute_snippet filter #25

signo opened this Issue May 16, 2015 · 1 comment


None yet
2 participants
Copy link

signo commented May 16, 2015

I implemented a must use plugin that allows me to recover from coding errors or disable plugins or the current theme for testing purposes, to do this i defined various options that are controlled by a parameter in the $_GET variable, one of them is an option to disable code snippets by defining CODE_SNIPPETS_SAFE_MODE as true, i was thinking to maybe extend this to disable a single snippet this way.

I suggest you add a filter that could allow to change the code before it is executed, this implementation requires that you also read the snippet id from the db, this filter would open the door to write code where i could check the snippet id and maybe return and empty string to not allow the snippet to execute depending of the situation.

        foreach ( $active_snippets as $snippet_id => $snippet_code ) {
            /* Execute the PHP code */
            execute_snippet( apply_filters( 'code_snippets/before_execute_snippet', '', $snippet_code, $snippet_id ) );

Now that i write down this idea, i don´t now if this filter could be a security problem, another approach would be to make the filter a switch, instead of changing the snippet code, the filter could return true/false to allow the snippet to execute.

        foreach ( $active_snippets as $snippet_id => $snippet_code ) {
            /* Execute the PHP code */
            if ( apply_filters( 'code_snippets/allow_execute_snippet', '', true, $snippet_id ) === true )
                execute_snippet( $snippet_code );

What do you think?

sheabunge added a commit that referenced this issue May 18, 2015


This comment has been minimized.

Copy link

sheabunge commented May 18, 2015

This is a great idea, thanks. I've decided to use the second method you suggested, though it seems like you have a bug with the '' parameter.

The old filter was really only added for the sake of having an action there; it didn't serve much useful purpose, so I've removed it.

@sheabunge sheabunge closed this May 19, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.