REST API: Make template handling resilient against plugins setting the global post.
Plugins shouldn't be setting the global post object during a REST API request, but if they did this could cause unexpected errors when creating a post with a template. Props Kipperlenny, TimothyBlynJacobs. Fixes #49695. Built from https://develop.svn.wordpress.org/trunk@49301 git-svn-id: http://core.svn.wordpress.org/trunk@49063 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
3a01517c90
commit
abbc108d19
|
@ -1344,8 +1344,10 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $request['id'] ) {
|
if ( $request['id'] ) {
|
||||||
|
$post = get_post( $request['id'] );
|
||||||
$current_template = get_page_template_slug( $request['id'] );
|
$current_template = get_page_template_slug( $request['id'] );
|
||||||
} else {
|
} else {
|
||||||
|
$post = null;
|
||||||
$current_template = '';
|
$current_template = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1355,7 +1357,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is a create request, get_post() will return null and wp theme will fallback to the passed post type.
|
// If this is a create request, get_post() will return null and wp theme will fallback to the passed post type.
|
||||||
$allowed_templates = wp_get_theme()->get_page_templates( get_post( $request['id'] ), $this->post_type );
|
$allowed_templates = wp_get_theme()->get_page_templates( $post, $this->post_type );
|
||||||
|
|
||||||
if ( isset( $allowed_templates[ $template ] ) ) {
|
if ( isset( $allowed_templates[ $template ] ) ) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.6-beta1-49300';
|
$wp_version = '5.6-beta1-49301';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue