diff --git a/wp-includes/block-template-utils.php b/wp-includes/block-template-utils.php index f3eaf7b95a..3aba7f381d 100644 --- a/wp-includes/block-template-utils.php +++ b/wp-includes/block-template-utils.php @@ -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']; diff --git a/wp-includes/class-wp-block-template.php b/wp-includes/class-wp-block-template.php index 75bfd4747d..8149935203 100644 --- a/wp-includes/class-wp-block-template.php +++ b/wp-includes/class-wp-block-template.php @@ -146,4 +146,12 @@ class WP_Block_Template { * @var string|null */ public $area; + + /** + * Modified. + * + * @since 6.3.0 + * @var string|null + */ + public $modified; } diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php index df8a3dcd6d..d1854c5073 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php @@ -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, + ), ), ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 2586b8ddc5..9c0521072d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.