[ 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 $is_template_part = isset( $_GET['postType'] ) && 'wp_template_part' === sanitize_key( $_GET['postType'] ); 23 $is_template_part_path = isset( $_GET['path'] ) && 'wp_template_partall' === sanitize_key( $_GET['path'] ); 24 $is_template_part_editor = $is_template_part || $is_template_part_path; 25 $is_patterns = isset( $_GET['postType'] ) && 'wp_block' === sanitize_key( $_GET['postType'] ); 26 $is_patterns_path = isset( $_GET['path'] ) && 'patterns' === sanitize_key( $_GET['path'] ); 27 $is_patterns_editor = $is_patterns || $is_patterns_path; 28 29 if ( ! wp_is_block_theme() ) { 30 if ( ! current_theme_supports( 'block-template-parts' ) && $is_template_part_editor ) { 31 wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) ); 32 } elseif ( ! $is_patterns_editor && ! $is_template_part_editor ) { 33 wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) ); 34 } 35 } 36 37 // Used in the HTML title tag. 38 $title = _x( 'Editor', 'site editor title tag' ); 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', 48 static function ( $classes ) { 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( 61 'siteUrl' => site_url(), 62 'postsPerPage' => get_option( 'posts_per_page' ), 63 'styles' => get_block_editor_theme_styles(), 64 'defaultTemplateTypes' => $indexed_template_types, 65 'defaultTemplatePartAreas' => get_allowed_block_template_part_areas(), 66 'supportsLayout' => wp_theme_has_theme_json(), 67 'supportsTemplatePartsMode' => ! wp_is_block_theme() && current_theme_supports( 'block-template-parts' ), 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 74 $editor_settings = get_block_editor_settings( $custom_settings, $block_editor_context ); 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(); 84 $active_theme = get_stylesheet(); 85 86 $navigation_rest_route = rest_get_route_for_post_type_items( 87 'wp_navigation' 88 ); 89 90 $preload_paths = array( 91 array( rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ), 92 array( rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ), 93 '/wp/v2/types?context=view', 94 '/wp/v2/types/wp_template?context=edit', 95 '/wp/v2/types/wp_template_part?context=edit', 96 '/wp/v2/templates?context=edit&per_page=-1', 97 '/wp/v2/template-parts?context=edit&per_page=-1', 98 '/wp/v2/themes?context=edit&status=active', 99 '/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit', 100 array( '/wp/v2/global-styles/' . $active_global_styles_id, 'OPTIONS' ), 101 '/wp/v2/global-styles/themes/' . $active_theme . '?context=view', 102 '/wp/v2/global-styles/themes/' . $active_theme . '/variations?context=view', 103 array( $navigation_rest_route, 'OPTIONS' ), 104 array( 105 add_query_arg( 106 array( 107 'context' => 'edit', 108 'per_page' => 100, 109 'order' => 'desc', 110 'orderby' => 'date', 111 // array indices are required to avoid query being encoded and not matching in cache. 112 'status[0]' => 'publish', 113 'status[1]' => 'draft', 114 ), 115 $navigation_rest_route 116 ), 117 'GET', 118 ), 119 ); 120 121 block_editor_rest_api_preload( $preload_paths, $block_editor_context ); 122 123 wp_add_inline_script( 124 'wp-edit-site', 125 sprintf( 126 'wp.domReady( function() { 127 wp.editSite.initializeEditor( "site-editor", %s ); 128 } );', 129 wp_json_encode( $editor_settings ) 130 ) 131 ); 132 133 // Preload server-registered block schemas. 134 wp_add_inline_script( 135 'wp-blocks', 136 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' 137 ); 138 139 // Preload server-registered block bindings sources. 140 $registered_sources = get_all_registered_block_bindings_sources(); 141 if ( ! empty( $registered_sources ) ) { 142 $filtered_sources = array(); 143 foreach ( $registered_sources as $source ) { 144 $filtered_sources[] = array( 145 'name' => $source->name, 146 'label' => $source->label, 147 'usesContext' => $source->uses_context, 148 ); 149 } 150 $script = sprintf( 'for ( const source of %s ) { wp.blocks.registerBlockBindingsSource( source ); }', wp_json_encode( $filtered_sources ) ); 151 wp_add_inline_script( 152 'wp-blocks', 153 $script 154 ); 155 } 156 157 wp_add_inline_script( 158 'wp-blocks', 159 sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( isset( $editor_settings['blockCategories'] ) ? $editor_settings['blockCategories'] : array() ) ), 160 'after' 161 ); 162 163 wp_enqueue_script( 'wp-edit-site' ); 164 wp_enqueue_script( 'wp-format-library' ); 165 wp_enqueue_style( 'wp-edit-site' ); 166 wp_enqueue_style( 'wp-format-library' ); 167 wp_enqueue_media(); 168 169 if ( 170 current_theme_supports( 'wp-block-styles' ) && 171 ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) 172 ) { 173 wp_enqueue_style( 'wp-block-library-theme' ); 174 } 175 176 /** This action is documented in wp-admin/edit-form-blocks.php */ 177 do_action( 'enqueue_block_editor_assets' ); 178 179 require_once ABSPATH . 'wp-admin/admin-header.php'; 180 ?> 181 182 <div class="edit-site" id="site-editor"> 183 <?php // JavaScript is disabled. ?> 184 <div class="wrap hide-if-js site-editor-no-js"> 185 <h1 class="wp-heading-inline"><?php _e( 'Edit site' ); ?></h1> 186 <?php 187 /** 188 * Filters the message displayed in the site editor interface when JavaScript is 189 * not enabled in the browser. 190 * 191 * @since 6.3.0 192 * 193 * @param string $message The message being displayed. 194 * @param WP_Post $post The post being edited. 195 */ 196 $message = apply_filters( 'site_editor_no_javascript_message', __( 'The site editor requires JavaScript. Please enable JavaScript in your browser settings.' ), $post ); 197 wp_admin_notice( 198 $message, 199 array( 200 'type' => 'error', 201 'additional_classes' => array( 'hide-if-js' ), 202 ) 203 ); 204 ?> 205 </div> 206 </div> 207 208 <?php 209 210 require_once ABSPATH . 'wp-admin/admin-footer.php';
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sat Dec 21 08:20:01 2024 | Cross-referenced by PHPXref |