WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does WP Multisite require a specific function in order to programmatically add a menu item to a menu?

A friend and I have a plugin that adds a menu item to your menu found here. When we created it we assumed it would work with WordPress Multisite, but the few users who have tried it have had difficulty.

One guy got a fatal error which doesn't seem to be related: Fatal error: Call to undefined function wp_get_current_user() in /home/cmnet/public_html/wp-includes/capabilities.php on line 1451.

Another got it to show up, but said that it "crashed" I.E. and not all of the menu displayed.

Here's how we're currently doing this, but is there something we need to change to make this work with WordPress multisite.


if ( isset( $this->options['menu_name_1'] ) && $this->options['menu_name_1'] != '0' ) {
                    add_filter( 'wp_nav_menu_' . $this->options['menu_name_1'] . '_items', array( &$this, 'add_itemcart_to_menu' ) , 10, 2 );


public function add_itemcart_to_menu( $items ) {
            $classes = 'wpmenucart-display-'.$this->options['items_alignment'];

            if ($this->get_common_li_classes($items) != '')
                    $classes .= ' ' . $this->get_common_li_classes($items);

            $classes .= (isset($this->options['custom_class']) && $this->options['custom_class'] != '') ? sprintf( ' %s', $this->options['custom_class'] ) : '';

            // Filtering done here (instead of in function) to prevent issues with ajax
            $wpmenucart_menu_item = apply_filters( 'wpmenucart_menu_item_filter', $this->wpmenucart_menu_item() );

            $item_data = $this->shop->menu_item();

            if ($item_data['cart_contents_count'] > 0 || isset($this->options['always_display'])) {
                    $items .= '<li class="'.$classes.'">' . $wpmenucart_menu_item . '</li>';

            return $items;
share|improve this question
Maybe you are calling that function too early? There are no differences between single and multi-site for menus. – toscho May 9 '13 at 5:01
What exactly are the differences between single and multi-site menus? – Jeremiah Prummer May 9 '13 at 5:05
Sorry, I forgot an important no. Fixed my comment. :) – toscho May 9 '13 at 5:06
Oh, okay. :) Thanks for your help. I don't see how using the plugins_loaded action would make a difference, but I'll investigate that further. Also, We've had nearly 10k downloads. If it was an issue with the function being called too early, it would affect single site installs as well, wouldn't it? – Jeremiah Prummer May 9 '13 at 5:09

Your Answer


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

Browse other questions tagged or ask your own question.