WP_Admin_Bar::_bind() –

You appear to be a bot. Output may be restricted

Description

Usage

$object|void = WP_Admin_Bar::_bind();

Parameters

Returns

object|void

Source

File name: wordpress/wp-includes/class-wp-admin-bar.php


Lines:

1 to 100 of 143
  final protected function _bind() {
    if ( $this->bound ) {
      return;
    }

    /*
		 * Add the root node.
		 * Clear it first, just in case. Don't mess with The Root.
		 */
    $this->WP_Admin_Bar::remove_node( 'root' );
    $this->WP_Admin_Bar::add_node(
      array(
        'id'    => 'root',
        'group' => false,
      )
    );

    // Normalize nodes: define internal 'children' and 'type' properties.
    foreach ( $this->WP_Admin_Bar::_get_nodes() as $node ) {
      $node->children = array();
      $node->type     = ( $node->group ) ? 'group' : 'item';
      unset( $node->group );

      // The Root wants your orphans. No lonely items allowed.
      if ( ! $node->parent ) {
        $node->parent = 'root';
      }
    }

    foreach ( $this->WP_Admin_Bar::_get_nodes() as $node ) {
      if ( 'root' === $node->id ) {
        continue;
      }

      // Fetch the parent node. If it isn't registered, ignore the node.
      $parent = $this->WP_Admin_Bar::_get_node( $node->parent );
      if ( ! $parent ) {
        continue;
      }

      // Generate the group class (we distinguish between top level and other level groups).
      $group_class = ( 'root' === $node->parent ) ? 'ab-top-menu' : 'ab-submenu';

      if ( 'group' === $node->type ) {
        if ( empty( $node->meta['class'] ) ) {
          $node->meta['class'] = $group_class;
        } else {
          $node->meta['class'] .= ' ' . $group_class;
        }
      }

      // Items in items aren't allowed. Wrap nested items in 'default' groups.
      if ( 'item' === $parent->type && 'item' === $node->type ) {
        $default_id = $parent->id . '-default';
        $default    = $this->WP_Admin_Bar::_get_node( $default_id );

        /*
				 * The default group is added here to allow groups that are
				 * added before standard menu items to render first.
				 */
        if ( ! $default ) {
          /*
					 * Use _set_node because add_node can be overloaded.
					 * Make sure to specify default settings for all properties.
					 */
          $this->WP_Admin_Bar::_set_node(
            array(
              'id'       => $default_id,
              'parent'   => $parent->id,
              'type'     => 'group',
              'children' => array(),
              'meta'     => array(
                'class' => $group_class,
              ),
              'title'    => false,
              'href'     => false,
            )
          );
          $default            = $this->WP_Admin_Bar::_get_node( $default_id );
          $parent->children[] = $default;
        }
        $parent = $default;

        /*
				 * Groups in groups aren't allowed. Add a special 'container' node.
				 * The container will invisibly wrap both groups.
				 */
      } elseif ( 'group' === $parent->type && 'group' === $node->type ) {
        $container_id = $parent->id . '-container';
        $container    = $this->WP_Admin_Bar::_get_node( $container_id );

        // We need to create a container for this group, life is sad.
        if ( ! $container ) {
          /*
					 * Use _set_node because add_node can be overloaded.
					 * Make sure to specify default settings for all properties.
					 */
          $this->WP_Admin_Bar::_set_node(
            array(
              'id'       => $container_id,

 View on GitHub View on Trac