X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/wordpress.git/blobdiff_plain/a5227bf01edbe6660486c9f5c0f0ed7b7fea3130..f9001779751f83dc8a10e478bfecb4d8dd5f964c:/wp-includes/class-wp-admin-bar.php diff --git a/wp-includes/class-wp-admin-bar.php b/wp-includes/class-wp-admin-bar.php new file mode 100644 index 00000000..549d5ecf --- /dev/null +++ b/wp-includes/class-wp-admin-bar.php @@ -0,0 +1,236 @@ +proto = 'https://'; + + $this->user = new stdClass; + $this->menu = new stdClass; + + /* Populate settings we need for the menu based on the current user. */ + $this->user->blogs = get_blogs_of_user( get_current_user_id() ); + if ( is_multisite() ) { + $this->user->active_blog = get_active_blog_for_user( get_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[get_current_blog_id()]; + $this->user->domain = trailingslashit( home_url() ); + $this->user->account_domain = $this->user->domain; + } + $this->user->locale = get_locale(); + + add_action( 'wp_head', 'wp_admin_bar_header' ); + + add_action( 'admin_head', 'wp_admin_bar_header' ); + + if ( current_theme_supports( 'admin-bar' ) ) { + $admin_bar_args = get_theme_support( 'admin-bar' ); // add_theme_support( 'admin-bar', array( 'callback' => '__return_false') ); + $header_callback = $admin_bar_args[0]['callback']; + } + + if ( empty($header_callback) ) + $header_callback = '_admin_bar_bump_cb'; + + add_action('wp_head', $header_callback); + + wp_enqueue_script( 'admin-bar' ); + wp_enqueue_style( 'admin-bar' ); + + do_action( 'admin_bar_init' ); + } + + 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 => '', title => '' ); + ); + + $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() { + ?> +