Make WordPress Core

Ticket #43502: 43502.4.diff

File 43502.4.diff, 1.8 KB (added by manzoorwani.jk, 6 years ago)
  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

     
    14081408         * @return WP_REST_Response Response object.
    14091409         */
    14101410        public function prepare_item_for_response( $post, $request ) {
     1411
     1412                $previous_post = null;
     1413                if ( ! empty( $GLOBALS['post'] ) ) {
     1414                        $previous_post = $GLOBALS['post'];
     1415                }
     1416
    14111417                $GLOBALS['post'] = $post;
    14121418
    14131419                setup_postdata( $post );
     
    16071613                        }
    16081614                }
    16091615
     1616                $GLOBALS['post'] = $previous_post;
     1617               
     1618                if ( $previous_post ) {
     1619                        setup_postdata( $previous_post );
     1620                }
     1621
    16101622                /**
    16111623                 * Filters the post data for a response.
    16121624                 *
  • src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php

     
    483483         * @return WP_REST_Response Response object.
    484484         */
    485485        public function prepare_item_for_response( $post, $request ) {
     486
     487                $previous_post = null;
     488                if ( ! empty( $GLOBALS['post'] ) ) {
     489                        $previous_post = $GLOBALS['post'];
     490                }
     491               
    486492                $GLOBALS['post'] = $post;
    487493
    488494                setup_postdata( $post );
     
    562568                        $response->add_link( 'parent', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->parent_base, $data['parent'] ) ) );
    563569                }
    564570
     571                $GLOBALS['post'] = $previous_post;
     572               
     573                if ( $previous_post ) {
     574                        setup_postdata( $previous_post );
     575                }
     576
    565577                /**
    566578                 * Filters a revision returned from the API.
    567579                 *