WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/24/2020 02:10:26 PM (12 months ago)
Author:
TimothyBlynJacobs
Message:

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.

File:
1 edited

Legend:

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

    r49172 r49301  
    13451345
    13461346        if ( $request['id'] ) {
     1347            $post             = get_post( $request['id'] );
    13471348            $current_template = get_page_template_slug( $request['id'] );
    13481349        } else {
     1350            $post             = null;
    13491351            $current_template = '';
    13501352        }
     
    13561358
    13571359        // If this is a create request, get_post() will return null and wp theme will fallback to the passed post type.
    1358         $allowed_templates = wp_get_theme()->get_page_templates( get_post( $request['id'] ), $this->post_type );
     1360        $allowed_templates = wp_get_theme()->get_page_templates( $post, $this->post_type );
    13591361
    13601362        if ( isset( $allowed_templates[ $template ] ) ) {
Note: See TracChangeset for help on using the changeset viewer.