author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
child 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
19 | 1 |
<?php |
2 |
/** |
|
3 |
* Site Editor administration screen. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7 |
*/ |
|
8 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
9 |
global $editor_styles; |
19 | 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 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
22 |
$is_template_part = isset( $_GET['postType'] ) && 'wp_template_part' === sanitize_key( $_GET['postType'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
23 |
$is_template_part_path = isset( $_GET['path'] ) && 'wp_template_partall' === sanitize_key( $_GET['path'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
24 |
$is_template_part_editor = $is_template_part || $is_template_part_path; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
25 |
$is_patterns = isset( $_GET['postType'] ) && 'wp_block' === sanitize_key( $_GET['postType'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
26 |
$is_patterns_path = isset( $_GET['path'] ) && 'patterns' === sanitize_key( $_GET['path'] ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
27 |
$is_patterns_editor = $is_patterns || $is_patterns_path; |
19 | 28 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
29 |
if ( ! wp_is_block_theme() ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
30 |
if ( ! current_theme_supports( 'block-template-parts' ) && $is_template_part_editor ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
31 |
wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
32 |
} elseif ( ! $is_patterns_editor && ! $is_template_part_editor ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
33 |
wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) ); |
19 | 34 |
} |
35 |
} |
|
36 |
||
37 |
// Used in the HTML title tag. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
38 |
$title = _x( 'Editor', 'site editor title tag' ); |
19 | 39 |
$parent_file = 'themes.php'; |
40 |
||
41 |
// Flag that we're loading the block editor. |
|
42 |
$current_screen = get_current_screen(); |
|
43 |
$current_screen->is_block_editor( true ); |
|
44 |
||
45 |
// Default to is-fullscreen-mode to avoid jumps in the UI. |
|
46 |
add_filter( |
|
47 |
'admin_body_class', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
48 |
static function ( $classes ) { |
19 | 49 |
return "$classes is-fullscreen-mode"; |
50 |
} |
|
51 |
); |
|
52 |
||
53 |
$indexed_template_types = array(); |
|
54 |
foreach ( get_default_block_template_types() as $slug => $template_type ) { |
|
55 |
$template_type['slug'] = (string) $slug; |
|
56 |
$indexed_template_types[] = $template_type; |
|
57 |
} |
|
58 |
||
59 |
$block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) ); |
|
60 |
$custom_settings = array( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
61 |
'siteUrl' => site_url(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
62 |
'postsPerPage' => get_option( 'posts_per_page' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
63 |
'styles' => get_block_editor_theme_styles(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
64 |
'defaultTemplateTypes' => $indexed_template_types, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
65 |
'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
66 |
'supportsLayout' => wp_theme_has_theme_json(), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
67 |
'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ), |
19 | 68 |
); |
69 |
||
70 |
// Add additional back-compat patterns registered by `current_screen` et al. |
|
71 |
$custom_settings['__experimentalAdditionalBlockPatterns'] = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true ); |
|
72 |
$custom_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true ); |
|
73 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
74 |
$editor_settings = get_block_editor_settings( $custom_settings, $block_editor_context ); |
19 | 75 |
|
76 |
if ( isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ) ) { |
|
77 |
$post_type = get_post_type_object( $_GET['postType'] ); |
|
78 |
if ( ! $post_type ) { |
|
79 |
wp_die( __( 'Invalid post type.' ) ); |
|
80 |
} |
|
81 |
} |
|
82 |
||
83 |
$active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
84 |
$active_theme = get_stylesheet(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
85 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
86 |
$navigation_rest_route = rest_get_route_for_post_type_items( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
87 |
'wp_navigation' |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
88 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
89 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
90 |
$preload_paths = array( |
19 | 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, |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
101 |
array( $navigation_rest_route, 'OPTIONS' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
102 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
103 |
add_query_arg( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
104 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
105 |
'context' => 'edit', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
106 |
'per_page' => 100, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
107 |
'order' => 'desc', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
108 |
'orderby' => 'date', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
109 |
// array indices are required to avoid query being encoded and not matching in cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
110 |
'status[0]' => 'publish', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
111 |
'status[1]' => 'draft', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
112 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
113 |
$navigation_rest_route |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
114 |
), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
115 |
'GET', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
116 |
), |
19 | 117 |
); |
118 |
||
119 |
block_editor_rest_api_preload( $preload_paths, $block_editor_context ); |
|
120 |
||
121 |
wp_add_inline_script( |
|
122 |
'wp-edit-site', |
|
123 |
sprintf( |
|
124 |
'wp.domReady( function() { |
|
125 |
wp.editSite.initializeEditor( "site-editor", %s ); |
|
126 |
} );', |
|
127 |
wp_json_encode( $editor_settings ) |
|
128 |
) |
|
129 |
); |
|
130 |
||
131 |
// Preload server-registered block schemas. |
|
132 |
wp_add_inline_script( |
|
133 |
'wp-blocks', |
|
134 |
'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' |
|
135 |
); |
|
136 |
||
137 |
wp_add_inline_script( |
|
138 |
'wp-blocks', |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
139 |
sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( isset( $editor_settings['blockCategories'] ) ? $editor_settings['blockCategories'] : array() ) ), |
19 | 140 |
'after' |
141 |
); |
|
142 |
||
143 |
wp_enqueue_script( 'wp-edit-site' ); |
|
144 |
wp_enqueue_script( 'wp-format-library' ); |
|
145 |
wp_enqueue_style( 'wp-edit-site' ); |
|
146 |
wp_enqueue_style( 'wp-format-library' ); |
|
147 |
wp_enqueue_media(); |
|
148 |
||
149 |
if ( |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
150 |
current_theme_supports( 'wp-block-styles' ) && |
19 | 151 |
( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) |
152 |
) { |
|
153 |
wp_enqueue_style( 'wp-block-library-theme' ); |
|
154 |
} |
|
155 |
||
156 |
/** This action is documented in wp-admin/edit-form-blocks.php */ |
|
157 |
do_action( 'enqueue_block_editor_assets' ); |
|
158 |
||
159 |
require_once ABSPATH . 'wp-admin/admin-header.php'; |
|
160 |
?> |
|
161 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
162 |
<div class="edit-site" id="site-editor"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
163 |
<?php // JavaScript is disabled. ?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
164 |
<div class="wrap hide-if-js site-editor-no-js"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
165 |
<h1 class="wp-heading-inline"><?php _e( 'Edit site' ); ?></h1> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
166 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
167 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
168 |
* Filters the message displayed in the site editor interface when JavaScript is |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
169 |
* not enabled in the browser. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
170 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
171 |
* @since 6.3.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
172 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
173 |
* @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
|
174 |
* @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
|
175 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
176 |
$message = apply_filters( 'site_editor_no_javascript_message', __( 'The site editor requires JavaScript. Please enable JavaScript in your browser settings.' ), $post ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
177 |
wp_admin_notice( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
178 |
$message, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
179 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
180 |
'type' => 'error', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
181 |
'additional_classes' => array( 'hide-if-js' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
182 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
183 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
184 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
185 |
</div> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
186 |
</div> |
19 | 187 |
|
188 |
<?php |
|
189 |
||
190 |
require_once ABSPATH . 'wp-admin/admin-footer.php'; |