Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/01/2024 10:19:51 PM (2 years ago)
Author:
espellcaste
Message:

WPCS: Part III: miscellaneous fixes for some of the files of the core component.

Follow-up to [13883] and [13886]

See #9164 and #7228

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-walker-nav-menu.php

    r12552 r13887  
    2121         *
    2222         * @since 1.7.0
     23         *
    2324         * @var array
    2425         */
    25         var $db_fields = array( 'id' => 'css_id', 'parent' => 'parent' );
     26        public $db_fields = array(
     27                'id'     => 'css_id',
     28                'parent' => 'parent',
     29        );
    2630
    2731        /**
     
    2933         *
    3034         * @since 1.7.0
     35         *
    3136         * @var string
    3237         */
    33         var $tree_type = array();
     38        public $tree_type = array();
    3439
    3540        /**
     
    5964                $output = '';
    6065
    61                 if ( $max_depth < -1 ) // Invalid parameter.
     66                if ( $max_depth < -1 ) { // Invalid parameter.
    6267                        return $output;
    63 
    64                 if ( empty( $elements ) ) // Nothing to walk.
     68                }
     69
     70                if ( empty( $elements ) ) { // Nothing to walk.
    6571                        return $output;
     72                }
    6673
    6774                $parent_field = $this->db_fields['parent'];
    6875
    6976                // Flat display.
    70                 if ( -1 == $max_depth ) {
     77                if ( -1 === $max_depth ) {
    7178
    7279                        $empty_array = array();
    73                         foreach ( $elements as $e )
     80                        foreach ( $elements as $e ) {
    7481                                $this->display_element( $e, $empty_array, 1, 0, $args, $output );
     82                        }
    7583
    7684                        return $output;
     
    8896                foreach ( $elements as $e ) {
    8997                        // BuddyPress: changed '==' to '==='. This is the only change from version in Walker::walk().
    90                         if ( 0 === $e->$parent_field )
     98                        if ( 0 === $e->$parent_field ) {
    9199                                $top_level_elements[] = $e;
    92                         else
    93                                 $children_elements[$e->$parent_field][] = $e;
     100                        } else {
     101                                $children_elements[ $e->$parent_field ][] = $e;
     102                        }
    94103                }
    95104
     
    106115
    107116                        foreach ( $elements as $e ) {
    108                                 if ( $root->$parent_field == $e->$parent_field )
     117                                if ( $root->$parent_field === $e->$parent_field ) {
    109118                                        $top_level_elements[] = $e;
    110                                 else
    111                                         $children_elements[$e->$parent_field][] = $e;
    112                         }
    113                 }
    114 
    115                 foreach ( $top_level_elements as $e )
     119                                } else {
     120                                        $children_elements[ $e->$parent_field ][] = $e;
     121                                }
     122                        }
     123                }
     124
     125                foreach ( $top_level_elements as $e ) {
    116126                        $this->display_element( $e, $children_elements, $max_depth, 0, $args, $output );
     127                }
    117128
    118129                /*
     
    120131                 * then we got orphans, which should be displayed regardless.
    121132                 */
    122                 if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) {
     133                if ( ( 0 === $max_depth ) && count( $children_elements ) > 0 ) {
    123134                        $empty_array = array();
    124135
    125                         foreach ( $children_elements as $orphans )
    126                                 foreach ( $orphans as $op )
     136                        foreach ( $children_elements as $orphans ) {
     137                                foreach ( $orphans as $op ) {
    127138                                        $this->display_element( $op, $empty_array, 1, 0, $args, $output );
    128                  }
    129 
    130                  return $output;
     139                                }
     140                        }
     141                }
     142
     143                return $output;
    131144        }
    132145
     
    152165         * @since 1.7.0
    153166         *
    154          * @param string $output Passed by reference. Used to append
    155          *                       additional content.
    156          * @param object $item   Menu item data object.
    157          * @param int    $depth  Depth of menu item. Used for padding. Optional,
    158          *                       defaults to 0.
    159          * @param array $args   Optional. See {@link Walker::start_el()}.
    160          * @param int    $id     Menu item ID. Optional.
     167         * @param string   $output Passed by reference. Used to append
     168         *                         dditional content.
     169         * @param object   $item   Menu item data object.
     170         * @param int      $depth  Optional. Depth of menu item. Used for padding.
     171         *                         Defaults to 0.
     172         * @param stdClass $args   Optional. See {@link Walker::start_el()}.
     173         * @param int      $id     Menu item ID. Optional.
    161174         */
    162175        public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
     
    169182                 * @since 1.7.0
    170183                 *
    171                  * @param array  $value Array of classes to be added.
    172                  * @param object $item  Menu item data object.
    173                  * @param array  $args  Array of arguments for the item.
     184                 * @param array    $value Array of classes to be added.
     185                 * @param object   $item  Menu item data object.
     186                 * @param stdClass $args  An object of wp_nav_menu() arguments.
    174187                 */
    175188                $class_names = join( ' ', apply_filters( 'bp_nav_menu_css_class', array_filter( $item->class ), $item, $args ) );
    176189                $class_names = ! empty( $class_names ) ? ' class="' . esc_attr( $class_names ) . '"' : '';
    177190
    178                 // Add HTML ID
     191                // Add HTML ID.
    179192                $id = sanitize_html_class( $item->css_id . '-personal-li' );  // Backpat with BP pre-1.7.
    180193
     
    184197                 * @since 1.7.0
    185198                 *
    186                  * @param string $id   ID attribute to be added to the menu item.
    187                  * @param object $item Menu item data object.
    188                  * @param array  $args Array of arguments for the item.
     199                 * @param string   $id   ID attribute to be added to the menu item.
     200                 * @param object   $item Menu item data object.
     201                 * @param stdClass $args An object of wp_nav_menu() arguments.
    189202                 */
    190203                $id = apply_filters( 'bp_nav_menu_item_id', $id, $item, $args );
     
    198211
    199212                // Construct the link.
    200                 $item_output = $args->before;
     213                $item_output  = $args->before;
    201214                $item_output .= '<a' . $attributes . '>';
    202215
     
    206219                 * @since 1.7.0
    207220                 *
    208                  * @param string $name  Item text to be applied.
    209                  * @param int    $value Post ID the title is for.
    210                  */
    211                 $item_output .= $args->link_before . apply_filters( 'the_title', $item->name, 0 ) . $args->link_after;
     221                 * @param string $name    Item text to be applied.
     222                 * @param int    $post_id Post ID the title is for.
     223                 */
     224                $link_text = apply_filters( 'the_title', $item->name, 0 );
     225
     226                $item_output .= $args->link_before . $link_text . $args->link_after;
    212227                $item_output .= '</a>';
    213228                $item_output .= $args->after;
     
    218233                 * @since 1.7.0
    219234                 *
    220                  * @param string $item_output Constructed output for the menu item to append to output.
    221                  * @param object $item        Menu item data object.
    222                  * @param int    $depth       Depth of menu item. Used for padding.
    223                  * @param array  $args        Array of arguments for the item.
     235                 * @param string   $item_output Constructed output for the menu item to append to output.
     236                 * @param object   $item        Menu item data object.
     237                 * @param int      $depth       Depth of menu item. Used for padding.
     238                 * @param stdClass $args        An object of wp_nav_menu() arguments.
    224239                 */
    225240                $output .= apply_filters( 'bp_walker_nav_menu_start_el', $item_output, $item, $depth, $args );
Note: See TracChangeset for help on using the changeset viewer.