wp/wp-includes/class-wp-admin-bar.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    16 	private $nodes = array();
    16 	private $nodes = array();
    17 	private $bound = false;
    17 	private $bound = false;
    18 	public $user;
    18 	public $user;
    19 
    19 
    20 	/**
    20 	/**
       
    21 	 * @since 3.3.0
       
    22 	 *
    21 	 * @param string $name
    23 	 * @param string $name
    22 	 * @return string|array|void
    24 	 * @return string|array|void
    23 	 */
    25 	 */
    24 	public function __get( $name ) {
    26 	public function __get( $name ) {
    25 		switch ( $name ) {
    27 		switch ( $name ) {
    31 				return array(); // Sorry, folks.
    33 				return array(); // Sorry, folks.
    32 		}
    34 		}
    33 	}
    35 	}
    34 
    36 
    35 	/**
    37 	/**
       
    38 	 * Initializes the admin bar.
       
    39 	 *
       
    40 	 * @since 3.1.0
    36 	 */
    41 	 */
    37 	public function initialize() {
    42 	public function initialize() {
    38 		$this->user = new stdClass;
    43 		$this->user = new stdClass;
    39 
    44 
    40 		if ( is_user_logged_in() ) {
    45 		if ( is_user_logged_in() ) {
    80 		 */
    85 		 */
    81 		do_action( 'admin_bar_init' );
    86 		do_action( 'admin_bar_init' );
    82 	}
    87 	}
    83 
    88 
    84 	/**
    89 	/**
    85 	 * Add a node (menu item) to the Admin Bar menu.
    90 	 * Adds a node (menu item) to the admin bar menu.
    86 	 *
    91 	 *
    87 	 * @since 3.3.0
    92 	 * @since 3.3.0
    88 	 *
    93 	 *
    89 	 * @param array $node The attributes that define the node.
    94 	 * @param array $node The attributes that define the node.
    90 	 */
    95 	 */
    91 	public function add_menu( $node ) {
    96 	public function add_menu( $node ) {
    92 		$this->add_node( $node );
    97 		$this->add_node( $node );
    93 	}
    98 	}
    94 
    99 
    95 	/**
   100 	/**
    96 	 * Remove a node from the admin bar.
   101 	 * Removes a node from the admin bar.
    97 	 *
   102 	 *
    98 	 * @since 3.1.0
   103 	 * @since 3.1.0
    99 	 *
   104 	 *
   100 	 * @param string $id The menu slug to remove.
   105 	 * @param string $id The menu slug to remove.
   101 	 */
   106 	 */
   177 
   182 
   178 		$this->_set_node( $args );
   183 		$this->_set_node( $args );
   179 	}
   184 	}
   180 
   185 
   181 	/**
   186 	/**
       
   187 	 * @since 3.3.0
       
   188 	 *
   182 	 * @param array $args
   189 	 * @param array $args
   183 	 */
   190 	 */
   184 	final protected function _set_node( $args ) {
   191 	final protected function _set_node( $args ) {
   185 		$this->nodes[ $args['id'] ] = (object) $args;
   192 		$this->nodes[ $args['id'] ] = (object) $args;
   186 	}
   193 	}
   187 
   194 
   188 	/**
   195 	/**
   189 	 * Gets a node.
   196 	 * Gets a node.
       
   197 	 *
       
   198 	 * @since 3.3.0
   190 	 *
   199 	 *
   191 	 * @param string $id
   200 	 * @param string $id
   192 	 * @return object|void Node.
   201 	 * @return object|void Node.
   193 	 */
   202 	 */
   194 	final public function get_node( $id ) {
   203 	final public function get_node( $id ) {
   197 			return clone $node;
   206 			return clone $node;
   198 		}
   207 		}
   199 	}
   208 	}
   200 
   209 
   201 	/**
   210 	/**
       
   211 	 * @since 3.3.0
       
   212 	 *
   202 	 * @param string $id
   213 	 * @param string $id
   203 	 * @return object|void
   214 	 * @return object|void
   204 	 */
   215 	 */
   205 	final protected function _get_node( $id ) {
   216 	final protected function _get_node( $id ) {
   206 		if ( $this->bound ) {
   217 		if ( $this->bound ) {
   215 			return $this->nodes[ $id ];
   226 			return $this->nodes[ $id ];
   216 		}
   227 		}
   217 	}
   228 	}
   218 
   229 
   219 	/**
   230 	/**
       
   231 	 * @since 3.3.0
       
   232 	 *
   220 	 * @return array|void
   233 	 * @return array|void
   221 	 */
   234 	 */
   222 	final public function get_nodes() {
   235 	final public function get_nodes() {
   223 		$nodes = $this->_get_nodes();
   236 		$nodes = $this->_get_nodes();
   224 		if ( ! $nodes ) {
   237 		if ( ! $nodes ) {
   230 		}
   243 		}
   231 		return $nodes;
   244 		return $nodes;
   232 	}
   245 	}
   233 
   246 
   234 	/**
   247 	/**
       
   248 	 * @since 3.3.0
       
   249 	 *
   235 	 * @return array|void
   250 	 * @return array|void
   236 	 */
   251 	 */
   237 	final protected function _get_nodes() {
   252 	final protected function _get_nodes() {
   238 		if ( $this->bound ) {
   253 		if ( $this->bound ) {
   239 			return;
   254 			return;
   241 
   256 
   242 		return $this->nodes;
   257 		return $this->nodes;
   243 	}
   258 	}
   244 
   259 
   245 	/**
   260 	/**
   246 	 * Add a group to a toolbar menu node.
   261 	 * Adds a group to a toolbar menu node.
   247 	 *
   262 	 *
   248 	 * Groups can be used to organize toolbar items into distinct sections of a toolbar menu.
   263 	 * Groups can be used to organize toolbar items into distinct sections of a toolbar menu.
   249 	 *
   264 	 *
   250 	 * @since 3.3.0
   265 	 * @since 3.3.0
   251 	 *
   266 	 *
   265 	}
   280 	}
   266 
   281 
   267 	/**
   282 	/**
   268 	 * Remove a node.
   283 	 * Remove a node.
   269 	 *
   284 	 *
       
   285 	 * @since 3.1.0
       
   286 	 *
   270 	 * @param string $id The ID of the item.
   287 	 * @param string $id The ID of the item.
   271 	 */
   288 	 */
   272 	public function remove_node( $id ) {
   289 	public function remove_node( $id ) {
   273 		$this->_unset_node( $id );
   290 		$this->_unset_node( $id );
   274 	}
   291 	}
   275 
   292 
   276 	/**
   293 	/**
       
   294 	 * @since 3.3.0
       
   295 	 *
   277 	 * @param string $id
   296 	 * @param string $id
   278 	 */
   297 	 */
   279 	final protected function _unset_node( $id ) {
   298 	final protected function _unset_node( $id ) {
   280 		unset( $this->nodes[ $id ] );
   299 		unset( $this->nodes[ $id ] );
   281 	}
   300 	}
   282 
   301 
   283 	/**
   302 	/**
       
   303 	 * @since 3.1.0
   284 	 */
   304 	 */
   285 	public function render() {
   305 	public function render() {
   286 		$root = $this->_bind();
   306 		$root = $this->_bind();
   287 		if ( $root ) {
   307 		if ( $root ) {
   288 			$this->_render( $root );
   308 			$this->_render( $root );
   289 		}
   309 		}
   290 	}
   310 	}
   291 
   311 
   292 	/**
   312 	/**
       
   313 	 * @since 3.3.0
       
   314 	 *
   293 	 * @return object|void
   315 	 * @return object|void
   294 	 */
   316 	 */
   295 	final protected function _bind() {
   317 	final protected function _bind() {
   296 		if ( $this->bound ) {
   318 		if ( $this->bound ) {
   297 			return;
   319 			return;
   424 		$this->bound = true;
   446 		$this->bound = true;
   425 		return $root;
   447 		return $root;
   426 	}
   448 	}
   427 
   449 
   428 	/**
   450 	/**
       
   451 	 * @since 3.3.0
       
   452 	 *
   429 	 * @param object $root
   453 	 * @param object $root
   430 	 */
   454 	 */
   431 	final protected function _render( $root ) {
   455 	final protected function _render( $root ) {
   432 		// Add browser classes.
   456 		// Add browser classes.
   433 		// We have to do this here since admin bar shows on the front end.
   457 		// We have to do this here since admin bar shows on the front end.
   455 
   479 
   456 		<?php
   480 		<?php
   457 	}
   481 	}
   458 
   482 
   459 	/**
   483 	/**
       
   484 	 * @since 3.3.0
       
   485 	 *
   460 	 * @param object $node
   486 	 * @param object $node
   461 	 */
   487 	 */
   462 	final protected function _render_container( $node ) {
   488 	final protected function _render_container( $node ) {
   463 		if ( 'container' !== $node->type || empty( $node->children ) ) {
   489 		if ( 'container' !== $node->type || empty( $node->children ) ) {
   464 			return;
   490 			return;
   470 		}
   496 		}
   471 		echo '</div>';
   497 		echo '</div>';
   472 	}
   498 	}
   473 
   499 
   474 	/**
   500 	/**
       
   501 	 * @since 3.3.0
       
   502 	 *
   475 	 * @param object $node
   503 	 * @param object $node
   476 	 */
   504 	 */
   477 	final protected function _render_group( $node ) {
   505 	final protected function _render_group( $node ) {
   478 		if ( 'container' === $node->type ) {
   506 		if ( 'container' === $node->type ) {
   479 			$this->_render_container( $node );
   507 			$this->_render_container( $node );
   495 		}
   523 		}
   496 		echo '</ul>';
   524 		echo '</ul>';
   497 	}
   525 	}
   498 
   526 
   499 	/**
   527 	/**
       
   528 	 * @since 3.3.0
       
   529 	 *
   500 	 * @param object $node
   530 	 * @param object $node
   501 	 */
   531 	 */
   502 	final protected function _render_item( $node ) {
   532 	final protected function _render_item( $node ) {
   503 		if ( 'item' !== $node->type ) {
   533 		if ( 'item' !== $node->type ) {
   504 			return;
   534 			return;
   594 		_deprecated_function( __METHOD__, '3.3.0', 'WP_Admin_bar::render(), WP_Admin_Bar::_render_item()' );
   624 		_deprecated_function( __METHOD__, '3.3.0', 'WP_Admin_bar::render(), WP_Admin_Bar::_render_item()' );
   595 		$this->_render_item( $node );
   625 		$this->_render_item( $node );
   596 	}
   626 	}
   597 
   627 
   598 	/**
   628 	/**
       
   629 	 * Adds menus to the admin bar.
       
   630 	 *
       
   631 	 * @since 3.1.0
   599 	 */
   632 	 */
   600 	public function add_menus() {
   633 	public function add_menus() {
   601 		// User-related, aligned right.
   634 		// User-related, aligned right.
   602 		add_action( 'admin_bar_menu', 'wp_admin_bar_my_account_menu', 0 );
   635 		add_action( 'admin_bar_menu', 'wp_admin_bar_my_account_menu', 0 );
   603 		add_action( 'admin_bar_menu', 'wp_admin_bar_search_menu', 4 );
   636 		add_action( 'admin_bar_menu', 'wp_admin_bar_search_menu', 4 );
   607 		// Site-related.
   640 		// Site-related.
   608 		add_action( 'admin_bar_menu', 'wp_admin_bar_sidebar_toggle', 0 );
   641 		add_action( 'admin_bar_menu', 'wp_admin_bar_sidebar_toggle', 0 );
   609 		add_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 );
   642 		add_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 );
   610 		add_action( 'admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20 );
   643 		add_action( 'admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20 );
   611 		add_action( 'admin_bar_menu', 'wp_admin_bar_site_menu', 30 );
   644 		add_action( 'admin_bar_menu', 'wp_admin_bar_site_menu', 30 );
       
   645 		add_action( 'admin_bar_menu', 'wp_admin_bar_edit_site_menu', 40 );
   612 		add_action( 'admin_bar_menu', 'wp_admin_bar_customize_menu', 40 );
   646 		add_action( 'admin_bar_menu', 'wp_admin_bar_customize_menu', 40 );
   613 		add_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 50 );
   647 		add_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 50 );
   614 
   648 
   615 		// Content-related.
   649 		// Content-related.
   616 		if ( ! is_network_admin() && ! is_user_admin() ) {
   650 		if ( ! is_network_admin() && ! is_user_admin() ) {