1 <?php |
1 <?php |
2 /** |
2 /** |
3 * The Block Editor page. |
3 * The block editor page. |
4 * |
4 * |
5 * @since 5.0.0 |
5 * @since 5.0.0 |
6 * |
6 * |
7 * @package WordPress |
7 * @package WordPress |
8 * @subpackage Administration |
8 * @subpackage Administration |
9 */ |
9 */ |
10 |
10 |
11 // don't load directly |
11 // Don't load directly. |
12 if ( ! defined( 'ABSPATH' ) ) { |
12 if ( ! defined( 'ABSPATH' ) ) { |
13 die( '-1' ); |
13 die( '-1' ); |
14 } |
14 } |
15 |
15 |
16 /** |
16 /** |
17 * @global string $post_type |
17 * @global string $post_type |
18 * @global WP_Post_Type $post_type_object |
18 * @global WP_Post_Type $post_type_object |
19 * @global WP_Post $post |
19 * @global WP_Post $post Global post object. |
20 * @global string $title |
20 * @global string $title |
21 * @global array $editor_styles |
21 * @global array $editor_styles |
22 * @global array $wp_meta_boxes |
22 * @global array $wp_meta_boxes |
23 */ |
23 */ |
24 global $post_type, $post_type_object, $post, $title, $editor_styles, $wp_meta_boxes; |
24 global $post_type, $post_type_object, $post, $title, $editor_styles, $wp_meta_boxes; |
47 sprintf( '/wp/v2/%s/%s?context=edit', $rest_base, $post->ID ), |
47 sprintf( '/wp/v2/%s/%s?context=edit', $rest_base, $post->ID ), |
48 sprintf( '/wp/v2/types/%s?context=edit', $post_type ), |
48 sprintf( '/wp/v2/types/%s?context=edit', $post_type ), |
49 sprintf( '/wp/v2/users/me?post_type=%s&context=edit', $post_type ), |
49 sprintf( '/wp/v2/users/me?post_type=%s&context=edit', $post_type ), |
50 array( '/wp/v2/media', 'OPTIONS' ), |
50 array( '/wp/v2/media', 'OPTIONS' ), |
51 array( '/wp/v2/blocks', 'OPTIONS' ), |
51 array( '/wp/v2/blocks', 'OPTIONS' ), |
|
52 sprintf( '/wp/v2/%s/%d/autosaves?context=edit', $rest_base, $post->ID ), |
52 ); |
53 ); |
53 |
54 |
54 /** |
55 /** |
55 * Preload common data by specifying an array of REST API paths that will be preloaded. |
56 * Preload common data by specifying an array of REST API paths that will be preloaded. |
56 * |
57 * |
57 * Filters the array of paths that will be preloaded. |
58 * Filters the array of paths that will be preloaded. |
58 * |
59 * |
59 * @since 5.0.0 |
60 * @since 5.0.0 |
60 * |
61 * |
61 * @param array $preload_paths Array of paths to preload. |
62 * @param string[] $preload_paths Array of paths to preload. |
62 * @param object $post The post resource data. |
63 * @param WP_Post $post Post being edited. |
63 */ |
64 */ |
64 $preload_paths = apply_filters( 'block_editor_preload_paths', $preload_paths, $post ); |
65 $preload_paths = apply_filters( 'block_editor_preload_paths', $preload_paths, $post ); |
65 |
66 |
66 /* |
67 /* |
67 * Ensure the global $post remains the same after API data is preloaded. |
68 * Ensure the global $post remains the same after API data is preloaded. |
129 |
130 |
130 /* |
131 /* |
131 * Initialize the editor. |
132 * Initialize the editor. |
132 */ |
133 */ |
133 |
134 |
134 $align_wide = get_theme_support( 'align-wide' ); |
135 $align_wide = get_theme_support( 'align-wide' ); |
135 $color_palette = current( (array) get_theme_support( 'editor-color-palette' ) ); |
136 $color_palette = current( (array) get_theme_support( 'editor-color-palette' ) ); |
136 $font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) ); |
137 $font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) ); |
|
138 $gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) ); |
|
139 $custom_line_height = get_theme_support( 'custom-line-height' ); |
|
140 $custom_units = get_theme_support( 'custom-units' ); |
137 |
141 |
138 /** |
142 /** |
139 * Filters the allowed block types for the editor, defaulting to true (all |
143 * Filters the allowed block types for the editor, defaulting to true (all |
140 * block types supported). |
144 * block types supported). |
141 * |
145 * |
142 * @since 5.0.0 |
146 * @since 5.0.0 |
143 * |
147 * |
144 * @param bool|array $allowed_block_types Array of block type slugs, or |
148 * @param bool|array $allowed_block_types Array of block type slugs, or |
145 * boolean to enable/disable all. |
149 * boolean to enable/disable all. |
146 * @param object $post The post resource data. |
150 * @param WP_Post $post The post resource data. |
147 */ |
151 */ |
148 $allowed_block_types = apply_filters( 'allowed_block_types', true, $post ); |
152 $allowed_block_types = apply_filters( 'allowed_block_types', true, $post ); |
149 |
153 |
150 // Get all available templates for the post/page attributes meta-box. |
154 /* |
151 // The "Default template" array element should only be added if the array is |
155 * Get all available templates for the post/page attributes meta-box. |
152 // not empty so we do not trigger the template select element without any options |
156 * The "Default template" array element should only be added if the array is |
153 // besides the default value. |
157 * not empty so we do not trigger the template select element without any options |
|
158 * besides the default value. |
|
159 */ |
154 $available_templates = wp_get_theme()->get_page_templates( get_post( $post->ID ) ); |
160 $available_templates = wp_get_theme()->get_page_templates( get_post( $post->ID ) ); |
155 $available_templates = ! empty( $available_templates ) ? array_merge( |
161 $available_templates = ! empty( $available_templates ) ? array_merge( |
156 array( |
162 array( |
157 /** This filter is documented in wp-admin/includes/meta-boxes.php */ |
163 /** This filter is documented in wp-admin/includes/meta-boxes.php */ |
158 '' => apply_filters( 'default_page_template_title', __( 'Default template' ), 'rest-api' ), |
164 '' => apply_filters( 'default_page_template_title', __( 'Default template' ), 'rest-api' ), |
264 * @param WP_Post $post Post object. |
283 * @param WP_Post $post Post object. |
265 */ |
284 */ |
266 $body_placeholder = apply_filters( 'write_your_story', __( 'Start writing or type / to choose a block' ), $post ); |
285 $body_placeholder = apply_filters( 'write_your_story', __( 'Start writing or type / to choose a block' ), $post ); |
267 |
286 |
268 $editor_settings = array( |
287 $editor_settings = array( |
269 'alignWide' => $align_wide, |
288 'alignWide' => $align_wide, |
270 'availableTemplates' => $available_templates, |
289 'availableTemplates' => $available_templates, |
271 'allowedBlockTypes' => $allowed_block_types, |
290 'allowedBlockTypes' => $allowed_block_types, |
272 'disableCustomColors' => get_theme_support( 'disable-custom-colors' ), |
291 'disableCustomColors' => get_theme_support( 'disable-custom-colors' ), |
273 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ), |
292 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ), |
274 'disablePostFormats' => ! current_theme_supports( 'post-formats' ), |
293 'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ), |
|
294 'disablePostFormats' => ! current_theme_supports( 'post-formats' ), |
275 /** This filter is documented in wp-admin/edit-form-advanced.php */ |
295 /** This filter is documented in wp-admin/edit-form-advanced.php */ |
276 'titlePlaceholder' => apply_filters( 'enter_title_here', __( 'Add title' ), $post ), |
296 'titlePlaceholder' => apply_filters( 'enter_title_here', __( 'Add title' ), $post ), |
277 'bodyPlaceholder' => $body_placeholder, |
297 'bodyPlaceholder' => $body_placeholder, |
278 'isRTL' => is_rtl(), |
298 'isRTL' => is_rtl(), |
279 'autosaveInterval' => AUTOSAVE_INTERVAL, |
299 'autosaveInterval' => AUTOSAVE_INTERVAL, |
280 'maxUploadFileSize' => $max_upload_size, |
300 'maxUploadFileSize' => $max_upload_size, |
281 'allowedMimeTypes' => get_allowed_mime_types(), |
301 'allowedMimeTypes' => get_allowed_mime_types(), |
282 'styles' => $styles, |
302 'styles' => $styles, |
283 'imageSizes' => $available_image_sizes, |
303 'imageSizes' => $available_image_sizes, |
284 'richEditingEnabled' => user_can_richedit(), |
304 'imageDimensions' => $image_dimensions, |
285 'postLock' => $lock_details, |
305 'richEditingEnabled' => user_can_richedit(), |
286 'postLockUtils' => array( |
306 'postLock' => $lock_details, |
|
307 'postLockUtils' => array( |
287 'nonce' => wp_create_nonce( 'lock-post_' . $post->ID ), |
308 'nonce' => wp_create_nonce( 'lock-post_' . $post->ID ), |
288 'unlockNonce' => wp_create_nonce( 'update-post_' . $post->ID ), |
309 'unlockNonce' => wp_create_nonce( 'update-post_' . $post->ID ), |
289 'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
310 'ajaxUrl' => admin_url( 'admin-ajax.php' ), |
290 ), |
311 ), |
|
312 '__experimentalBlockPatterns' => WP_Block_Patterns_Registry::get_instance()->get_all_registered(), |
|
313 '__experimentalBlockPatternCategories' => WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered(), |
291 |
314 |
292 // Whether or not to load the 'postcustom' meta box is stored as a user meta |
315 // Whether or not to load the 'postcustom' meta box is stored as a user meta |
293 // field so that we're not always loading its assets. |
316 // field so that we're not always loading its assets. |
294 'enableCustomFields' => (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ), |
317 'enableCustomFields' => (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ), |
|
318 'enableCustomLineHeight' => $custom_line_height, |
|
319 'enableCustomUnits' => $custom_units, |
295 ); |
320 ); |
296 |
321 |
297 $autosave = wp_get_post_autosave( $post_ID ); |
322 $autosave = wp_get_post_autosave( $post_ID ); |
298 if ( $autosave ) { |
323 if ( $autosave ) { |
299 if ( mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) { |
324 if ( mysql2date( 'U', $autosave->post_modified_gmt, false ) > mysql2date( 'U', $post->post_modified_gmt, false ) ) { |
409 <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1> |
439 <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1> |
410 <div class="notice notice-error notice-alt"> |
440 <div class="notice notice-error notice-alt"> |
411 <p> |
441 <p> |
412 <?php |
442 <?php |
413 $message = sprintf( |
443 $message = sprintf( |
414 /* translators: %s: Classic Editor plugin URL */ |
444 /* translators: %s: A link to install the Classic Editor plugin. */ |
415 __( 'The block editor requires JavaScript. Please enable JavaScript in your browser settings, or try the <a href="%s">Classic Editor plugin</a>.' ), |
445 __( 'The block editor requires JavaScript. Please enable JavaScript in your browser settings, or try the <a href="%s">Classic Editor plugin</a>.' ), |
416 __( 'https://wordpress.org/plugins/classic-editor/' ) |
446 esc_url( wp_nonce_url( self_admin_url( 'plugin-install.php?tab=favorites&user=wordpressdotorg&save=0' ), 'save_wporg_username_' . get_current_user_id() ) ) |
417 ); |
447 ); |
418 |
448 |
419 /** |
449 /** |
420 * Filters the message displayed in the block editor interface when JavaScript is |
450 * Filters the message displayed in the block editor interface when JavaScript is |
421 * not enabled in the browser. |
451 * not enabled in the browser. |