Skip to content

Commit 41c8c61

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

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
@@ -1212,17 +1212,19 @@ public function delete_item( $request ) {
12121212
protected function prepare_items_query( $prepared_args = array(), $request = null ) {
12131213
$query_args = array();
12141214

1215-
foreach ( $prepared_args as $key => $value ) {
1216-
/**
1217-
* Filters the query_vars used in get_items() for the constructed query.
1218-
*
1219-
* The dynamic portion of the hook name, `$key`, refers to the query_var key.
1220-
*
1221-
* @since 4.7.0
1222-
*
1223-
* @param string $value The query_var value.
1224-
*/
1225-
$query_args[ $key ] = apply_filters( "rest_query_var-{$key}", $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1215+
if ( is_array( $prepared_args ) ) {
1216+
foreach ( $prepared_args as $key => $value ) {
1217+
/**
1218+
* Filters the query_vars used in get_items() for the constructed query.
1219+
*
1220+
* The dynamic portion of the hook name, `$key`, refers to the query_var key.
1221+
*
1222+
* @since 4.7.0
1223+
*
1224+
* @param string $value The query_var value.
1225+
*/
1226+
$query_args[ $key ] = apply_filters( "rest_query_var-{$key}", $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
1227+
}
12261228
}
12271229

12281230
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
@@ -550,9 +550,11 @@ public function delete_item( $request ) {
550550
protected function prepare_items_query( $prepared_args = array(), $request = null ) {
551551
$query_args = array();
552552

553-
foreach ( $prepared_args as $key => $value ) {
554-
/** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
555-
$query_args[ $key ] = apply_filters( "rest_query_var-{$key}", $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
553+
if ( is_array( $prepared_args ) ) {
554+
foreach ( $prepared_args as $key => $value ) {
555+
/** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
556+
$query_args[ $key ] = apply_filters( "rest_query_var-{$key}", $value ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
557+
}
556558
}
557559

558560
// Map to proper WP_Query orderby param.

0 commit comments

Comments
 (0)