From 8d7063d65840cff39c895bb5bde31423c5d18846 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Fri, 12 Jul 2024 16:24:03 +0200 Subject: [PATCH] Add schemas for WordPress 6.6. --- composer.json | 2 +- packages/wp-types/index.ts | 43 ++++++++++++++ schemas/properties/post-type-labels.json | 3 + schemas/properties/taxonomy-labels.json | 4 ++ schemas/rest-api/attachment.json | 9 +++ schemas/rest-api/block.json | 27 +++++++++ schemas/rest-api/post.json | 9 +++ schemas/rest-api/type.json | 57 +++++++++++++++++++ tests/data/rest-api/routes/routes.json | 4 ++ .../routes/wp-v2-book-id-autosaves.json | 3 + tests/data/rest-api/routes/wp-v2-book-id.json | 3 + .../wp-v2-book-parent-autosaves-id.json | 3 + tests/data/rest-api/routes/wp-v2-book.json | 3 + tests/mu-plugins/mu-plugin.php | 17 ++++++ 14 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 tests/data/rest-api/routes/wp-v2-book-id-autosaves.json create mode 100644 tests/data/rest-api/routes/wp-v2-book-id.json create mode 100644 tests/data/rest-api/routes/wp-v2-book-parent-autosaves-id.json create mode 100644 tests/data/rest-api/routes/wp-v2-book.json diff --git a/composer.json b/composer.json index 1e0263d..0ebe16a 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "ext-pdo_sqlite": "*", "johnbillion/args": "1.7.0", "roots/wordpress-core-installer": "^1.0.0", - "roots/wordpress-full": "~6.5.0", + "roots/wordpress-full": "6.6-RC3", "wp-cli/core-command": "^2", "wp-cli/db-command": "^2", "wp-cli/language-command": "^2", diff --git a/packages/wp-types/index.ts b/packages/wp-types/index.ts index 2519a27..b123a82 100644 --- a/packages/wp-types/index.ts +++ b/packages/wp-types/index.ts @@ -984,6 +984,7 @@ export interface WP_Post_Type_Labels { item_link_description: string; menu_name: string; name_admin_bar: string; + template_name?: string; } /** * Post type capabilities. @@ -1723,6 +1724,7 @@ export interface WP_Taxonomy_Labels { item_link_description: string; menu_name: string; name_admin_bar: string; + template_name: string; } /** * Taxonomy capabilities. @@ -1957,6 +1959,10 @@ export interface WP_REST_API_Post { * A field used for ordering posts. */ menu_order?: number; + /** + * An array of the class names for the post container element. + */ + class_list: string[]; /** * The title for the post. */ @@ -2202,6 +2208,10 @@ export interface WP_REST_API_Attachment { * Slug automatically generated from the attachment title. Only present when using the 'edit' context and the post type is public. */ generated_slug?: string; + /** + * An array of the class names for the post container element. + */ + class_list: string[]; /** * The title for the attachment. */ @@ -2339,6 +2349,23 @@ export interface WP_REST_API_Block { */ protected: boolean; }; + /** + * The excerpt for the block. + */ + excerpt?: { + /** + * Excerpt for the block, as it exists in the database. Only present when using the 'edit' context. + */ + raw?: string; + /** + * HTML content for the post excerpt, transformed for display. + */ + rendered: string; + /** + * Whether the content is protected with a password. + */ + protected: boolean; + }; wp_pattern_sync_status: "" | "partial" | "unsynced"; /** * Pattern categories. @@ -3279,6 +3306,22 @@ export interface WP_REST_API_Type { * REST route's namespace for the post type. */ rest_namespace: string; + /** + * The block template associated with the post type. + */ + template?: ( + | [string] + | [ + string, + { + [k: string]: unknown; + }, + ] + )[]; + /** + * The template lock associated with the post type, or false if none. + */ + template_lock?: "all" | "insert" | false; /** * The visibility settings for the post type. Only present when using the 'edit' context. */ diff --git a/schemas/properties/post-type-labels.json b/schemas/properties/post-type-labels.json index 0afa819..14b366b 100644 --- a/schemas/properties/post-type-labels.json +++ b/schemas/properties/post-type-labels.json @@ -149,6 +149,9 @@ }, "name_admin_bar": { "type": "string" + }, + "template_name": { + "type": "string" } }, "additionalProperties": false diff --git a/schemas/properties/taxonomy-labels.json b/schemas/properties/taxonomy-labels.json index b02f71f..1c4da20 100644 --- a/schemas/properties/taxonomy-labels.json +++ b/schemas/properties/taxonomy-labels.json @@ -33,6 +33,7 @@ "back_to_items", "item_link", "item_link_description", + "template_name", "menu_name", "name_admin_bar" ], @@ -162,6 +163,9 @@ }, "name_admin_bar": { "type": "string" + }, + "template_name": { + "type": "string" } }, "additionalProperties": false diff --git a/schemas/rest-api/attachment.json b/schemas/rest-api/attachment.json index 14f5746..a8e2c04 100644 --- a/schemas/rest-api/attachment.json +++ b/schemas/rest-api/attachment.json @@ -16,6 +16,7 @@ "slug", "status", "type", + "class_list", "title", "author", "template", @@ -222,6 +223,14 @@ "description": "Slug automatically generated from the attachment title. Only present when using the 'edit' context and the post type is public.", "type": "string" }, + "class_list": { + "readOnly": true, + "description": "An array of the class names for the post container element.", + "type": "array", + "items": { + "type": "string" + } + }, "title": { "description": "The title for the attachment.", "type": "object", diff --git a/schemas/rest-api/block.json b/schemas/rest-api/block.json index 67bc176..19be0a7 100644 --- a/schemas/rest-api/block.json +++ b/schemas/rest-api/block.json @@ -153,6 +153,33 @@ }, "additionalProperties": false }, + "excerpt": { + "description": "The excerpt for the block.", + "type": "object", + "required": [ + "rendered", + "protected" + ], + "properties": { + "raw": { + "description": "Excerpt for the block, as it exists in the database. Only present when using the 'edit' context.", + "contentMediaType": "text/html", + "type": "string" + }, + "rendered": { + "readOnly": true, + "description": "HTML content for the post excerpt, transformed for display.", + "contentMediaType": "text/html", + "type": "string" + }, + "protected": { + "readOnly": true, + "description": "Whether the content is protected with a password.", + "type": "boolean" + } + }, + "additionalProperties": false + }, "wp_pattern_sync_status": { "type": "string", "enum": [ diff --git a/schemas/rest-api/post.json b/schemas/rest-api/post.json index 010d2f3..9da7e14 100644 --- a/schemas/rest-api/post.json +++ b/schemas/rest-api/post.json @@ -15,6 +15,7 @@ "slug", "status", "type", + "class_list", "title", "content", "author", @@ -144,6 +145,14 @@ "description": "A field used for ordering posts.", "type": "integer" }, + "class_list": { + "readOnly": true, + "description": "An array of the class names for the post container element.", + "type": "array", + "items": { + "type": "string" + } + }, "title": { "description": "The title for the post.", "type": "object", diff --git a/schemas/rest-api/type.json b/schemas/rest-api/type.json index 6b0ac80..3cb374c 100644 --- a/schemas/rest-api/type.json +++ b/schemas/rest-api/type.json @@ -98,6 +98,63 @@ "description": "REST route's namespace for the post type.", "type": "string" }, + "template": { + "description": "The block template associated with the post type.", + "examples": [ + [ + [ + "core/image" + ] + ], + [ + [ + "core/image" + ], + [ + "core/paragraph", + { + "placeholder": "Image Details" + } + ] + ] + ], + "type": "array", + "items": { + "oneOf": [ + { + "type": "array", + "items": [ + { + "type": "string" + } + ], + "minItems": 1, + "maxItems": 1 + }, + { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "object" + } + ], + "minItems": 2, + "maxItems": 2 + } + ] + } + }, + "template_lock": { + "description": "The template lock associated with the post type, or false if none.", + "enum": [ + "all", + "insert", + false + ] + }, "visibility": { "description": "The visibility settings for the post type. Only present when using the 'edit' context.", "type": "object", diff --git a/tests/data/rest-api/routes/routes.json b/tests/data/rest-api/routes/routes.json index 30e6705..3e2a40f 100644 --- a/tests/data/rest-api/routes/routes.json +++ b/tests/data/rest-api/routes/routes.json @@ -13,6 +13,10 @@ "/wp/v2/blocks/(?P[\\d]+)/autosaves/(?P[\\d]+)", "/wp/v2/blocks/(?P[\\d]+)/revisions", "/wp/v2/blocks/(?P[\\d]+)/revisions/(?P[\\d]+)", + "/wp/v2/book", + "/wp/v2/book/(?P[\\d]+)", + "/wp/v2/book/(?P[\\d]+)/autosaves", + "/wp/v2/book/(?P[\\d]+)/autosaves/(?P[\\d]+)", "/wp/v2/categories", "/wp/v2/categories/(?P[\\d]+)", "/wp/v2/comments", diff --git a/tests/data/rest-api/routes/wp-v2-book-id-autosaves.json b/tests/data/rest-api/routes/wp-v2-book-id-autosaves.json new file mode 100644 index 0000000..a4a7d2a --- /dev/null +++ b/tests/data/rest-api/routes/wp-v2-book-id-autosaves.json @@ -0,0 +1,3 @@ +{ + "route": "/wp/v2/book/(?P[\\d]+)/autosaves" +} \ No newline at end of file diff --git a/tests/data/rest-api/routes/wp-v2-book-id.json b/tests/data/rest-api/routes/wp-v2-book-id.json new file mode 100644 index 0000000..77affbb --- /dev/null +++ b/tests/data/rest-api/routes/wp-v2-book-id.json @@ -0,0 +1,3 @@ +{ + "route": "/wp/v2/book/(?P[\\d]+)" +} \ No newline at end of file diff --git a/tests/data/rest-api/routes/wp-v2-book-parent-autosaves-id.json b/tests/data/rest-api/routes/wp-v2-book-parent-autosaves-id.json new file mode 100644 index 0000000..7b48d0f --- /dev/null +++ b/tests/data/rest-api/routes/wp-v2-book-parent-autosaves-id.json @@ -0,0 +1,3 @@ +{ + "route": "/wp/v2/book/(?P[\\d]+)/autosaves/(?P[\\d]+)" +} \ No newline at end of file diff --git a/tests/data/rest-api/routes/wp-v2-book.json b/tests/data/rest-api/routes/wp-v2-book.json new file mode 100644 index 0000000..880253a --- /dev/null +++ b/tests/data/rest-api/routes/wp-v2-book.json @@ -0,0 +1,3 @@ +{ + "route": "/wp/v2/book" +} \ No newline at end of file diff --git a/tests/mu-plugins/mu-plugin.php b/tests/mu-plugins/mu-plugin.php index c7be522..9cb2e23 100644 --- a/tests/mu-plugins/mu-plugin.php +++ b/tests/mu-plugins/mu-plugin.php @@ -33,6 +33,23 @@ // Ensure we're authenticated as an admin during test data generation. grant_super_admin( 1 ); wp_set_current_user( 1 ); + + register_post_type( 'book', [ + 'public' => true, + 'label' => 'Books', + 'show_in_rest' => true, + 'template' => [ + [ + 'core/paragraph', + [ + 'placeholder' => 'Add a description of the book', + ], + ], + [ + 'core/paragraph', + ], + ], + ] ); } ); /**