|
1 <?php |
|
2 /** |
|
3 * Site Editor administration screen. |
|
4 * |
|
5 * @package WordPress |
|
6 * @subpackage Administration |
|
7 */ |
|
8 |
|
9 global $post, $editor_styles; |
|
10 |
|
11 /** WordPress Administration Bootstrap */ |
|
12 require_once __DIR__ . '/admin.php'; |
|
13 |
|
14 if ( ! current_user_can( 'edit_theme_options' ) ) { |
|
15 wp_die( |
|
16 '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' . |
|
17 '<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>', |
|
18 403 |
|
19 ); |
|
20 } |
|
21 |
|
22 if ( ! wp_is_block_theme() ) { |
|
23 wp_die( __( 'The theme you are currently using is not compatible with Full Site Editing.' ) ); |
|
24 } |
|
25 |
|
26 /** |
|
27 * Do a server-side redirection if missing `postType` and `postId` |
|
28 * query args when visiting Site Editor. |
|
29 */ |
|
30 $home_template = _resolve_home_block_template(); |
|
31 if ( $home_template && empty( $_GET['postType'] ) && empty( $_GET['postId'] ) ) { |
|
32 if ( ! empty( $_GET['styles'] ) ) { |
|
33 $home_template['styles'] = sanitize_key( $_GET['styles'] ); |
|
34 } |
|
35 $redirect_url = add_query_arg( |
|
36 $home_template, |
|
37 admin_url( 'site-editor.php' ) |
|
38 ); |
|
39 wp_safe_redirect( $redirect_url ); |
|
40 exit; |
|
41 } |
|
42 |
|
43 // Used in the HTML title tag. |
|
44 $title = __( 'Editor (beta)' ); |
|
45 $parent_file = 'themes.php'; |
|
46 |
|
47 // Flag that we're loading the block editor. |
|
48 $current_screen = get_current_screen(); |
|
49 $current_screen->is_block_editor( true ); |
|
50 |
|
51 // Default to is-fullscreen-mode to avoid jumps in the UI. |
|
52 add_filter( |
|
53 'admin_body_class', |
|
54 static function( $classes ) { |
|
55 return "$classes is-fullscreen-mode"; |
|
56 } |
|
57 ); |
|
58 |
|
59 $indexed_template_types = array(); |
|
60 foreach ( get_default_block_template_types() as $slug => $template_type ) { |
|
61 $template_type['slug'] = (string) $slug; |
|
62 $indexed_template_types[] = $template_type; |
|
63 } |
|
64 |
|
65 $block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) ); |
|
66 $custom_settings = array( |
|
67 'siteUrl' => site_url(), |
|
68 'postsPerPage' => get_option( 'posts_per_page' ), |
|
69 'styles' => get_block_editor_theme_styles(), |
|
70 'defaultTemplateTypes' => $indexed_template_types, |
|
71 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), |
|
72 '__unstableHomeTemplate' => $home_template, |
|
73 ); |
|
74 |
|
75 // Add additional back-compat patterns registered by `current_screen` et al. |
|
76 $custom_settings['__experimentalAdditionalBlockPatterns'] = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true ); |
|
77 $custom_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true ); |
|
78 |
|
79 $editor_settings = get_block_editor_settings( $custom_settings, $block_editor_context ); |
|
80 |
|
81 if ( isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ) ) { |
|
82 $post_type = get_post_type_object( $_GET['postType'] ); |
|
83 if ( ! $post_type ) { |
|
84 wp_die( __( 'Invalid post type.' ) ); |
|
85 } |
|
86 } |
|
87 |
|
88 $active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); |
|
89 $active_theme = wp_get_theme()->get_stylesheet(); |
|
90 $preload_paths = array( |
|
91 array( '/wp/v2/media', 'OPTIONS' ), |
|
92 '/wp/v2/types?context=view', |
|
93 '/wp/v2/types/wp_template?context=edit', |
|
94 '/wp/v2/types/wp_template-part?context=edit', |
|
95 '/wp/v2/templates?context=edit&per_page=-1', |
|
96 '/wp/v2/template-parts?context=edit&per_page=-1', |
|
97 '/wp/v2/themes?context=edit&status=active', |
|
98 '/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit', |
|
99 '/wp/v2/global-styles/' . $active_global_styles_id, |
|
100 '/wp/v2/global-styles/themes/' . $active_theme, |
|
101 ); |
|
102 |
|
103 block_editor_rest_api_preload( $preload_paths, $block_editor_context ); |
|
104 |
|
105 wp_add_inline_script( |
|
106 'wp-edit-site', |
|
107 sprintf( |
|
108 'wp.domReady( function() { |
|
109 wp.editSite.initializeEditor( "site-editor", %s ); |
|
110 } );', |
|
111 wp_json_encode( $editor_settings ) |
|
112 ) |
|
113 ); |
|
114 |
|
115 // Preload server-registered block schemas. |
|
116 wp_add_inline_script( |
|
117 'wp-blocks', |
|
118 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' |
|
119 ); |
|
120 |
|
121 wp_add_inline_script( |
|
122 'wp-blocks', |
|
123 sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $post ) ) ), |
|
124 'after' |
|
125 ); |
|
126 |
|
127 wp_enqueue_script( 'wp-edit-site' ); |
|
128 wp_enqueue_script( 'wp-format-library' ); |
|
129 wp_enqueue_style( 'wp-edit-site' ); |
|
130 wp_enqueue_style( 'wp-format-library' ); |
|
131 wp_enqueue_media(); |
|
132 |
|
133 if ( |
|
134 current_theme_supports( 'wp-block-styles' ) || |
|
135 ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) |
|
136 ) { |
|
137 wp_enqueue_style( 'wp-block-library-theme' ); |
|
138 } |
|
139 |
|
140 /** This action is documented in wp-admin/edit-form-blocks.php */ |
|
141 do_action( 'enqueue_block_editor_assets' ); |
|
142 |
|
143 require_once ABSPATH . 'wp-admin/admin-header.php'; |
|
144 ?> |
|
145 |
|
146 <div id="site-editor" class="edit-site"></div> |
|
147 |
|
148 <?php |
|
149 |
|
150 require_once ABSPATH . 'wp-admin/admin-footer.php'; |