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.

Built from https://develop.svn.wordpress.org/trunk@55992


git-svn-id: http://core.svn.wordpress.org/trunk@55504 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
isabel_brison 2023-06-23 06:29:23 +00:00
parent bfce1cef9a
commit 19dda6b262
4 changed files with 25 additions and 1 deletions

View File

@ -542,6 +542,7 @@ function _remove_theme_attribute_in_block_template_content( $template_content )
* Builds a unified template object based on a theme file.
*
* @since 5.9.0
* @since 6.3.0 Added `modified` property to template objects.
* @access private
*
* @param array $template_file Theme file.
@ -564,6 +565,7 @@ function _build_block_template_result_from_file( $template_file, $template_type
$template->status = 'publish';
$template->has_theme_file = true;
$template->is_custom = true;
$template->modified = null;
if ( 'wp_template' === $template_type && isset( $default_template_types[ $template_file['slug'] ] ) ) {
$template->description = $default_template_types[ $template_file['slug'] ]['description'];
@ -743,6 +745,7 @@ function _wp_build_title_and_description_for_taxonomy_block_template( $taxonomy,
* Builds a unified template object based a post Object.
*
* @since 5.9.0
* @since 6.3.0 Added `modified` property to template objects.
* @access private
*
* @param WP_Post $post Template post.
@ -782,6 +785,7 @@ function _build_block_template_result_from_post( $post ) {
$template->has_theme_file = $has_theme_file;
$template->is_custom = empty( $is_wp_suggestion );
$template->author = $post->post_author;
$template->modified = $post->post_modified;
if ( 'wp_template' === $post->post_type && $has_theme_file && isset( $template_file['postTypes'] ) ) {
$template->post_types = $template_file['postTypes'];

View File

@ -146,4 +146,12 @@ class WP_Block_Template {
* @var string|null
*/
public $area;
/**
* Modified.
*
* @since 6.3.0
* @var string|null
*/
public $modified;
}

View File

@ -614,6 +614,7 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
*
* @since 5.8.0
* @since 5.9.0 Renamed `$template` to `$item` to match parent class for PHP 8 named parameter support.
* @since 6.3.0 Added `modified` property to the response.
*
* @param WP_Block_Template $item Template instance.
* @param WP_REST_Request $request Request object.
@ -708,6 +709,10 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
$data['area'] = $template->area;
}
if ( rest_is_field_included( 'modified', $fields ) ) {
$data['modified'] = mysql_to_rfc3339( $template->modified );
}
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
@ -926,6 +931,13 @@ class WP_REST_Templates_Controller extends WP_REST_Controller {
'type' => 'integer',
'context' => array( 'view', 'edit', 'embed' ),
),
'modified' => array(
'description' => __( "The date the template was last modified, in the site's timezone." ),
'type' => 'string',
'format' => 'date-time',
'context' => array( 'view', 'edit' ),
'readonly' => true,
),
),
);

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.3-alpha-55991';
$wp_version = '6.3-alpha-55992';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.