PluginProbe
Gutenberg / 23.2.0
Gutenberg v23.2.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 12.6.0 All 403 releases
gutenberg / lib / experimental / rest-api-overrides.php
lib/experimental
connectors 3 months ago content-types 3 months ago dashboard-widgets 3 months ago experiments 3 months ago font-face 1 year ago guidelines 3 months ago interactivity-api 1 year ago media-editor 3 months ago pages 6 months ago block-editor-settings-mobile.php 888 B 2 years ago blocks.php 4.4 KB 7 months ago class-gutenberg-hierarchical-sort.php 4.7 KB 6 months ago class-wp-rest-block-editor-settings-controller.php 24.2 KB 7 months ago editor-settings.php 3.3 KB 3 months ago extensible-site-editor.php 975 B 7 months ago kses-allowed-html.php 965 B 1 year ago kses.php 6.2 KB 5 months ago navigation-theme-opt-in.php 13.3 KB 6 months ago rest-api-overrides.php 1.6 KB 9 months ago rest-api.php 3.2 KB 7 months ago script-modules.php 7.9 KB 6 months ago workflow-palette.php 355 B 9 months ago

rest-api-overrides.php in Gutenberg 23.2.0, at lib/experimental/rest-api-overrides.php

53 lines 1.6 KB Raw Download Zip
1 <?php
2 /**
3 * Boot package REST API overrides.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Allow auto-draft status in WordPress REST API for all post types.
10 *
11 * By default, WordPress REST API doesn't include 'auto-draft' in the
12 * allowed status values. This function adds it to the schema enum for
13 * all eligible post types.
14 */
15 function gutenberg_boot_allow_auto_draft_in_rest_api() {
16 $auto_draft_filter = function ( $schema ) {
17 if ( isset( $schema['properties']['status']['enum'] ) ) {
18 $schema['properties']['status']['enum'][] = 'auto-draft';
19 }
20 return $schema;
21 };
22
23 // Get post types that should support auto-draft.
24 $post_types = get_post_types(
25 array(
26 'show_in_rest' => true,
27 'show_ui' => true,
28 ),
29 'objects'
30 );
31
32 foreach ( $post_types as $post_type ) {
33 $supports_editor = post_type_supports( $post_type->name, 'editor' );
34 $supports_title = post_type_supports( $post_type->name, 'title' );
35 $is_wp_core_system = strpos( $post_type->name, 'wp_' ) === 0;
36 $is_attachment = 'attachment' === $post_type->name;
37
38 // Only add auto-draft to content post types:
39 // - Must support either editor or title (content editing capabilities).
40 // - Exclude WordPress core system types (wp_block, wp_navigation, etc.).
41 // - Exclude attachments (media files don't need auto-draft status).
42 $should_support_auto_draft = ( $supports_editor || $supports_title ) &&
43 ! $is_wp_core_system &&
44 ! $is_attachment;
45
46 if ( $should_support_auto_draft ) {
47 add_filter( "rest_{$post_type->name}_item_schema", $auto_draft_filter );
48 }
49 }
50 }
51
52 add_action( 'rest_api_init', 'gutenberg_boot_allow_auto_draft_in_rest_api' );
53