user = new stdClass; $this->menu = new stdClass; /* Populate settings we need for the menu based on the current user. */ $this->user->blogs = get_ordered_blogs_of_user( $current_user->id ); if ( is_multisite() ) { $this->user->active_blog = get_active_blog_for_user( $current_user->id ); $this->user->domain = empty( $this->user->active_blog ) ? user_admin_url() : trailingslashit( get_home_url( $this->user->active_blog->blog_id ) ); $this->user->account_domain = $this->user->domain; } else { $this->user->active_blog = $this->user->blogs[$blog_id]; $this->user->domain = home_url(); $this->user->account_domain = home_url(); } $this->user->locale = get_locale(); } function add_menu( $args = array() ) { $defaults = array( 'title' => false, 'href' => false, 'parent' => false, // false for a root menu, pass the ID value for a submenu of that menu. 'id' => false, // defaults to a sanitized title value. 'meta' => false // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '' ); ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); if ( empty( $title ) ) return false; /* Make sure we have a valid ID */ if ( empty( $id ) ) $id = esc_attr( sanitize_title( trim( $title ) ) ); if ( !empty( $parent ) ) { /* Add the menu to the parent item */ $child = array( 'id' => $id, 'title' => $title, 'href' => $href ); if ( !empty( $meta ) ) $child['meta'] = $meta; $this->add_node( $parent, $this->menu, $child ); } else { /* Add the menu item */ $this->menu->{$id} = array( 'title' => $title, 'href' => $href ); if ( !empty( $meta ) ) $this->menu->{$id}['meta'] = $meta; } } function remove_menu( $id ) { return $this->remove_node( $id, $this->menu ); } function render() { ?>