[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Site Editor administration screen. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 global $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 /** 23 * Maps old site editor urls to the new updated ones. 24 * 25 * @since 6.8.0 26 * @access private 27 * 28 * @global string $pagenow The filename of the current screen. 29 * 30 * @return string|false The new URL to redirect to, or false if no redirection is needed. 31 */ 32 function _wp_get_site_editor_redirection_url() { 33 global $pagenow; 34 if ( 'site-editor.php' !== $pagenow || isset( $_REQUEST['p'] ) || ! $_SERVER['QUERY_STRING'] ) { 35 return false; 36 } 37 38 // The following redirects are for the new permalinks in the site editor. 39 if ( isset( $_REQUEST['postType'] ) && 'wp_navigation' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) { 40 return add_query_arg( array( 'p' => '/wp_navigation/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) ); 41 } 42 43 if ( isset( $_REQUEST['postType'] ) && 'wp_navigation' === $_REQUEST['postType'] && empty( $_REQUEST['postId'] ) ) { 44 return add_query_arg( array( 'p' => '/navigation' ), remove_query_arg( 'postType' ) ); 45 } 46 47 if ( isset( $_REQUEST['path'] ) && '/wp_global_styles' === $_REQUEST['path'] ) { 48 return add_query_arg( array( 'p' => '/styles' ), remove_query_arg( 'path' ) ); 49 } 50 51 if ( isset( $_REQUEST['postType'] ) && 'page' === $_REQUEST['postType'] && ( empty( $_REQUEST['canvas'] ) || empty( $_REQUEST['postId'] ) ) ) { 52 return add_query_arg( array( 'p' => '/page' ), remove_query_arg( 'postType' ) ); 53 } 54 55 if ( isset( $_REQUEST['postType'] ) && 'page' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) { 56 return add_query_arg( array( 'p' => '/page/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) ); 57 } 58 59 if ( isset( $_REQUEST['postType'] ) && 'wp_template' === $_REQUEST['postType'] && ( empty( $_REQUEST['canvas'] ) || empty( $_REQUEST['postId'] ) ) ) { 60 return add_query_arg( array( 'p' => '/template' ), remove_query_arg( 'postType' ) ); 61 } 62 63 if ( isset( $_REQUEST['postType'] ) && 'wp_template' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) { 64 return add_query_arg( array( 'p' => '/wp_template/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) ); 65 } 66 67 if ( isset( $_REQUEST['postType'] ) && 'wp_block' === $_REQUEST['postType'] && ( empty( $_REQUEST['canvas'] ) || empty( $_REQUEST['postId'] ) ) ) { 68 return add_query_arg( array( 'p' => '/pattern' ), remove_query_arg( 'postType' ) ); 69 } 70 71 if ( isset( $_REQUEST['postType'] ) && 'wp_block' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) { 72 return add_query_arg( array( 'p' => '/wp_block/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) ); 73 } 74 75 if ( isset( $_REQUEST['postType'] ) && 'wp_template_part' === $_REQUEST['postType'] && ( empty( $_REQUEST['canvas'] ) || empty( $_REQUEST['postId'] ) ) ) { 76 return add_query_arg( array( 'p' => '/pattern' ) ); 77 } 78 79 if ( isset( $_REQUEST['postType'] ) && 'wp_template_part' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) { 80 return add_query_arg( array( 'p' => '/wp_template_part/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) ); 81 } 82 83 // The following redirects are for backward compatibility with the old site editor URLs. 84 if ( isset( $_REQUEST['path'] ) && '/wp_template_part/all' === $_REQUEST['path'] ) { 85 return add_query_arg( 86 array( 87 'p' => '/pattern', 88 'postType' => 'wp_template_part', 89 ), 90 remove_query_arg( 'path' ) 91 ); 92 } 93 94 if ( isset( $_REQUEST['path'] ) && '/page' === $_REQUEST['path'] ) { 95 return add_query_arg( array( 'p' => '/page' ), remove_query_arg( 'path' ) ); 96 } 97 98 if ( isset( $_REQUEST['path'] ) && '/wp_template' === $_REQUEST['path'] ) { 99 return add_query_arg( array( 'p' => '/template' ), remove_query_arg( 'path' ) ); 100 } 101 102 if ( isset( $_REQUEST['path'] ) && '/patterns' === $_REQUEST['path'] ) { 103 return add_query_arg( array( 'p' => '/pattern' ), remove_query_arg( 'path' ) ); 104 } 105 106 if ( isset( $_REQUEST['path'] ) && '/navigation' === $_REQUEST['path'] ) { 107 return add_query_arg( array( 'p' => '/navigation' ), remove_query_arg( 'path' ) ); 108 } 109 110 return add_query_arg( array( 'p' => '/' ) ); 111 } 112 113 // Redirect to the site editor to the new URLs if needed. 114 $redirection = _wp_get_site_editor_redirection_url(); 115 if ( false !== $redirection ) { 116 wp_safe_redirect( $redirection ); 117 exit; 118 } 119 120 // Used in the HTML title tag. 121 $title = _x( 'Editor', 'site editor title tag' ); 122 $parent_file = 'themes.php'; 123 124 // Flag that we're loading the block editor. 125 $current_screen = get_current_screen(); 126 $current_screen->is_block_editor( true ); 127 128 // Default to is-fullscreen-mode to avoid jumps in the UI. 129 add_filter( 130 'admin_body_class', 131 static function ( $classes ) { 132 return "$classes is-fullscreen-mode"; 133 } 134 ); 135 136 $indexed_template_types = array(); 137 foreach ( get_default_block_template_types() as $slug => $template_type ) { 138 $template_type['slug'] = (string) $slug; 139 $indexed_template_types[] = $template_type; 140 } 141 142 $block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) ); 143 $custom_settings = array( 144 'siteUrl' => site_url(), 145 'postsPerPage' => get_option( 'posts_per_page' ), 146 'styles' => get_block_editor_theme_styles(), 147 'defaultTemplateTypes' => $indexed_template_types, 148 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), 149 'supportsLayout' => wp_theme_has_theme_json(), 150 'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ), 151 ); 152 153 // Add additional back-compat patterns registered by `current_screen` et al. 154 $custom_settings['__experimentalAdditionalBlockPatterns'] = WP_Block_Patterns_Registry::get_instance()->get_all_registered( true ); 155 $custom_settings['__experimentalAdditionalBlockPatternCategories'] = WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered( true ); 156 157 $editor_settings = get_block_editor_settings( $custom_settings, $block_editor_context ); 158 159 if ( isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ) ) { 160 $post_type = get_post_type_object( $_GET['postType'] ); 161 if ( ! $post_type ) { 162 wp_die( __( 'Invalid post type.' ) ); 163 } 164 } 165 166 $active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); 167 $active_theme = get_stylesheet(); 168 169 $navigation_rest_route = rest_get_route_for_post_type_items( 170 'wp_navigation' 171 ); 172 173 $preload_paths = array( 174 array( rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ), 175 array( rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ), 176 '/wp/v2/types?context=view', 177 '/wp/v2/types/wp_template?context=edit', 178 '/wp/v2/types/wp_template_part?context=edit', 179 '/wp/v2/templates?context=edit&per_page=-1', 180 '/wp/v2/template-parts?context=edit&per_page=-1', 181 '/wp/v2/themes?context=edit&status=active', 182 '/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit', 183 array( '/wp/v2/global-styles/' . $active_global_styles_id, 'OPTIONS' ), 184 '/wp/v2/global-styles/themes/' . $active_theme . '?context=view', 185 '/wp/v2/global-styles/themes/' . $active_theme . '/variations?context=view', 186 array( $navigation_rest_route, 'OPTIONS' ), 187 array( 188 add_query_arg( 189 array( 190 'context' => 'edit', 191 'per_page' => 100, 192 'order' => 'desc', 193 'orderby' => 'date', 194 // array indices are required to avoid query being encoded and not matching in cache. 195 'status[0]' => 'publish', 196 'status[1]' => 'draft', 197 ), 198 $navigation_rest_route 199 ), 200 'GET', 201 ), 202 ); 203 204 block_editor_rest_api_preload( $preload_paths, $block_editor_context ); 205 206 wp_add_inline_script( 207 'wp-edit-site', 208 sprintf( 209 'wp.domReady( function() { 210 wp.editSite.initializeEditor( "site-editor", %s ); 211 } );', 212 wp_json_encode( $editor_settings ) 213 ) 214 ); 215 216 // Preload server-registered block schemas. 217 wp_add_inline_script( 218 'wp-blocks', 219 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' 220 ); 221 222 // Preload server-registered block bindings sources. 223 $registered_sources = get_all_registered_block_bindings_sources(); 224 if ( ! empty( $registered_sources ) ) { 225 $filtered_sources = array(); 226 foreach ( $registered_sources as $source ) { 227 $filtered_sources[] = array( 228 'name' => $source->name, 229 'label' => $source->label, 230 'usesContext' => $source->uses_context, 231 ); 232 } 233 $script = sprintf( 'for ( const source of %s ) { wp.blocks.registerBlockBindingsSource( source ); }', wp_json_encode( $filtered_sources ) ); 234 wp_add_inline_script( 235 'wp-blocks', 236 $script 237 ); 238 } 239 240 wp_add_inline_script( 241 'wp-blocks', 242 sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( isset( $editor_settings['blockCategories'] ) ? $editor_settings['blockCategories'] : array() ) ), 243 'after' 244 ); 245 246 wp_enqueue_script( 'wp-edit-site' ); 247 wp_enqueue_script( 'wp-format-library' ); 248 wp_enqueue_style( 'wp-edit-site' ); 249 wp_enqueue_style( 'wp-format-library' ); 250 wp_enqueue_media(); 251 252 if ( 253 current_theme_supports( 'wp-block-styles' ) && 254 ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) 255 ) { 256 wp_enqueue_style( 'wp-block-library-theme' ); 257 } 258 259 /** This action is documented in wp-admin/edit-form-blocks.php */ 260 do_action( 'enqueue_block_editor_assets' ); 261 262 require_once ABSPATH . 'wp-admin/admin-header.php'; 263 ?> 264 265 <div class="edit-site" id="site-editor"> 266 <?php // JavaScript is disabled. ?> 267 <div class="wrap hide-if-js site-editor-no-js"> 268 <h1 class="wp-heading-inline"><?php _e( 'Edit Site' ); ?></h1> 269 <?php 270 /** 271 * Filters the message displayed in the site editor interface when JavaScript is 272 * not enabled in the browser. 273 * 274 * @since 6.3.0 275 * 276 * @param string $message The message being displayed. 277 * @param WP_Post $post The post being edited. 278 */ 279 $message = apply_filters( 'site_editor_no_javascript_message', __( 'The site editor requires JavaScript. Please enable JavaScript in your browser settings.' ), $post ); 280 wp_admin_notice( 281 $message, 282 array( 283 'type' => 'error', 284 'additional_classes' => array( 'hide-if-js' ), 285 ) 286 ); 287 ?> 288 </div> 289 </div> 290 291 <?php 292 293 require_once ABSPATH . 'wp-admin/admin-footer.php';
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Fri Feb 21 08:20:01 2025 | Cross-referenced by PHPXref |