Skip to content

Commit 9101a4a

Browse files
committed
Fixes the warning if null is given to prepare_items_query()
See https://core.trac.wordpress.org/ticket/62287
1 parent c4752a1 commit 9101a4a

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,17 +1181,19 @@ public function delete_item( $request ) {
11811181
protected function prepare_items_query( $prepared_args = array(), $request = null ) {
11821182
$query_args = array();
11831183

1184-
foreach ( $prepared_args as $key => $value ) {
1185-
/**
1186-
* Filters the query_vars used in get_items() for the constructed query.
1187-
*
1188-
* The dynamic portion of the hook name, `$key`, refers to the query_var key.
1189-
*
1190-
* @since 4.7.0
1191-
*
1192-
* @param string $value The query_var value.
1193-
*/
1194-
$query_args[ $key ] = apply_filters( "rest_query_var-{$key}", $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1184+
if ( is_array( $prepared_args ) ) {
1185+
foreach ( $prepared_args as $key => $value ) {
1186+
/**
1187+
* Filters the query_vars used in get_items() for the constructed query.
1188+
*
1189+
* The dynamic portion of the hook name, `$key`, refers to the query_var key.
1190+
*
1191+
* @since 4.7.0
1192+
*
1193+
* @param string $value The query_var value.
1194+
*/
1195+
$query_args[ $key ] = apply_filters( "rest_query_var-{$key}", $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1196+
}
11951197
}
11961198

11971199
if ( 'post' !== $this->post_type || ! isset( $query_args['ignore_sticky_posts'] ) ) {

src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,11 @@ public function delete_item( $request ) {
532532
protected function prepare_items_query( $prepared_args = array(), $request = null ) {
533533
$query_args = array();
534534

535-
foreach ( $prepared_args as $key => $value ) {
536-
/** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
537-
$query_args[ $key ] = apply_filters( "rest_query_var-{$key}", $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
535+
if ( is_array( $prepared_args ) ) {
536+
foreach ( $prepared_args as $key => $value ) {
537+
/** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
538+
$query_args[ $key ] = apply_filters( "rest_query_var-{$key}", $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
539+
}
538540
}
539541

540542
// Map to proper WP_Query orderby param.

0 commit comments

Comments
 (0)