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
| 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 |