Make WordPress Core


Ignore:
Timestamp:
07/26/2024 07:54:26 AM (10 months ago)
Author:
SergeyBiryukov
Message:

General: Cast $max_depth and $depth to an integer in the Walker class.

This ensures that the arguments are correctly interpreted when passed as a query string, i.e. when wp_parse_args() is involved. For example, wp_list_pages( 'depth=0' ) should display a list of all pages to the maximum depth.

Follow-up to [57848].

Props freibergergarcia, peterwilsoncc, ahortin.
Fixes #61749.

File:
1 edited

Legend:

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

    r57848 r58812  
    136136        }
    137137
     138        $max_depth = (int) $max_depth;
     139        $depth     = (int) $depth;
     140
    138141        $id_field = $this->db_fields['id'];
    139142        $id       = $element->$id_field;
     
    191194    public function walk( $elements, $max_depth, ...$args ) {
    192195        $output = '';
     196
     197        $max_depth = (int) $max_depth;
    193198
    194199        // Invalid parameter or nothing to walk.
     
    286291     */
    287292    public function paged_walk( $elements, $max_depth, $page_num, $per_page, ...$args ) {
     293        $output = '';
     294
     295        $max_depth = (int) $max_depth;
     296
    288297        if ( empty( $elements ) || $max_depth < -1 ) {
    289             return '';
    290         }
    291 
    292         $output = '';
     298            return $output;
     299        }
    293300
    294301        $parent_field = $this->db_fields['parent'];
Note: See TracChangeset for help on using the changeset viewer.