Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (7 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-admin-bar.php

    r42131 r42343  
    2424    public function __get( $name ) {
    2525        switch ( $name ) {
    26             case 'proto' :
     26            case 'proto':
    2727                return is_ssl() ? 'https://' : 'http://';
    2828
    29             case 'menu' :
     29            case 'menu':
    3030                _deprecated_argument( 'WP_Admin_Bar', '3.3.0', 'Modify admin bar nodes with WP_Admin_Bar::get_node(), WP_Admin_Bar::add_node(), and WP_Admin_Bar::remove_node(), not the <code>menu</code> property.' );
    3131                return array(); // Sorry, folks.
     
    4242            $this->user->blogs = get_blogs_of_user( get_current_user_id() );
    4343            if ( is_multisite() ) {
    44                 $this->user->active_blog = get_active_blog_for_user( get_current_user_id() );
    45                 $this->user->domain = empty( $this->user->active_blog ) ? user_admin_url() : trailingslashit( get_home_url( $this->user->active_blog->blog_id ) );
     44                $this->user->active_blog    = get_active_blog_for_user( get_current_user_id() );
     45                $this->user->domain         = empty( $this->user->active_blog ) ? user_admin_url() : trailingslashit( get_home_url( $this->user->active_blog->blog_id ) );
    4646                $this->user->account_domain = $this->user->domain;
    4747            } else {
    48                 $this->user->active_blog = $this->user->blogs[get_current_blog_id()];
    49                 $this->user->domain = trailingslashit( home_url() );
     48                $this->user->active_blog    = $this->user->blogs[ get_current_blog_id() ];
     49                $this->user->domain         = trailingslashit( home_url() );
    5050                $this->user->account_domain = $this->user->domain;
    5151            }
     
    6161             * add_theme_support( 'admin-bar', array( 'callback' => '__return_false' ) );
    6262             */
    63             $admin_bar_args = get_theme_support( 'admin-bar' );
     63            $admin_bar_args  = get_theme_support( 'admin-bar' );
    6464            $header_callback = $admin_bar_args[0]['callback'];
    6565        }
    6666
    67         if ( empty($header_callback) )
     67        if ( empty( $header_callback ) ) {
    6868            $header_callback = '_admin_bar_bump_cb';
    69 
    70         add_action('wp_head', $header_callback);
     69        }
     70
     71        add_action( 'wp_head', $header_callback );
    7172
    7273        wp_enqueue_script( 'admin-bar' );
     
    115116    public function add_node( $args ) {
    116117        // Shim for old method signature: add_node( $parent_id, $menu_obj, $args )
    117         if ( func_num_args() >= 3 && is_string( func_get_arg(0) ) )
    118             $args = array_merge( array( 'parent' => func_get_arg(0) ), func_get_arg(2) );
    119 
    120         if ( is_object( $args ) )
     118        if ( func_num_args() >= 3 && is_string( func_get_arg( 0 ) ) ) {
     119            $args = array_merge( array( 'parent' => func_get_arg( 0 ) ), func_get_arg( 2 ) );
     120        }
     121
     122        if ( is_object( $args ) ) {
    121123            $args = get_object_vars( $args );
     124        }
    122125
    123126        // Ensure we have a valid title.
    124127        if ( empty( $args['id'] ) ) {
    125             if ( empty( $args['title'] ) )
     128            if ( empty( $args['title'] ) ) {
    126129                return;
     130            }
    127131
    128132            _doing_it_wrong( __METHOD__, __( 'The menu ID should not be empty.' ), '3.3.0' );
     
    141145
    142146        // If the node already exists, keep any data that isn't provided.
    143         if ( $maybe_defaults = $this->get_node( $args['id'] ) )
     147        if ( $maybe_defaults = $this->get_node( $args['id'] ) ) {
    144148            $defaults = get_object_vars( $maybe_defaults );
     149        }
    145150
    146151        // Do the same for 'meta' items.
    147         if ( ! empty( $defaults['meta'] ) && ! empty( $args['meta'] ) )
     152        if ( ! empty( $defaults['meta'] ) && ! empty( $args['meta'] ) ) {
    148153            $args['meta'] = wp_parse_args( $args['meta'], $defaults['meta'] );
     154        }
    149155
    150156        $args = wp_parse_args( $args, $defaults );
     
    152158        $back_compat_parents = array(
    153159            'my-account-with-avatar' => array( 'my-account', '3.3' ),
    154             'my-blogs'               => array( 'my-sites',   '3.3' ),
     160            'my-blogs'               => array( 'my-sites', '3.3' ),
    155161        );
    156162
     
    178184     */
    179185    final public function get_node( $id ) {
    180         if ( $node = $this->_get_node( $id ) )
     186        if ( $node = $this->_get_node( $id ) ) {
    181187            return clone $node;
     188        }
    182189    }
    183190
     
    187194     */
    188195    final protected function _get_node( $id ) {
    189         if ( $this->bound )
    190             return;
    191 
    192         if ( empty( $id ) )
     196        if ( $this->bound ) {
     197            return;
     198        }
     199
     200        if ( empty( $id ) ) {
    193201            $id = 'root';
    194 
    195         if ( isset( $this->nodes[ $id ] ) )
     202        }
     203
     204        if ( isset( $this->nodes[ $id ] ) ) {
    196205            return $this->nodes[ $id ];
     206        }
    197207    }
    198208
     
    201211     */
    202212    final public function get_nodes() {
    203         if ( ! $nodes = $this->_get_nodes() )
    204             return;
     213        if ( ! $nodes = $this->_get_nodes() ) {
     214            return;
     215        }
    205216
    206217        foreach ( $nodes as &$node ) {
     
    214225     */
    215226    final protected function _get_nodes() {
    216         if ( $this->bound )
    217             return;
     227        if ( $this->bound ) {
     228            return;
     229        }
    218230
    219231        return $this->nodes;
     
    260272    public function render() {
    261273        $root = $this->_bind();
    262         if ( $root )
     274        if ( $root ) {
    263275            $this->_render( $root );
     276        }
    264277    }
    265278
     
    268281     */
    269282    final protected function _bind() {
    270         if ( $this->bound )
    271             return;
     283        if ( $this->bound ) {
     284            return;
     285        }
    272286
    273287        // Add the root node.
    274288        // Clear it first, just in case. Don't mess with The Root.
    275289        $this->remove_node( 'root' );
    276         $this->add_node( array(
    277             'id'    => 'root',
    278             'group' => false,
    279         ) );
     290        $this->add_node(
     291            array(
     292                'id'    => 'root',
     293                'group' => false,
     294            )
     295        );
    280296
    281297        // Normalize nodes: define internal 'children' and 'type' properties.
    282298        foreach ( $this->_get_nodes() as $node ) {
    283299            $node->children = array();
    284             $node->type = ( $node->group ) ? 'group' : 'item';
     300            $node->type     = ( $node->group ) ? 'group' : 'item';
    285301            unset( $node->group );
    286302
    287303            // The Root wants your orphans. No lonely items allowed.
    288             if ( ! $node->parent )
     304            if ( ! $node->parent ) {
    289305                $node->parent = 'root';
     306            }
    290307        }
    291308
    292309        foreach ( $this->_get_nodes() as $node ) {
    293             if ( 'root' == $node->id )
     310            if ( 'root' == $node->id ) {
    294311                continue;
     312            }
    295313
    296314            // Fetch the parent node. If it isn't registered, ignore the node.
     
    303321
    304322            if ( $node->type == 'group' ) {
    305                 if ( empty( $node->meta['class'] ) )
     323                if ( empty( $node->meta['class'] ) ) {
    306324                    $node->meta['class'] = $group_class;
    307                 else
     325                } else {
    308326                    $node->meta['class'] .= ' ' . $group_class;
     327                }
    309328            }
    310329
     
    319338                    // Use _set_node because add_node can be overloaded.
    320339                    // Make sure to specify default settings for all properties.
    321                     $this->_set_node( array(
    322                         'id'        => $default_id,
    323                         'parent'    => $parent->id,
    324                         'type'      => 'group',
    325                         'children'  => array(),
    326                         'meta'      => array(
    327                             'class'     => $group_class,
    328                         ),
    329                         'title'     => false,
    330                         'href'      => false,
    331                     ) );
    332                     $default = $this->_get_node( $default_id );
     340                    $this->_set_node(
     341                        array(
     342                            'id'       => $default_id,
     343                            'parent'   => $parent->id,
     344                            'type'     => 'group',
     345                            'children' => array(),
     346                            'meta'     => array(
     347                                'class' => $group_class,
     348                            ),
     349                            'title'    => false,
     350                            'href'     => false,
     351                        )
     352                    );
     353                    $default            = $this->_get_node( $default_id );
    333354                    $parent->children[] = $default;
    334355                }
    335356                $parent = $default;
    336357
    337             // Groups in groups aren't allowed. Add a special 'container' node.
    338             // The container will invisibly wrap both groups.
     358                // Groups in groups aren't allowed. Add a special 'container' node.
     359                // The container will invisibly wrap both groups.
    339360            } elseif ( $parent->type == 'group' && $node->type == 'group' ) {
    340361                $container_id = $parent->id . '-container';
     
    345366                    // Use _set_node because add_node can be overloaded.
    346367                    // Make sure to specify default settings for all properties.
    347                     $this->_set_node( array(
    348                         'id'       => $container_id,
    349                         'type'     => 'container',
    350                         'children' => array( $parent ),
    351                         'parent'   => false,
    352                         'title'    => false,
    353                         'href'     => false,
    354                         'meta'     => array(),
    355                     ) );
     368                    $this->_set_node(
     369                        array(
     370                            'id'       => $container_id,
     371                            'type'     => 'container',
     372                            'children' => array( $parent ),
     373                            'parent'   => false,
     374                            'title'    => false,
     375                            'href'     => false,
     376                            'meta'     => array(),
     377                        )
     378                    );
    356379
    357380                    $container = $this->_get_node( $container_id );
     
    364387
    365388                        $index = array_search( $parent, $grandparent->children, true );
    366                         if ( $index === false )
     389                        if ( $index === false ) {
    367390                            $grandparent->children[] = $container;
    368                         else
     391                        } else {
    369392                            array_splice( $grandparent->children, $index, 1, array( $container ) );
     393                        }
    370394                    }
    371395
     
    383407        }
    384408
    385         $root = $this->_get_node( 'root' );
     409        $root        = $this->_get_node( 'root' );
    386410        $this->bound = true;
    387411        return $root;
     
    389413
    390414    /**
    391      *
    392415     * @global bool $is_IE
    393416     * @param object $root
     
    400423        $class = 'nojq nojs';
    401424        if ( $is_IE ) {
    402             if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 7' ) )
     425            if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 7' ) ) {
    403426                $class .= ' ie7';
    404             elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 8' ) )
     427            } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 8' ) ) {
    405428                $class .= ' ie8';
    406             elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 9' ) )
     429            } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 9' ) ) {
    407430                $class .= ' ie9';
     431            }
    408432        } elseif ( wp_is_mobile() ) {
    409433            $class .= ' mobile';
     
    416440            <?php } ?>
    417441            <div class="quicklinks" id="wp-toolbar" role="navigation" aria-label="<?php esc_attr_e( 'Toolbar' ); ?>" tabindex="0">
    418                 <?php foreach ( $root->children as $group ) {
     442                <?php
     443                foreach ( $root->children as $group ) {
    419444                    $this->_render_group( $group );
    420                 } ?>
     445                }
     446                ?>
    421447            </div>
    422448            <?php if ( is_user_logged_in() ) : ?>
    423             <a class="screen-reader-shortcut" href="<?php echo esc_url( wp_logout_url() ); ?>"><?php _e('Log Out'); ?></a>
     449            <a class="screen-reader-shortcut" href="<?php echo esc_url( wp_logout_url() ); ?>"><?php _e( 'Log Out' ); ?></a>
    424450            <?php endif; ?>
    425451        </div>
     
    432458     */
    433459    final protected function _render_container( $node ) {
    434         if ( $node->type != 'container' || empty( $node->children ) )
    435             return;
     460        if ( $node->type != 'container' || empty( $node->children ) ) {
     461            return;
     462        }
    436463
    437464        echo '<div id="' . esc_attr( 'wp-admin-bar-' . $node->id ) . '" class="ab-group-container">';
     
    450477            return;
    451478        }
    452         if ( $node->type != 'group' || empty( $node->children ) )
    453             return;
    454 
    455         if ( ! empty( $node->meta['class'] ) )
     479        if ( $node->type != 'group' || empty( $node->children ) ) {
     480            return;
     481        }
     482
     483        if ( ! empty( $node->meta['class'] ) ) {
    456484            $class = ' class="' . esc_attr( trim( $node->meta['class'] ) ) . '"';
    457         else
     485        } else {
    458486            $class = '';
     487        }
    459488
    460489        echo "<ul id='" . esc_attr( 'wp-admin-bar-' . $node->id ) . "'$class>";
     
    469498     */
    470499    final protected function _render_item( $node ) {
    471         if ( $node->type != 'item' )
    472             return;
     500        if ( $node->type != 'item' ) {
     501            return;
     502        }
    473503
    474504        $is_parent = ! empty( $node->children );
     
    476506
    477507        // Allow only numeric values, then casted to integers, and allow a tabindex value of `0` for a11y.
    478         $tabindex = ( isset( $node->meta['tabindex'] ) && is_numeric( $node->meta['tabindex'] ) ) ? (int) $node->meta['tabindex'] : '';
     508        $tabindex        = ( isset( $node->meta['tabindex'] ) && is_numeric( $node->meta['tabindex'] ) ) ? (int) $node->meta['tabindex'] : '';
    479509        $aria_attributes = ( '' !== $tabindex ) ? ' tabindex="' . $tabindex . '"' : '';
    480510
     
    482512
    483513        if ( $is_parent ) {
    484             $menuclass = 'menupop ';
     514            $menuclass        = 'menupop ';
    485515            $aria_attributes .= ' aria-haspopup="true"';
    486516        }
    487517
    488         if ( ! empty( $node->meta['class'] ) )
     518        if ( ! empty( $node->meta['class'] ) ) {
    489519            $menuclass .= $node->meta['class'];
    490 
    491         if ( $menuclass )
     520        }
     521
     522        if ( $menuclass ) {
    492523            $menuclass = ' class="' . esc_attr( trim( $menuclass ) ) . '"';
     524        }
    493525
    494526        echo "<li id='" . esc_attr( 'wp-admin-bar-' . $node->id ) . "'$menuclass>";
Note: See TracChangeset for help on using the changeset viewer.