Support » Plugin: Code Snippets » Execute snippets: User roles / loaded admin pages as criteria

  • Resolved itsthomas


    Hi there,

    I think your most useful plugin would become even better with the ability to chose when a snippet is executed, judging by the role of the logged in user (right now, I would need a snippet to run only when the user is not an admin, for example) and the loaded admin page (for example, execute a snippet only on profile.php).

    Keep up the excellent work!


Viewing 3 replies - 1 through 3 (of 3 total)
  • NeoCrash


    I guess you can use something like
    if (!current_user_can(‘administrator’) && !is_admin()) {
    /*place your code here
    for no admin users*/

    Plugin Author Shea Bunge


    Hi Thomas,

    It’s possible to do this by adding some extra code to your snippets.

    For example, you can ensure a snippet will only run when the current user is not an admin by adding this code to the beginning of a snippet:

    if ( current_user_can( 'manage_options' ) ) {

    It’s also fairly simple to check whether the user is currently viewing the Profile admin menu:

    if ( ! isset( $GLOBALS['pagenow'] ) || 'profile.php' !== $GLOBALS['pagenow'] ) {

    Of course, you would want to set this snippet to run in the administration area only.

    This is something that I an unlikely to implement into the plugin with a user interface, as it can be achieved quite simply and neatly just using code. There are so many possible combinations that any interface designed for handling them would be very complex, and it would not really offer any sort of performance improvement.



    Thanks for getting back (to both of you)!

    I will use individual (extra) code snippets to accomplish my aim, just as you suggested.


Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Execute snippets: User roles / loaded admin pages as criteria’ is closed to new replies.