Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

In functions.php of a theme makes a call to show_admin_bar(false) which hides admin bar in front end:

if (!is_admin())
{
    wp_deregister_style( 'bp-admin-bar' );
    if ( function_exists( 'show_admin_bar' ) )
    {
        show_admin_bar( false );
        remove_action( 'bp_init', 'bp_core_load_buddybar_css' );
    }
}

I want to make admin bar appear in front end for the admin users. To do this, I added the following code to a plugin:

add_action('plugins_loaded', 'show_admin_bar_to_admins', 100);
function show_admin_bar_to_admins()
{
    if (current_user_can('manage_options')) {
        show_admin_bar(true);
    }
}

But this call didn't make a difference. I put 100 as the priority value such in order to make this function to be called later than the call inside functions.php. But it didn't make a difference.

Is there a way to make a function call inside a plugin to be executed later than the call inside functions.php.

share|improve this question

2 Answers 2

up vote 6 down vote accepted

First off: This Theme is so doing it wrong. One should not simply stuff plain calls in functions.php files. Those should be wrapped and hook. Best to after_setup_theme(). You could btw try the same hook.

share|improve this answer
3  
+1 for "doing it wrong" –  s_ha_dum Feb 1 '13 at 16:18

I think the best way to show or hide the admin bar is by hooking into show_admin_bar filter, and specifying the conditions you need in the filter function:

add_filter('show_admin_bar', 'ad_show_admin_bar');

function ad_show_admin_bar($show) {
    // show front-end admin bar for admins only
    if(current_user_can('manage_options')) {
        return true;
    } else {
        return false;
    }
}

This will take care of adding necessary scripts and styles for the admin bar as well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.