From a88a66b0bd3dd5e135e80bc3c29c385b1fbb25cf Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Mon, 22 May 2023 10:03:22 +0000 Subject: [PATCH] Posts, Post Types: Add a new filter for query arguments in `get_pages`. In [55569] `get_pages` was converted to use `WP_Query` internally. But for plugins that were extending the `get_pages` filters and filter `WP_Query` query arguments, this could result in a conflict. Add a filter `get_pages_query_args` to allow developers to change arguments passed to `WP_Query` but also have the context of the original arguments passed to the `get_pages` function. This change also expands test coverage of `get_pages` to ensure no breakages in the future. Props spacedmonkey, westonruter, costdev, flixos90, kenwins, marianne38. See #12821. Built from https://develop.svn.wordpress.org/trunk@55845 git-svn-id: http://core.svn.wordpress.org/trunk@55357 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 12 +++++++++++- wp-includes/version.php | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 77a1a49238..fabd68edb2 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -6031,7 +6031,7 @@ function get_pages( $args = array() ) { } $post_author = $post_author->ID; } - $query_args['author__in'][] = $post_author; + $query_args['author__in'][] = (int) $post_author; } } } @@ -6060,6 +6060,16 @@ function get_pages( $args = array() ) { $query_args['posts_per_page'] = $number; } + /** + * Filters query arguments passed to WP_Query in get_pages. + * + * @since 6.3.0 + * + * @param array $query_args Array of arguments passed to WP_Query. + * @param array $parsed_args Array of get_pages() arguments. + */ + $query_args = apply_filters( 'get_pages_query_args', $query_args, $parsed_args ); + $query = new WP_Query( $query_args ); $pages = $query->get_posts(); diff --git a/wp-includes/version.php b/wp-includes/version.php index 1236896967..c7778e785e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-55844'; +$wp_version = '6.3-alpha-55845'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.