• Resolved amadhav1

    (@amadhav1)


    I was wondering if you could help me with a plugin I am building. I am taking some functions that we would want even if we moved to a different theme, and moving the functions to a plugin. All of the plugins work except for one, and I have narrowed it down to my use of if(!is_super_admin()){}. This is what I have:

    if ( !is_super_admin() ) {
    add_action( ‘wp_before_admin_bar_render’, ‘admin_bar_hide’ );
    add_action(‘admin_menu’, ‘customize_admin_menu_hide’, 999);
    add_action( ‘wp_before_admin_bar_render’, ‘wpse200296_before_admin_bar_render’ );
    add_action(‘admin_menu’, ‘hide_acf’);
    add_filter(‘tiny_mce_before_init’, ‘myformatTinyMCE’);
    }

    If I use this in the functions.php it works fine, but if I use this in a plugin it breaks. If I remove the “if ( !is_super_admin() ) {“ I can get it to work, have you ever used is_super_admin in a plugin?

    This is the error I am getting: “PHP Fatal error: Call to undefined function wp_get_current_user() in /var/www/sites/hsa-dev/wp-includes/capabilities.php on line 715”

    Thanks,

    Aaron

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Plugins load fairly early, when WP is not yet stable. To use is_super_admin(), you would need to hook an action that fires later on, something like “after_theme_setup”. Within that callback you can use this function and add the other hooks. I’m assuming none of those hooks you are adding fire before “after_theme_setup”. There would be no point in adding a hook after the action has already fired ??

    Thread Starter amadhav1

    (@amadhav1)

    Thanks a lot, I used after_theme_setup and it works great.

    Thanks again.

    Aaron

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘using is_super_admin() in a plugin’ is closed to new replies.