• I have used add_action('admin_bar_menu', 'modify_admin_bar') to change the admin bar on the “front end” of WordPress (the site the user sees). However, it seems that modify_admin_bar() is not called before the admin bar is rendered on the “back end” (the Dashboard or admin side of WordPress).

    How can I modify the admin bar as it is presented on the admin side of WordPress?

    Here’s an example…

    add_action( 'admin_bar_menu', 'modify_admin_bar');
    function modify_admin_bar() {
        error_log('admin barring');
    }

    In this example, my error log shows “admin barring” every time I refresh a page on the user side of WordPress, but never shows “admin barring” when I refresh the admin side (the Dashboard) of WordPress. It does not seem that the function gets called from the admin side. I am running WP 3.5, but have confirmed the same behavior in 3.4.2.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Seems to work for me (stripped out of some of my current work in progress, so sorry if I’ve missed a bit of code):

    class CommentsEncryptMain
    {
    	public function __construct()
    	{
    		$this->initScreens()
    	}
    
    	protected function initScreens()
    	{
    		// Set up handler for admin screen hook
    		add_action('admin_menu', array($this, 'screensHandler'));
    
    		// Set up handler for admin bar registration (100 = put menu item at the end of standard items)
    		add_action('admin_bar_menu', array($this, 'adminBarRegister'), 100);
    	}
    
    	public function adminBarRegister(WP_Admin_Bar $WpAdminBar)
    	{
    		$privKeySet = (bool) $_COOKIE[self::COOKIE_PRIV_KEY];
    
    		$WpAdminBar->add_menu(
    			array(
    				'id' => 'encdemo_key_status',
    				'title' => $privKeySet? 'Private key set' : 'Private key unknown',
    				'href' => 'edit-comments.php?page=xyz',
    			)
    		);
    	}
    }
    
    new CommentsEncryptMain();

    If that doesn’t help, can you confirm that your plugin is actually activated, and is called for admin screens?

    Thread Starter efc

    (@eceleste)

    @halferdev, you mention “and is called for admin screens.” How do I ensure a plugin is called for admin screens?

    I know my plugin is actually getting activated because I do get the proper entries in the error log when I reload user screens. But I’m getting nothing when admin screens load.

    Well, I dunno about the proper way, but if this is your plugin PHP file:

    <?php
    // Put this at the start of your plugin file
    echo "I got called!\n";

    Inelegant, but it works ??

    Thread Starter efc

    (@eceleste)

    That’s what the call to error_log() is, just a bit less intrusive. ??

    I can say for sure, my plugin is ONLY getting called for user screens. Nothing in my plugin gets executed when I’m on an admin screen.

    I wonder why?

    Thread Starter efc

    (@eceleste)

    Gosh, blush, I figured it out.

    error_log() on my system was writing to two different logs. One log for the user page, another log for the admin page.

    The plugin was working fine, I just could not see the log entries because I was looking at the wrong long.

    Sorry to bother you all! @halferdev, I appreciate your help. Your “echo” clue finally helped me see the problem.

    Ha ha, no worries! Glad you figured it out.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Can admin_bar_menu or another action be used to modify the Dashboard admin bar?’ is closed to new replies.