author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
9 | 1 |
<?php |
2 |
/** |
|
16 | 3 |
* The block editor page. |
9 | 4 |
* |
5 |
* @since 5.0.0 |
|
6 |
* |
|
7 |
* @package WordPress |
|
8 |
* @subpackage Administration |
|
9 |
*/ |
|
10 |
||
16 | 11 |
// Don't load directly. |
9 | 12 |
if ( ! defined( 'ABSPATH' ) ) { |
13 |
die( '-1' ); |
|
14 |
} |
|
15 |
||
16 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
17 |
* @global string $post_type Global post type. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
18 |
* @global WP_Post_Type $post_type_object Global post type object. |
16 | 19 |
* @global WP_Post $post Global post object. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
20 |
* @global string $title The title of the current screen. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
21 |
* @global array $wp_meta_boxes Global meta box state. |
9 | 22 |
*/ |
18 | 23 |
global $post_type, $post_type_object, $post, $title, $wp_meta_boxes; |
24 |
||
25 |
$block_editor_context = new WP_Block_Editor_Context( array( 'post' => $post ) ); |
|
9 | 26 |
|
27 |
// Flag that we're loading the block editor. |
|
28 |
$current_screen = get_current_screen(); |
|
29 |
$current_screen->is_block_editor( true ); |
|
30 |
||
18 | 31 |
// Default to is-fullscreen-mode to avoid jumps in the UI. |
32 |
add_filter( |
|
33 |
'admin_body_class', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
34 |
static function ( $classes ) { |
18 | 35 |
return "$classes is-fullscreen-mode"; |
36 |
} |
|
37 |
); |
|
38 |
||
9 | 39 |
/* |
40 |
* Emoji replacement is disabled for now, until it plays nicely with React. |
|
41 |
*/ |
|
42 |
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); |
|
43 |
||
18 | 44 |
/* |
45 |
* Block editor implements its own Options menu for toggling Document Panels. |
|
46 |
*/ |
|
47 |
add_filter( 'screen_options_show_screen', '__return_false' ); |
|
48 |
||
9 | 49 |
wp_enqueue_script( 'heartbeat' ); |
50 |
wp_enqueue_script( 'wp-edit-post' ); |
|
51 |
||
19 | 52 |
$rest_path = rest_get_route_for_post( $post ); |
9 | 53 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
54 |
$active_theme = get_stylesheet(); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
55 |
$global_styles_endpoint_context = current_user_can( 'edit_theme_options' ) ? 'edit' : 'view'; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
56 |
$template_lookup_slug = 'page' === $post->post_type ? 'page' : 'single-' . $post->post_type; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
57 |
if ( ! empty( $post->post_name ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
58 |
$template_lookup_slug .= '-' . $post->post_name; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
59 |
} |
9 | 60 |
// Preload common data. |
61 |
$preload_paths = array( |
|
19 | 62 |
'/wp/v2/types?context=view', |
63 |
'/wp/v2/taxonomies?context=view', |
|
64 |
add_query_arg( 'context', 'edit', $rest_path ), |
|
9 | 65 |
sprintf( '/wp/v2/types/%s?context=edit', $post_type ), |
19 | 66 |
'/wp/v2/users/me', |
67 |
array( rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ), |
|
68 |
array( rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ), |
|
69 |
array( rest_get_route_for_post_type_items( 'wp_block' ), 'OPTIONS' ), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
70 |
array( rest_get_route_for_post_type_items( 'wp_template' ), 'OPTIONS' ), |
19 | 71 |
sprintf( '%s/autosaves?context=edit', $rest_path ), |
72 |
'/wp/v2/settings', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
73 |
array( '/wp/v2/settings', 'OPTIONS' ), |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
74 |
'/wp/v2/global-styles/themes/' . $active_theme . '?context=view', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
75 |
'/wp/v2/global-styles/themes/' . $active_theme . '/variations?context=view', |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
76 |
'/wp/v2/themes?context=edit&status=active', |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
77 |
array( '/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id(), 'OPTIONS' ), |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
78 |
/* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
79 |
* Preload the global styles path with the correct context based on user caps. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
80 |
* NOTE: There is an equivalent conditional check in the client-side code to fetch |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
81 |
* the global styles entity using the appropriate context value. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
82 |
* See the call to `canUser()`, under `useGlobalStylesUserConfig()` in `packages/edit-site/src/components/use-global-styles-user-config/index.js`. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
83 |
* Please ensure that the equivalent check is kept in sync with this preload path. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
84 |
*/ |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
85 |
'/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=' . $global_styles_endpoint_context, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
86 |
// Used by getBlockPatternCategories in useBlockEditorSettings. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
87 |
'/wp/v2/block-patterns/categories', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
88 |
// @see packages/core-data/src/entities.js |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
89 |
'/?_fields=' . implode( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
90 |
',', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
91 |
array( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
92 |
'description', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
93 |
'gmt_offset', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
94 |
'home', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
95 |
'name', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
96 |
'site_icon', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
97 |
'site_icon_url', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
98 |
'site_logo', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
99 |
'timezone_string', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
100 |
'url', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
101 |
'page_for_posts', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
102 |
'page_on_front', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
103 |
'show_on_front', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
104 |
) |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
105 |
), |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
106 |
$paths[] = add_query_arg( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
107 |
'slug', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
108 |
// @see https://github.com/WordPress/gutenberg/blob/e093fefd041eb6cc4a4e7f67b92ab54fd75c8858/packages/core-data/src/private-selectors.ts#L244-L254 |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
109 |
$template_lookup_slug, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
110 |
'/wp/v2/templates/lookup' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
111 |
), |
9 | 112 |
); |
113 |
||
18 | 114 |
block_editor_rest_api_preload( $preload_paths, $block_editor_context ); |
9 | 115 |
|
116 |
wp_add_inline_script( |
|
117 |
'wp-blocks', |
|
118 |
sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $post ) ) ), |
|
119 |
'after' |
|
120 |
); |
|
121 |
||
122 |
/* |
|
123 |
* Assign initial edits, if applicable. These are not initially assigned to the persisted post, |
|
124 |
* but should be included in its save payload. |
|
125 |
*/ |
|
19 | 126 |
$initial_edits = array(); |
9 | 127 |
$is_new_post = false; |
128 |
if ( 'auto-draft' === $post->post_status ) { |
|
129 |
$is_new_post = true; |
|
130 |
// Override "(Auto Draft)" new post default title with empty string, or filtered value. |
|
19 | 131 |
if ( post_type_supports( $post->post_type, 'title' ) ) { |
132 |
$initial_edits['title'] = $post->post_title; |
|
133 |
} |
|
134 |
||
135 |
if ( post_type_supports( $post->post_type, 'editor' ) ) { |
|
136 |
$initial_edits['content'] = $post->post_content; |
|
137 |
} |
|
138 |
||
139 |
if ( post_type_supports( $post->post_type, 'excerpt' ) ) { |
|
140 |
$initial_edits['excerpt'] = $post->post_excerpt; |
|
141 |
} |
|
9 | 142 |
} |
143 |
||
144 |
// Preload server-registered block schemas. |
|
145 |
wp_add_inline_script( |
|
146 |
'wp-blocks', |
|
147 |
'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' |
|
148 |
); |
|
149 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
150 |
// Preload server-registered block bindings sources. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
151 |
$registered_sources = get_all_registered_block_bindings_sources(); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
152 |
if ( ! empty( $registered_sources ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
153 |
$filtered_sources = array(); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
154 |
foreach ( $registered_sources as $source ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
155 |
$filtered_sources[] = array( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
156 |
'name' => $source->name, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
157 |
'label' => $source->label, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
158 |
'usesContext' => $source->uses_context, |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
159 |
); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
160 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
161 |
$script = sprintf( 'for ( const source of %s ) { wp.blocks.registerBlockBindingsSource( source ); }', wp_json_encode( $filtered_sources ) ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
162 |
wp_add_inline_script( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
163 |
'wp-blocks', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
164 |
$script |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
165 |
); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
166 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
167 |
|
9 | 168 |
// Get admin url for handling meta boxes. |
169 |
$meta_box_url = admin_url( 'post.php' ); |
|
170 |
$meta_box_url = add_query_arg( |
|
171 |
array( |
|
172 |
'post' => $post->ID, |
|
173 |
'action' => 'edit', |
|
174 |
'meta-box-loader' => true, |
|
175 |
'meta-box-loader-nonce' => wp_create_nonce( 'meta-box-loader' ), |
|
176 |
), |
|
177 |
$meta_box_url |
|
178 |
); |
|
18 | 179 |
wp_add_inline_script( |
180 |
'wp-editor', |
|
181 |
sprintf( 'var _wpMetaBoxUrl = %s;', wp_json_encode( $meta_box_url ) ), |
|
182 |
'before' |
|
183 |
); |
|
9 | 184 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
185 |
// Set Heartbeat interval to 10 seconds, used to refresh post locks. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
186 |
wp_add_inline_script( |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
187 |
'heartbeat', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
188 |
'jQuery( function() { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
189 |
wp.heartbeat.interval( 10 ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
190 |
} );', |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
191 |
'after' |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
192 |
); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
193 |
|
16 | 194 |
/* |
195 |
* Get all available templates for the post/page attributes meta-box. |
|
196 |
* The "Default template" array element should only be added if the array is |
|
197 |
* not empty so we do not trigger the template select element without any options |
|
198 |
* besides the default value. |
|
199 |
*/ |
|
9 | 200 |
$available_templates = wp_get_theme()->get_page_templates( get_post( $post->ID ) ); |
18 | 201 |
$available_templates = ! empty( $available_templates ) ? array_replace( |
9 | 202 |
array( |
203 |
/** This filter is documented in wp-admin/includes/meta-boxes.php */ |
|
204 |
'' => apply_filters( 'default_page_template_title', __( 'Default template' ), 'rest-api' ), |
|
205 |
), |
|
206 |
$available_templates |
|
207 |
) : $available_templates; |
|
208 |
||
209 |
// Lock settings. |
|
210 |
$user_id = wp_check_post_lock( $post->ID ); |
|
211 |
if ( $user_id ) { |
|
212 |
$locked = false; |
|
213 |
||
214 |
/** This filter is documented in wp-admin/includes/post.php */ |
|
215 |
if ( apply_filters( 'show_post_locked_dialog', true, $post, $user_id ) ) { |
|
216 |
$locked = true; |
|
217 |
} |
|
218 |
||
219 |
$user_details = null; |
|
220 |
if ( $locked ) { |
|
221 |
$user = get_userdata( $user_id ); |
|
222 |
$user_details = array( |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
223 |
'name' => $user->display_name, |
9 | 224 |
); |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
225 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
226 |
if ( get_option( 'show_avatars' ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
227 |
$user_details['avatar'] = get_avatar_url( $user_id, array( 'size' => 128 ) ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
228 |
} |
9 | 229 |
} |
230 |
||
231 |
$lock_details = array( |
|
232 |
'isLocked' => $locked, |
|
233 |
'user' => $user_details, |
|
234 |
); |
|
235 |
} else { |
|
236 |
// Lock the post. |
|
237 |
$active_post_lock = wp_set_post_lock( $post->ID ); |
|
16 | 238 |
if ( $active_post_lock ) { |
239 |
$active_post_lock = esc_attr( implode( ':', $active_post_lock ) ); |
|
240 |
} |
|
241 |
||
242 |
$lock_details = array( |
|
9 | 243 |
'isLocked' => false, |
16 | 244 |
'activePostLock' => $active_post_lock, |
9 | 245 |
); |
246 |
} |
|
247 |
||
248 |
/** |
|
249 |
* Filters the body placeholder text. |
|
250 |
* |
|
251 |
* @since 5.0.0 |
|
18 | 252 |
* @since 5.8.0 Changed the default placeholder text. |
9 | 253 |
* |
18 | 254 |
* @param string $text Placeholder text. Default 'Type / to choose a block'. |
9 | 255 |
* @param WP_Post $post Post object. |
256 |
*/ |
|
18 | 257 |
$body_placeholder = apply_filters( 'write_your_story', __( 'Type / to choose a block' ), $post ); |
9 | 258 |
|
259 |
$editor_settings = array( |
|
19 | 260 |
'availableTemplates' => $available_templates, |
261 |
'disablePostFormats' => ! current_theme_supports( 'post-formats' ), |
|
9 | 262 |
/** This filter is documented in wp-admin/edit-form-advanced.php */ |
19 | 263 |
'titlePlaceholder' => apply_filters( 'enter_title_here', __( 'Add title' ), $post ), |
264 |
'bodyPlaceholder' => $body_placeholder, |
|
265 |
'autosaveInterval' => AUTOSAVE_INTERVAL, |
|
266 |
'richEditingEnabled' => user_can_richedit(), |
|
267 |
'postLock' => $lock_details, |
|
268 |
'postLockUtils' => array( |
|
9 | 269 |
'nonce' => wp_create_nonce( 'lock-post_' . $post->ID ), |
270 |
'unlockNonce' => wp_create_nonce( 'update-post_' . $post->ID ), |
|
271 |
'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
|
272 |
), |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
273 |
'supportsLayout' => wp_theme_has_theme_json(), |
19 | 274 |
'supportsTemplateMode' => current_theme_supports( 'block-templates' ), |
9 | 275 |
|
276 |
// Whether or not to load the 'postcustom' meta box is stored as a user meta |
|
277 |
// field so that we're not always loading its assets. |
|
19 | 278 |
'enableCustomFields' => (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ), |
9 | 279 |
); |
280 |
||
19 | 281 |
// Add additional back-compat patterns registered by `current_screen` et al. |
282 |
$editor_settings['__experimentalAdditionalBlockPatterns'] = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true ); |
|
283 |
$editor_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true ); |
|
284 |
||
18 | 285 |
$autosave = wp_get_post_autosave( $post->ID ); |
9 | 286 |
if ( $autosave ) { |
287 |
if ( mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) { |
|
288 |
$editor_settings['autosave'] = array( |
|
289 |
'editLink' => get_edit_post_link( $autosave->ID ), |
|
290 |
); |
|
291 |
} else { |
|
292 |
wp_delete_post_revision( $autosave->ID ); |
|
293 |
} |
|
294 |
} |
|
295 |
||
296 |
if ( ! empty( $post_type_object->template ) ) { |
|
297 |
$editor_settings['template'] = $post_type_object->template; |
|
298 |
$editor_settings['templateLock'] = ! empty( $post_type_object->template_lock ) ? $post_type_object->template_lock : false; |
|
299 |
} |
|
300 |
||
301 |
// If there's no template set on a new post, use the post format, instead. |
|
302 |
if ( $is_new_post && ! isset( $editor_settings['template'] ) && 'post' === $post->post_type ) { |
|
303 |
$post_format = get_post_format( $post ); |
|
304 |
if ( in_array( $post_format, array( 'audio', 'gallery', 'image', 'quote', 'video' ), true ) ) { |
|
305 |
$editor_settings['template'] = array( array( "core/$post_format" ) ); |
|
306 |
} |
|
307 |
} |
|
308 |
||
19 | 309 |
if ( wp_is_block_theme() && $editor_settings['supportsTemplateMode'] ) { |
310 |
$editor_settings['defaultTemplatePartAreas'] = get_allowed_block_template_part_areas(); |
|
311 |
} |
|
312 |
||
9 | 313 |
/** |
314 |
* Scripts |
|
315 |
*/ |
|
316 |
wp_enqueue_media( |
|
317 |
array( |
|
318 |
'post' => $post->ID, |
|
319 |
) |
|
320 |
); |
|
321 |
wp_tinymce_inline_scripts(); |
|
322 |
wp_enqueue_editor(); |
|
323 |
||
324 |
/** |
|
325 |
* Styles |
|
326 |
*/ |
|
327 |
wp_enqueue_style( 'wp-edit-post' ); |
|
328 |
||
329 |
/** |
|
330 |
* Fires after block assets have been enqueued for the editing interface. |
|
331 |
* |
|
332 |
* Call `add_action` on any hook before 'admin_enqueue_scripts'. |
|
333 |
* |
|
334 |
* In the function call you supply, simply use `wp_enqueue_script` and |
|
335 |
* `wp_enqueue_style` to add your functionality to the block editor. |
|
336 |
* |
|
337 |
* @since 5.0.0 |
|
338 |
*/ |
|
339 |
do_action( 'enqueue_block_editor_assets' ); |
|
340 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
341 |
// In order to duplicate classic meta box behavior, we need to run the classic meta box actions. |
16 | 342 |
require_once ABSPATH . 'wp-admin/includes/meta-boxes.php'; |
9 | 343 |
register_and_do_post_meta_boxes( $post ); |
344 |
||
345 |
// Check if the Custom Fields meta box has been removed at some point. |
|
346 |
$core_meta_boxes = $wp_meta_boxes[ $current_screen->id ]['normal']['core']; |
|
347 |
if ( ! isset( $core_meta_boxes['postcustom'] ) || ! $core_meta_boxes['postcustom'] ) { |
|
348 |
unset( $editor_settings['enableCustomFields'] ); |
|
349 |
} |
|
350 |
||
18 | 351 |
$editor_settings = get_block_editor_settings( $editor_settings, $block_editor_context ); |
9 | 352 |
|
353 |
$init_script = <<<JS |
|
354 |
( function() { |
|
355 |
window._wpLoadBlockEditor = new Promise( function( resolve ) { |
|
356 |
wp.domReady( function() { |
|
357 |
resolve( wp.editPost.initializeEditor( 'editor', "%s", %d, %s, %s ) ); |
|
358 |
} ); |
|
359 |
} ); |
|
360 |
} )(); |
|
361 |
JS; |
|
362 |
||
363 |
$script = sprintf( |
|
364 |
$init_script, |
|
365 |
$post->post_type, |
|
366 |
$post->ID, |
|
367 |
wp_json_encode( $editor_settings ), |
|
368 |
wp_json_encode( $initial_edits ) |
|
369 |
); |
|
370 |
wp_add_inline_script( 'wp-edit-post', $script ); |
|
371 |
||
18 | 372 |
if ( (int) get_option( 'page_for_posts' ) === $post->ID ) { |
373 |
add_action( 'admin_enqueue_scripts', '_wp_block_editor_posts_page_notice' ); |
|
374 |
} |
|
375 |
||
16 | 376 |
require_once ABSPATH . 'wp-admin/admin-header.php'; |
9 | 377 |
?> |
378 |
||
379 |
<div class="block-editor"> |
|
380 |
<h1 class="screen-reader-text hide-if-no-js"><?php echo esc_html( $title ); ?></h1> |
|
381 |
<div id="editor" class="block-editor__container hide-if-no-js"></div> |
|
382 |
<div id="metaboxes" class="hidden"> |
|
383 |
<?php the_block_editor_meta_boxes(); ?> |
|
384 |
</div> |
|
385 |
||
386 |
<?php // JavaScript is disabled. ?> |
|
387 |
<div class="wrap hide-if-js block-editor-no-js"> |
|
388 |
<h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
389 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
390 |
if ( file_exists( WP_PLUGIN_DIR . '/classic-editor/classic-editor.php' ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
391 |
// If Classic Editor is already installed, provide a link to activate the plugin. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
392 |
$installed = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
393 |
$plugin_activate_url = wp_nonce_url( 'plugins.php?action=activate&plugin=classic-editor/classic-editor.php', 'activate-plugin_classic-editor/classic-editor.php' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
394 |
$message = sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
395 |
/* translators: %s: Link to activate the Classic Editor plugin. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
396 |
__( 'The block editor requires JavaScript. Please enable JavaScript in your browser settings, or activate the <a href="%s">Classic Editor plugin</a>.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
397 |
esc_url( $plugin_activate_url ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
398 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
399 |
} else { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
400 |
// If Classic Editor is not installed, provide a link to install it. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
401 |
$installed = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
402 |
$plugin_install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=classic-editor' ), 'install-plugin_classic-editor' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
403 |
$message = sprintf( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
404 |
/* translators: %s: Link to install the Classic Editor plugin. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
405 |
__( 'The block editor requires JavaScript. Please enable JavaScript in your browser settings, or install the <a href="%s">Classic Editor plugin</a>.' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
406 |
esc_url( $plugin_install_url ) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
407 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
408 |
} |
9 | 409 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
410 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
411 |
* Filters the message displayed in the block editor interface when JavaScript is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
412 |
* not enabled in the browser. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
413 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
414 |
* @since 5.0.3 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
415 |
* @since 6.4.0 Added `$installed` parameter. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
416 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
417 |
* @param string $message The message being displayed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
418 |
* @param WP_Post $post The post being edited. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
419 |
* @param bool $installed Whether the classic editor is installed. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
420 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
421 |
$message = apply_filters( 'block_editor_no_javascript_message', $message, $post, $installed ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
422 |
wp_admin_notice( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
423 |
$message, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
424 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
425 |
'type' => 'error', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
426 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
427 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
428 |
?> |
9 | 429 |
</div> |
430 |
</div> |