wp/wp-admin/edit-form-blocks.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    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        Global post type.
    18  * @global WP_Post_Type $post_type_object
    18  * @global WP_Post_Type $post_type_object Global post type object.
    19  * @global WP_Post      $post             Global post object.
    19  * @global WP_Post      $post             Global post object.
    20  * @global string       $title
    20  * @global string       $title            The title of the current screen.
    21  * @global array        $wp_meta_boxes
    21  * @global array        $wp_meta_boxes    Global meta box state.
    22  */
    22  */
    23 global $post_type, $post_type_object, $post, $title, $wp_meta_boxes;
    23 global $post_type, $post_type_object, $post, $title, $wp_meta_boxes;
    24 
    24 
    25 $block_editor_context = new WP_Block_Editor_Context( array( 'post' => $post ) );
    25 $block_editor_context = new WP_Block_Editor_Context( array( 'post' => $post ) );
    26 
    26 
    29 $current_screen->is_block_editor( true );
    29 $current_screen->is_block_editor( true );
    30 
    30 
    31 // Default to is-fullscreen-mode to avoid jumps in the UI.
    31 // Default to is-fullscreen-mode to avoid jumps in the UI.
    32 add_filter(
    32 add_filter(
    33 	'admin_body_class',
    33 	'admin_body_class',
    34 	static function( $classes ) {
    34 	static function ( $classes ) {
    35 		return "$classes is-fullscreen-mode";
    35 		return "$classes is-fullscreen-mode";
    36 	}
    36 	}
    37 );
    37 );
    38 
    38 
    39 /*
    39 /*
    66 	sprintf( '/wp/v2/types/%s?context=edit', $post_type ),
    66 	sprintf( '/wp/v2/types/%s?context=edit', $post_type ),
    67 	'/wp/v2/users/me',
    67 	'/wp/v2/users/me',
    68 	array( rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ),
    68 	array( rest_get_route_for_post_type_items( 'attachment' ), 'OPTIONS' ),
    69 	array( rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ),
    69 	array( rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ),
    70 	array( rest_get_route_for_post_type_items( 'wp_block' ), 'OPTIONS' ),
    70 	array( rest_get_route_for_post_type_items( 'wp_block' ), 'OPTIONS' ),
       
    71 	array( rest_get_route_for_post_type_items( 'wp_template' ), 'OPTIONS' ),
    71 	sprintf( '%s/autosaves?context=edit', $rest_path ),
    72 	sprintf( '%s/autosaves?context=edit', $rest_path ),
    72 	'/wp/v2/settings',
    73 	'/wp/v2/settings',
       
    74 	array( '/wp/v2/settings', 'OPTIONS' ),
       
    75 	'/wp/v2/global-styles/themes/' . get_stylesheet(),
       
    76 	'/wp/v2/themes?context=edit&status=active',
       
    77 	'/wp/v2/global-styles/' . WP_Theme_JSON_Resolver::get_user_global_styles_post_id() . '?context=edit',
    73 );
    78 );
    74 
    79 
    75 block_editor_rest_api_preload( $preload_paths, $block_editor_context );
    80 block_editor_rest_api_preload( $preload_paths, $block_editor_context );
    76 
    81 
    77 wp_add_inline_script(
    82 wp_add_inline_script(
   199 	'postLockUtils'        => array(
   204 	'postLockUtils'        => array(
   200 		'nonce'       => wp_create_nonce( 'lock-post_' . $post->ID ),
   205 		'nonce'       => wp_create_nonce( 'lock-post_' . $post->ID ),
   201 		'unlockNonce' => wp_create_nonce( 'update-post_' . $post->ID ),
   206 		'unlockNonce' => wp_create_nonce( 'update-post_' . $post->ID ),
   202 		'ajaxUrl'     => admin_url( 'admin-ajax.php' ),
   207 		'ajaxUrl'     => admin_url( 'admin-ajax.php' ),
   203 	),
   208 	),
   204 	'supportsLayout'       => WP_Theme_JSON_Resolver::theme_has_support(),
   209 	'supportsLayout'       => wp_theme_has_theme_json(),
   205 	'supportsTemplateMode' => current_theme_supports( 'block-templates' ),
   210 	'supportsTemplateMode' => current_theme_supports( 'block-templates' ),
   206 
   211 
   207 	// Whether or not to load the 'postcustom' meta box is stored as a user meta
   212 	// Whether or not to load the 'postcustom' meta box is stored as a user meta
   208 	// field so that we're not always loading its assets.
   213 	// field so that we're not always loading its assets.
   209 	'enableCustomFields'   => (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ),
   214 	'enableCustomFields'   => (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ),
   267  *
   272  *
   268  * @since 5.0.0
   273  * @since 5.0.0
   269  */
   274  */
   270 do_action( 'enqueue_block_editor_assets' );
   275 do_action( 'enqueue_block_editor_assets' );
   271 
   276 
   272 // In order to duplicate classic meta box behaviour, we need to run the classic meta box actions.
   277 // In order to duplicate classic meta box behavior, we need to run the classic meta box actions.
   273 require_once ABSPATH . 'wp-admin/includes/meta-boxes.php';
   278 require_once ABSPATH . 'wp-admin/includes/meta-boxes.php';
   274 register_and_do_post_meta_boxes( $post );
   279 register_and_do_post_meta_boxes( $post );
   275 
   280 
   276 // Check if the Custom Fields meta box has been removed at some point.
   281 // Check if the Custom Fields meta box has been removed at some point.
   277 $core_meta_boxes = $wp_meta_boxes[ $current_screen->id ]['normal']['core'];
   282 $core_meta_boxes = $wp_meta_boxes[ $current_screen->id ]['normal']['core'];
   315 	</div>
   320 	</div>
   316 
   321 
   317 	<?php // JavaScript is disabled. ?>
   322 	<?php // JavaScript is disabled. ?>
   318 	<div class="wrap hide-if-js block-editor-no-js">
   323 	<div class="wrap hide-if-js block-editor-no-js">
   319 		<h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
   324 		<h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
   320 		<div class="notice notice-error notice-alt">
   325 		<?php
   321 			<p>
   326 		if ( file_exists( WP_PLUGIN_DIR . '/classic-editor/classic-editor.php' ) ) {
   322 				<?php
   327 			// If Classic Editor is already installed, provide a link to activate the plugin.
   323 					$message = sprintf(
   328 			$installed           = true;
   324 						/* translators: %s: A link to install the Classic Editor plugin. */
   329 			$plugin_activate_url = wp_nonce_url( 'plugins.php?action=activate&amp;plugin=classic-editor/classic-editor.php', 'activate-plugin_classic-editor/classic-editor.php' );
   325 						__( 'The block editor requires JavaScript. Please enable JavaScript in your browser settings, or try the <a href="%s">Classic Editor plugin</a>.' ),
   330 			$message             = sprintf(
   326 						esc_url( wp_nonce_url( self_admin_url( 'plugin-install.php?tab=favorites&user=wordpressdotorg&save=0' ), 'save_wporg_username_' . get_current_user_id() ) )
   331 				/* translators: %s: Link to activate the Classic Editor plugin. */
   327 					);
   332 				__( 'The block editor requires JavaScript. Please enable JavaScript in your browser settings, or activate the <a href="%s">Classic Editor plugin</a>.' ),
   328 
   333 				esc_url( $plugin_activate_url )
   329 					/**
   334 			);
   330 					 * Filters the message displayed in the block editor interface when JavaScript is
   335 		} else {
   331 					 * not enabled in the browser.
   336 			// If Classic Editor is not installed, provide a link to install it.
   332 					 *
   337 			$installed          = false;
   333 					 * @since 5.0.3
   338 			$plugin_install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=classic-editor' ), 'install-plugin_classic-editor' );
   334 					 *
   339 			$message            = sprintf(
   335 					 * @param string  $message The message being displayed.
   340 				/* translators: %s: Link to install the Classic Editor plugin. */
   336 					 * @param WP_Post $post    The post being edited.
   341 				__( 'The block editor requires JavaScript. Please enable JavaScript in your browser settings, or install the <a href="%s">Classic Editor plugin</a>.' ),
   337 					 */
   342 				esc_url( $plugin_install_url )
   338 					echo apply_filters( 'block_editor_no_javascript_message', $message, $post );
   343 			);
   339 					?>
   344 		}
   340 			</p>
   345 
   341 		</div>
   346 		/**
       
   347 		 * Filters the message displayed in the block editor interface when JavaScript is
       
   348 		 * not enabled in the browser.
       
   349 		 *
       
   350 		 * @since 5.0.3
       
   351 		 * @since 6.4.0 Added `$installed` parameter.
       
   352 		 *
       
   353 		 * @param string  $message   The message being displayed.
       
   354 		 * @param WP_Post $post      The post being edited.
       
   355 		 * @param bool    $installed Whether the classic editor is installed.
       
   356 		 */
       
   357 		$message = apply_filters( 'block_editor_no_javascript_message', $message, $post, $installed );
       
   358 		wp_admin_notice(
       
   359 			$message,
       
   360 			array(
       
   361 				'type' => 'error',
       
   362 			)
       
   363 		);
       
   364 		?>
   342 	</div>
   365 	</div>
   343 </div>
   366 </div>