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
版权声明:本文标题:PHP Warning in JSON response is breaking pattern selector in editor 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736286255a1927630.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论