X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/38ca813a0e312e2768e5b9519f0415cd0aa84781..8a4706fdeb1ae30268e510df6ccf3c39b3028059:/wp-includes/class-wp-admin-bar.php?ds=sidebyside
diff --git a/wp-includes/class-wp-admin-bar.php b/wp-includes/class-wp-admin-bar.php
index 7db0fa22..f8ee5e2d 100644
--- a/wp-includes/class-wp-admin-bar.php
+++ b/wp-includes/class-wp-admin-bar.php
@@ -1,31 +1,45 @@
proto = 'https://';
+ private $nodes = array();
+ private $bound = false;
+ public $user;
+
+ public function __get( $name ) {
+ switch ( $name ) {
+ case 'proto' :
+ return is_ssl() ? 'https://' : 'http://';
+ break;
+ case 'menu' :
+ _deprecated_argument( 'WP_Admin_Bar', '3.3', 'Modify admin bar nodes with WP_Admin_Bar::get_node(), WP_Admin_Bar::add_node(), and WP_Admin_Bar::remove_node(), not the menu
property.' );
+ return array(); // Sorry, folks.
+ break;
+ }
+ }
+ public function initialize() {
$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;
+
+ if ( is_user_logged_in() ) {
+ /* 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' );
@@ -47,191 +61,430 @@ class WP_Admin_Bar {
do_action( 'admin_bar_init' );
}
- function add_menu( $args = array() ) {
+ public function add_menu( $node ) {
+ $this->add_node( $node );
+ }
+
+ public function remove_menu( $id ) {
+ $this->remove_node( $id );
+ }
+
+ /**
+ * Add a node to the menu.
+ *
+ * @param array $args - The arguments for each node.
+ * - id - string - The ID of the item.
+ * - title - string - The title of the node.
+ * - parent - string - The ID of the parent node. Optional.
+ * - href - string - The link for the item. Optional.
+ * - group - boolean - If the node is a group. Optional. Default false.
+ * - meta - array - Meta data including the following keys: html, class, onclick, target, title, tabindex.
+ */
+ public function add_node( $args ) {
+ // Shim for old method signature: add_node( $parent_id, $menu_obj, $args )
+ if ( func_num_args() >= 3 && is_string( func_get_arg(0) ) )
+ $args = array_merge( array( 'parent' => func_get_arg(0) ), func_get_arg(2) );
+
+ if ( is_object( $args ) )
+ $args = get_object_vars( $args );
+
+ // Ensure we have a valid title.
+ if ( empty( $args['id'] ) ) {
+ if ( empty( $args['title'] ) )
+ return;
+
+ _doing_it_wrong( __METHOD__, __( 'The menu ID should not be empty.' ), '3.3' );
+ // Deprecated: Generate an ID from the title.
+ $args['id'] = esc_attr( sanitize_title( trim( $args['title'] ) ) );
+ }
+
$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 => '' );
+ 'id' => false,
+ 'title' => false,
+ 'parent' => false,
+ 'href' => false,
+ 'group' => false,
+ 'meta' => array(),
);
- $r = wp_parse_args( $args, $defaults );
- extract( $r, EXTR_SKIP );
+ // If the node already exists, keep any data that isn't provided.
+ if ( $maybe_defaults = $this->get_node( $args['id'] ) )
+ $defaults = get_object_vars( $maybe_defaults );
- if ( empty( $title ) )
- return false;
+ // Do the same for 'meta' items.
+ if ( ! empty( $defaults['meta'] ) && ! empty( $args['meta'] ) )
+ $args['meta'] = wp_parse_args( $args['meta'], $defaults['meta'] );
- /* Make sure we have a valid ID */
- if ( empty( $id ) )
- $id = esc_attr( sanitize_title( trim( $title ) ) );
+ $args = wp_parse_args( $args, $defaults );
+
+ $back_compat_parents = array(
+ 'my-account-with-avatar' => array( 'my-account', '3.3' ),
+ 'my-blogs' => array( 'my-sites', '3.3' ),
+ );
- if ( ! empty( $parent ) ) {
- /* Add the menu to the parent item */
- $child = array( 'id' => $id, 'title' => $title, 'href' => $href );
+ if ( isset( $back_compat_parents[ $args['parent'] ] ) ) {
+ list( $new_parent, $version ) = $back_compat_parents[ $args['parent'] ];
+ _deprecated_argument( __METHOD__, $version, sprintf( 'Use %s
as the parent for the %s
admin bar node instead of %s
.', $new_parent, $args['id'], $args['parent'] ) );
+ $args['parent'] = $new_parent;
+ }
- if ( ! empty( $meta ) )
- $child['meta'] = $meta;
+ $this->_set_node( $args );
+ }
- $this->add_node( $parent, $this->menu, $child );
- } else {
- /* Add the menu item */
- $this->menu->{$id} = array( 'title' => $title, 'href' => $href );
+ final protected function _set_node( $args ) {
+ $this->nodes[ $args['id'] ] = (object) $args;
+ }
- if ( ! empty( $meta ) )
- $this->menu->{$id}['meta'] = $meta;
+ /**
+ * Gets a node.
+ *
+ * @return object Node.
+ */
+ final public function get_node( $id ) {
+ if ( $node = $this->_get_node( $id ) )
+ return clone $node;
+ }
+
+ final protected function _get_node( $id ) {
+ if ( $this->bound )
+ return;
+
+ if ( empty( $id ) )
+ $id = 'root';
+
+ if ( isset( $this->nodes[ $id ] ) )
+ return $this->nodes[ $id ];
+ }
+
+ final public function get_nodes() {
+ if ( ! $nodes = $this->_get_nodes() )
+ return;
+
+ foreach ( $nodes as &$node ) {
+ $node = clone $node;
}
+ return $nodes;
}
- function remove_menu( $id ) {
- return $this->remove_node( $id, $this->menu );
+ final protected function _get_nodes() {
+ if ( $this->bound )
+ return;
+
+ return $this->nodes;
}
- function render() {
- ?>
-