WordPress.org

Make WordPress Core

Opened 9 months ago

Closed 8 months ago

#38136 closed defect (bug) (fixed)

The docs for get_pages() - the post_status argument can also be an array

Reported by: birgire Owned by: SergeyBiryukov
Milestone: 4.7 Priority: normal
Severity: normal Version: 4.7
Component: General Keywords: has-patch
Focuses: docs Cc:

Description

The documentation for get_pages() says:

* @type string  $post_status  A comma-separated list of post statuses types to include.

but the post_status argument can also be an array according to this part of get_pages():

// Make sure we have a valid post status.
if ( ! is_array( $post_status ) ) {
    $post_status = explode( ',', $post_status );
}
if ( array_diff( $post_status, get_post_stati() ) ) {
    return false;
}

... cut ...

if ( 1 == count( $post_status ) ) {
    $where_post_type = $wpdb->prepare( "post_type = %s AND post_status = %s", $r['post_type'], reset( $post_status ) );
} else {
    $post_status = implode( "', '", $post_status );
    $where_post_type = $wpdb->prepare( "post_type = %s AND post_status IN ('$post_status')", $r['post_type'] );
}

ps: I also adjusted the defaults array of get_pages() for better readability.

Attachments (2)

get_pages.diff (6.7 KB) - added by birgire 9 months ago.
38136.diff (13.3 KB) - added by desrosj 9 months ago.
Adds fix for wp_list_pages() and fixes some spacing/tab inconsistencies in the default argument fixes.

Download all attachments as: .zip

Change History (8)

@birgire
9 months ago

#1 @birgire
9 months ago

  • Keywords has-patch added

#2 @SergeyBiryukov
9 months ago

  • Milestone changed from Awaiting Review to 4.7
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

wp_list_pages() docs have the same issue and should also be corrected.

#3 @birgire
9 months ago

@SergeyBiryukov

Yes it's the same with wp_list_pages().

I guess I could address that as well.

Not sure if I should use the same ticket, create a new one or if there's a special ticket for docs improvements in 4.7?

@desrosj
9 months ago

Adds fix for wp_list_pages() and fixes some spacing/tab inconsistencies in the default argument fixes.

This ticket was mentioned in Slack in #core by jeffpaul. View the logs.


8 months ago

#5 @SergeyBiryukov
8 months ago

@desrosj: 38136.diff has a couple of issues:

  • It removes $post_type entry for wp_list_pages() and creates a duplicate $post_status entry.
  • No need for additional tab before function (or in the preceding docblock).

Will handle on commit :)

#6 @SergeyBiryukov
8 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 38798:

Docs: In get_pages() and wp_list_pages(), note that post_status argument can also be an array.

Adjust the alignment of default argument values for better readability.

Props birgire, desrosj.
Fixes #38136.

Note: See TracTickets for help on using tickets.