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 -29 23.6.2 → 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.
@@ -72,28 +96,4 @@
72 96 }
73 97 return $args;
74 98 }
75 99 add_filter( 'register_post_type_args', 'gutenberg_override_attachments_rest_controller', 10, 2 );
76 -
77 -/**
78 - * Overrides the default REST controller for autosaves to fix real-time
79 - * collaboration on draft posts.
80 - *
81 - * When RTC is enabled, draft autosaves from all users update the post directly
82 - * instead of creating per-user autosave revisions depending on post lock and
83 - * assigned author.
84 - *
85 - * Only overrides when autosave_rest_controller_class is not explicitly set,
86 - * i.e. when WP_REST_Autosaves_Controller would be used by default. Post types
87 - * with their own specialized autosave controller (e.g. templates) are left alone.
88 - *
89 - * @param array $args Array of arguments for registering a post type.
90 - * @return array Modified array of arguments.
91 - */
92 -function gutenberg_override_autosaves_rest_controller( $args ) {
93 - if ( empty( $args['autosave_rest_controller_class'] ) ) {
94 - $args['autosave_rest_controller_class'] = 'Gutenberg_REST_Autosaves_Controller';
95 - }
96 - return $args;
97 -}
98 -
99 -add_filter( 'register_post_type_args', 'gutenberg_override_autosaves_rest_controller', 10, 1 );