Make WordPress Core


Ignore:
Timestamp:
06/23/2023 06:27:45 AM (12 months 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/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php

    r55294 r55992  
    615615     * @since 5.8.0
    616616     * @since 5.9.0 Renamed `$template` to `$item` to match parent class for PHP 8 named parameter support.
     617     * @since 6.3.0 Added `modified` property to the response.
    617618     *
    618619     * @param WP_Block_Template $item    Template instance.
     
    707708        if ( rest_is_field_included( 'area', $fields ) && 'wp_template_part' === $template->type ) {
    708709            $data['area'] = $template->area;
     710        }
     711
     712        if ( rest_is_field_included( 'modified', $fields ) ) {
     713            $data['modified'] = mysql_to_rfc3339( $template->modified );
    709714        }
    710715
     
    927932                    'context'     => array( 'view', 'edit', 'embed' ),
    928933                ),
     934                'modified'       => array(
     935                    'description' => __( "The date the template was last modified, in the site's timezone." ),
     936                    'type'        => 'string',
     937                    'format'      => 'date-time',
     938                    'context'     => array( 'view', 'edit' ),
     939                    'readonly'    => true,
     940                ),
    929941            ),
    930942        );
Note: See TracChangeset for help on using the changeset viewer.