I have an admin page in my plugin where I want to show a balance figure in the admin bar. This works fine for the most part:

// in the __construct method    
add_action('admin_bar_menu', array($this, 'admin_bar_item'), 999);

// the method itself
function admin_bar_item($wp_admin_bar){
    $userid = get_current_user_id();
    $display = $this->balance($userid);
    $args = array(
                'id'    => 'balance',
                'title' => $display,
                'href'  => 'http://mysite.com/my-page/',
                'meta'  => array('class' => 'balance_link')

The problem comes when the user does something to update their balance on the admin page - using a <form> and $_POST-ing the update. The admin bar fires too soon meaning that the balance displayed in the admin bar is the balance before the $_POSTed amount is processed. I've tried increasing the priority in the add_action hook to 9999999 but it doesn't make any difference. I don't know what else to try. How can I make rendering the admin bar the very last thing to happen?

  • You can't very easily, really. Wouldn't a better solution be to process the form earlier?
    – engelen
    Jun 11, 2014 at 13:51
  • Possibly. What's the best method for doing that?
    – user417627
    Jun 11, 2014 at 13:59
  • On what hook are you currently handling the $_POST data?
    – engelen
    Jun 11, 2014 at 14:04
  • add_submenu_page which calls the method for rendering the page. The first part of the method called is if (isset($_POST['submit'])) { /* process form */ }
    – user417627
    Jun 11, 2014 at 14:10
  • 1
    Then I would suggest moving that to the init action, for example. There's no reason for processing the data that late :-).
    – engelen
    Jun 11, 2014 at 14:13


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.