admin管理员组

文章数量:1122846

I have a local and a prod environment. I have 19 patterns registered with register_block_pattern(). In the post editor, I can see them in the pattern selector. In prod environment, suddenly, I can no longer see my patterns in the selector. I found that the response from here:

/wp-json/wp/v2/block-patterns/patterns?_locale=user

Isn't a valid JSON. Instead of starting out like:

[{"name":"core\/query-standard-posts","title":"Standard","block_types":["core\/query"]

It starts like:

<br />
<b>Warning</b>:  array_map(): Argument #2 should be an array in <b>/var/www/html/site/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php</b> on line <b>208</b><br />
<br />
<b>Warning</b>:  array_map(): Argument #2 should be an array in <b>/var/www/html/site/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php</b> on line <b>208</b><br />
<br />
<b>Warning</b>:  array_map(): Argument #2 should be an array in <b>/var/www/html/site/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php</b> on line <b>208</b><br />
<br />
<b>Warning</b>:  array_map(): Argument #2 should be an array in <b>/var/www/html/site/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php</b> on line <b>208</b><br />
<br />
<b>Warning</b>:  array_map(): Argument #2 should be an array in <b>/var/www/html/site/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php</b> on line <b>208</b><br />
<br />
<b>Warning</b>:  array_map(): Argument #2 should be an array in <b>/var/www/html/site/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php</b> on line <b>208</b><br />
<br />
<b>Warning</b>:  array_map(): Argument #2 should be an array in <b>/var/www/html/site/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php</b> on line <b>208</b><br />
<br />
<b>Warning</b>:  array_map(): Argument #2 should be an array in <b>/var/www/html/site/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php</b> on line <b>208</b><br />
<br />
<b>Warning</b>:  array_map(): Argument #2 should be an array in <b>/var/www/html/site/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php</b> on line <b>208</b><br />
[{"name":"core\/query-standard-posts","title":"Standard","block_types":["core\/query"],

I'm using Wordpress 6.1.1 so that warning is the $raw_pattern->category_slugs in this function so it's presumably patterns without a category returning empty for category slugs and then receiving a warning when it tries to use reference them:

/**
 * Prepare a raw block pattern before it gets output in a REST API response.
 *
 * @since 5.8.0
 * @since 5.9.0 Renamed `$raw_pattern` to `$item` to match parent class for PHP 8 named parameter support.
 *
 * @param object          $item    Raw pattern from api.wordpress, before any changes.
 * @param WP_REST_Request $request Request object.
 * @return WP_REST_Response
 */
public function prepare_item_for_response( $item, $request ) {
    // Restores the more descriptive, specific name for use within this method.
    $raw_pattern      = $item;
    $prepared_pattern = array(
        'id'             => absint( $raw_pattern->id ),
        'title'          => sanitize_text_field( $raw_pattern->title->rendered ),
        'content'        => wp_kses_post( $raw_pattern->pattern_content ),
        'categories'     => array_map( 'sanitize_title', $raw_pattern->category_slugs ),
        'keywords'       => array_map( 'sanitize_text_field', explode( ',', $raw_pattern->meta->wpop_keywords ) ),
        'description'    => sanitize_text_field( $raw_pattern->meta->wpop_description ),
        'viewport_width' => absint( $raw_pattern->meta->wpop_viewport_width ),
    );

    $prepared_pattern = $this->add_additional_fields_to_object( $prepared_pattern, $request );

    $response = new WP_REST_Response( $prepared_pattern );

    /**
     * Filters the REST API response for a block pattern.
     *
     * @since 5.8.0
     *
     * @param WP_REST_Response $response    The response object.
     * @param object           $raw_pattern The unprepared block pattern.
     * @param WP_REST_Request  $request     The request object.
     */
    return apply_filters( 'rest_prepare_block_pattern', $response, $raw_pattern, $request );
}

My wp-includes is in a docker container that I can't edit. I'm trying to replicate the problem on my local machine. Is there some change that could have been done to the content of the site (i.e. the db) that would explain why these warnings are only showing up now? How could I go about replicating this locally?

本文标签: PHP Warning in JSON response is breaking pattern selector in editor