Make WordPress Core


Ignore:
Timestamp:
06/23/2023 06:27:45 AM (3 years ago)
Author:
isabel_brison
Message:

REST API: return post modified datetime for Templates.

Adds a modified field to the template and template part objects in the rest response for WP_REST_Templates_Controller.

Props ramonopoly, andrewserong, mukesh27, timothyblynjacobs.
Fixes #58540.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php

    r55562 r55992  
    119119                                'is_custom'      => true,
    120120                                'author'         => 0,
     121                                'modified'       => mysql_to_rfc3339( self::$post->post_modified ),
    121122                        ),
    122123                        $this->find_and_normalize_template_by_id( $data, 'default//my_template' )
     
    163164                                'is_custom'      => true,
    164165                                'author'         => 0,
     166                                'modified'       => mysql_to_rfc3339( self::$post->post_modified ),
    165167                        ),
    166168                        $data
     
    199201                                'is_custom'      => true,
    200202                                'author'         => 0,
     203                                'modified'       => mysql_to_rfc3339( self::$post->post_modified ),
    201204                        ),
    202205                        $data
     
    258261                                'is_custom'      => true,
    259262                                'author'         => self::$admin_id,
     263                                'modified'       => mysql_to_rfc3339( $post->post_modified ),
    260264                        ),
    261265                        $data
     
    414418                $response = rest_get_server()->dispatch( $request );
    415419                $data     = $response->get_data();
     420                $modified = get_post( $data['wp_id'] )->post_modified;
    416421                unset( $data['_links'] );
    417422                unset( $data['wp_id'] );
     
    437442                                'is_custom'      => true,
    438443                                'author'         => self::$admin_id,
     444                                'modified'       => mysql_to_rfc3339( $modified ),
    439445                        ),
    440446                        $data
     
    460466                $response = rest_get_server()->dispatch( $request );
    461467                $data     = $response->get_data();
     468                $modified = get_post( $data['wp_id'] )->post_modified;
    462469                unset( $data['_links'] );
    463470                unset( $data['wp_id'] );
     
    483490                                'is_custom'      => false,
    484491                                'author'         => self::$admin_id,
     492                                'modified'       => mysql_to_rfc3339( $modified ),
    485493                        ),
    486494                        $data
     
    510518                $response = rest_get_server()->dispatch( $request );
    511519                $data     = $response->get_data();
     520                $modified = get_post( $data['wp_id'] )->post_modified;
    512521                unset( $data['_links'] );
    513522                unset( $data['wp_id'] );
     
    533542                                'is_custom'      => true,
    534543                                'author'         => self::$admin_id,
     544                                'modified'       => mysql_to_rfc3339( $modified ),
    535545                        ),
    536546                        $data
     
    691701                $data       = $response->get_data();
    692702                $properties = $data['schema']['properties'];
    693                 $this->assertCount( 14, $properties );
     703                $this->assertCount( 15, $properties );
    694704                $this->assertArrayHasKey( 'id', $properties );
    695705                $this->assertArrayHasKey( 'description', $properties );
     
    707717                $this->assertArrayHasKey( 'is_custom', $properties );
    708718                $this->assertArrayHasKey( 'author', $properties );
     719                $this->assertArrayHasKey( 'modified', $properties );
    709720        }
    710721
     
    737748                $request = new WP_REST_Request( 'POST', '/wp/v2/templates' );
    738749                $request->set_body_params( $body_params );
    739                 $response = rest_get_server()->dispatch( $request );
    740                 $data     = $response->get_data();
     750                $response             = rest_get_server()->dispatch( $request );
     751                $data                 = $response->get_data();
     752                $modified             = get_post( $data['wp_id'] )->post_modified;
     753                $expected['modified'] = mysql_to_rfc3339( $modified );
    741754                unset( $data['_links'] );
    742755                unset( $data['wp_id'] );
Note: See TracChangeset for help on using the changeset viewer.