Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#61749 closed defect (bug) (fixed)

`wp_list_pages()` depth of `0` can show only top level of pages

Reported by: peterwilsoncc Owned by: SergeyBiryukov
Priority: normal Milestone: 6.6.2
Component: General Version: 6.6
Severity: normal Keywords: has-patch has-unit-tests fixed-major dev-reviewed
Cc: Focuses:

Description

In WP 6.6, the code wp_list_pages( 'depth=0' ); no longer displays a list of all pages to the maximum depth. Instead only the top level of pages will be displayed.

Steps to reproduce:

  1. Replace entire theme with wp_list_pages( 'depth=0' );
  2. Create a few pages with parent child relationships
  3. On the latest version of 6.5 a heirachical list of pages will be displayed
  4. On the 6.6 branch and in trunk the top level pages will only be shown.

The cause is r57848 as the switch to strict comparisons in the walker class does not account for the way wp_parse_args() handles query string formatted arguments passed to the function and therefore interpreted, eventually, by the walker:

wp> wp_parse_args( 'depth=0', [ 'depth' => 0 ] );
=> phar:///usr/local/src/wp-cli/bin/wp/vendor/wp-cli/shell-command/src/WP_CLI/Shell/REPL.php:52:
array(1) {
  'depth' =>
  string(1) "0"
}
wp> 

I expect this is effecting other functions that make use of the walker class too.


Props @ahortin via the WP Australia Slack for discovery and assistance figuring out reproduction steps.

Change History (7)

This ticket was mentioned in PR #7091 on WordPress/wordpress-develop by @freibergergarcia.


2 years ago
#1

  • Keywords has-patch has-unit-tests added

Cast $max_depth and $depth to integer on class Walker (class-wp-walker), so it's compliant with strict comparisons.

Trac ticket: https://core.trac.wordpress.org/ticket/61749

#2 @freibergergarcia
2 years ago

See the suggested fix for the issue: https://github.com/WordPress/wordpress-develop/pull/7091.

I added a unit test for depth=0, triggering the wp_parse_args to simulate what was raised.
I also manually tested as suggested above. Hopefully, it will put us in the right direction.

#3 @SergeyBiryukov
2 years ago

  • Owner set to SergeyBiryukov
  • Resolutionfixed
  • Status newclosed

In 58812:

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.

@SergeyBiryukov commented on PR #7091:


2 years ago
#4

Thanks for the PR! Merged in r58812.

#5 @SergeyBiryukov
2 years ago

  • Keywords fixed-major added
  • Resolution fixed
  • Status closedreopened

Thanks for the ticket! Reopening for 6.6.2 consideration.

#6 @peterwilsoncc
2 years ago

  • Keywords dev-reviewed added

[58812] approved for backport.

#7 @hellofromTonya
2 years ago

  • Resolutionfixed
  • Status reopenedclosed

In 58863:

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].

Reviewed by peterwilsoncc.
Merges [58812] to the 6.6 branch.

Props freibergergarcia, peterwilsoncc, ahortin.
Fixes #61749.

Note: See TracTickets for help on using tickets.