Make WordPress Core

Changeset 61773


Ignore:
Timestamp:
02/28/2026 12:41:31 AM (6 weeks ago)
Author:
westonruter
Message:

REST API: Guard against passing null as $prepared_args to WP_REST_Posts_Controller::prepare_items_query().

The variable may get set to null by a filter or subclass.

Developed in https://github.com/WordPress/wordpress-develop/pull/7625

Follow-up to r38832.

Props apermo, dmsnell, westonruter.
Fixes #62287.

Location:
trunk/src/wp-includes/rest-api/endpoints
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r61707 r61773  
    442442         * @param WP_REST_Request $request The REST API request.
    443443         */
    444         $args       = apply_filters( "rest_{$this->post_type}_query", $args, $request );
     444        $args = apply_filters( "rest_{$this->post_type}_query", $args, $request );
     445        if ( ! is_array( $args ) ) {
     446            $args = array();
     447        }
    445448        $query_args = $this->prepare_items_query( $args, $request );
    446449
     
    12121215    protected function prepare_items_query( $prepared_args = array(), $request = null ) {
    12131216        $query_args = array();
     1217        if ( ! is_array( $prepared_args ) ) {
     1218            $prepared_args = array();
     1219        }
    12141220
    12151221        foreach ( $prepared_args as $key => $value ) {
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php

    r61002 r61773  
    299299
    300300            /** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */
    301             $args       = apply_filters( 'rest_revision_query', $args, $request );
     301            $args = apply_filters( 'rest_revision_query', $args, $request );
     302            if ( ! is_array( $args ) ) {
     303                $args = array();
     304            }
    302305            $query_args = $this->prepare_items_query( $args, $request );
    303306
     
    550553    protected function prepare_items_query( $prepared_args = array(), $request = null ) {
    551554        $query_args = array();
     555        if ( ! is_array( $prepared_args ) ) {
     556            $prepared_args = array();
     557        }
    552558
    553559        foreach ( $prepared_args as $key => $value ) {
Note: See TracChangeset for help on using the changeset viewer.