PluginProbe
Gutenberg / 24.1.0
Gutenberg v24.1.0
24.1.0 24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 All 404 releases
← All changes | lib/compat/wordpress-7.1/rest-api.php +29 -5 23.7.0 → 24.1.0 View file →
@@ -46,15 +46,39 @@
46 46 }
47 47 add_filter( 'rest_api_init', 'gutenberg_add_date_wp_template_schema' );
48 48
49 49 /**
50 - * Registers the Icon Collections Registry REST API routes.
50 + * Reports a `null` `modified` date for templates that have never been saved.
51 + *
52 + * `WP_REST_Templates_Controller::prepare_item_for_response()` passes the template's
53 + * `modified` property straight to `mysql_to_rfc3339()`, which returns `false` for
54 + * file-backed templates because they have no modification date. That value matches
55 + * neither the documented `string` type nor anything a client can format, so it is
56 + * replaced with `null` and the schema widened to allow it.
57 + *
58 + * @since 7.1.0 Allowed 'modified' to be null.
51 59 */
52 -function gutenberg_register_icon_collections_controller_endpoints() {
53 - $icon_collections_controller = new WP_REST_Icon_Collections_Controller();
54 - $icon_collections_controller->register_routes();
60 +function gutenberg_allow_null_modified_wp_template_field() {
61 + register_rest_field(
62 + array( 'wp_template', 'wp_template_part' ),
63 + 'modified',
64 + array(
65 + 'schema' => array(
66 + 'description' => __( "The date the template was last modified, in the site's timezone.", 'gutenberg' ),
67 + 'type' => array( 'string', 'null' ),
68 + 'format' => 'date-time',
69 + 'context' => array( 'view', 'edit' ),
70 + 'readonly' => true,
71 + ),
72 + // The controller has already converted the date by the time this runs, so
73 + // the prepared value is reused and only the `false` case is replaced.
74 + 'get_callback' => function ( $item ) {
75 + return isset( $item['modified'] ) && false !== $item['modified'] ? $item['modified'] : null;
76 + },
77 + )
78 + );
55 79 }
56 -add_action( 'rest_api_init', 'gutenberg_register_icon_collections_controller_endpoints' );
80 +add_action( 'rest_api_init', 'gutenberg_allow_null_modified_wp_template_field' );
57 81
58 82 /**
59 83 * Overrides the REST controller for the attachment post type to add support
60 84 * for filtering by multiple media types.