• Resolved lfirth

    (@lfirth)


    I have added this snippet:

    $user = wp_get_current_user();
    function fww_hook_css() {
    ?>
    <style>
    #easy-support-videos-insert-video {
    display : none;
    }
    </style>
    <?php
    }
    if ( $user->user_login == ‘lfirth’ ) {
    add_action(‘wp_head’, ‘fww_hook_css’);
    }

    But it doesn’t seem to work.

    Any suggestions?

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

    (@bungeshea)

    I would recommend placing the user check inside the action hook, like this:

    add_action( 'wp_head', function () {
        $user = wp_get_current_user();
        if ( 'lfirth' !== $user->user_login ) {
            return;
        }
        ?>
    
        <style>
            #easy-support-videos-insert-video {
                display : none;
            }
        </style>
        
        <?php
    } );
    Thread Starter lfirth

    (@lfirth)

    Tried with your suggestion but it still doesn’t work.

    Thread Starter lfirth

    (@lfirth)

    OK on doing a little more research, if I set the snippet to “Run snippet everywhere” it works on the front end but not in the back end.

    Plugin Author Shea Bunge

    (@bungeshea)

    Yep, that’s how the wp_head hook works – it is specifically for adding code to the front-end of your site.

    Do you want the code to only run in the administration area? If so, you can alter it like so:

    add_action( 'admin_head', function () {
        $user = wp_get_current_user();
        if ( 'lfirth' !== $user->user_login ) {
            return;
        }
        ?>
    
        <style>
            #easy-support-videos-insert-video {
                display : none;
            }
        </style>
        
        <?php
    } );
    Thread Starter lfirth

    (@lfirth)

    That fixed it thanks.

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

The topic ‘Code to run for a specific user only’ is closed to new replies.