wp/wp-includes/block-editor.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     9 
     9 
    10 /**
    10 /**
    11  * Returns the list of default categories for block types.
    11  * Returns the list of default categories for block types.
    12  *
    12  *
    13  * @since 5.8.0
    13  * @since 5.8.0
       
    14  * @since 6.3.0 Reusable Blocks renamed to Patterns.
    14  *
    15  *
    15  * @return array[] Array of categories for block types.
    16  * @return array[] Array of categories for block types.
    16  */
    17  */
    17 function get_default_block_categories() {
    18 function get_default_block_categories() {
    18 	return array(
    19 	return array(
    46 			'title' => _x( 'Embeds', 'block category' ),
    47 			'title' => _x( 'Embeds', 'block category' ),
    47 			'icon'  => null,
    48 			'icon'  => null,
    48 		),
    49 		),
    49 		array(
    50 		array(
    50 			'slug'  => 'reusable',
    51 			'slug'  => 'reusable',
    51 			'title' => _x( 'Reusable Blocks', 'block category' ),
    52 			'title' => _x( 'Patterns', 'block category' ),
    52 			'icon'  => null,
    53 			'icon'  => null,
    53 		),
    54 		),
    54 	);
    55 	);
    55 }
    56 }
    56 
    57 
   151  *
   152  *
   152  * @return array The default block editor settings.
   153  * @return array The default block editor settings.
   153  */
   154  */
   154 function get_default_block_editor_settings() {
   155 function get_default_block_editor_settings() {
   155 	// Media settings.
   156 	// Media settings.
   156 	$max_upload_size = wp_max_upload_size();
   157 
   157 	if ( ! $max_upload_size ) {
   158 	// wp_max_upload_size() can be expensive, so only call it when relevant for the current user.
   158 		$max_upload_size = 0;
   159 	$max_upload_size = 0;
       
   160 	if ( current_user_can( 'upload_files' ) ) {
       
   161 		$max_upload_size = wp_max_upload_size();
       
   162 		if ( ! $max_upload_size ) {
       
   163 			$max_upload_size = 0;
       
   164 		}
   159 	}
   165 	}
   160 
   166 
   161 	/** This filter is documented in wp-admin/includes/media.php */
   167 	/** This filter is documented in wp-admin/includes/media.php */
   162 	$image_size_names = apply_filters(
   168 	$image_size_names = apply_filters(
   163 		'image_size_names_choose',
   169 		'image_size_names_choose',
   190 	}
   196 	}
   191 
   197 
   192 	// These styles are used if the "no theme styles" options is triggered or on
   198 	// These styles are used if the "no theme styles" options is triggered or on
   193 	// themes without their own editor styles.
   199 	// themes without their own editor styles.
   194 	$default_editor_styles_file = ABSPATH . WPINC . '/css/dist/block-editor/default-editor-styles.css';
   200 	$default_editor_styles_file = ABSPATH . WPINC . '/css/dist/block-editor/default-editor-styles.css';
   195 	if ( file_exists( $default_editor_styles_file ) ) {
   201 
       
   202 	static $default_editor_styles_file_contents = false;
       
   203 	if ( ! $default_editor_styles_file_contents && file_exists( $default_editor_styles_file ) ) {
       
   204 		$default_editor_styles_file_contents = file_get_contents( $default_editor_styles_file );
       
   205 	}
       
   206 
       
   207 	$default_editor_styles = array();
       
   208 	if ( $default_editor_styles_file_contents ) {
   196 		$default_editor_styles = array(
   209 		$default_editor_styles = array(
   197 			array( 'css' => file_get_contents( $default_editor_styles_file ) ),
   210 			array( 'css' => $default_editor_styles_file_contents ),
   198 		);
   211 		);
   199 	} else {
       
   200 		$default_editor_styles = array();
       
   201 	}
   212 	}
   202 
   213 
   203 	$editor_settings = array(
   214 	$editor_settings = array(
   204 		'alignWide'                        => get_theme_support( 'align-wide' ),
   215 		'alignWide'                        => get_theme_support( 'align-wide' ),
   205 		'allowedBlockTypes'                => true,
   216 		'allowedBlockTypes'                => true,
   206 		'allowedMimeTypes'                 => get_allowed_mime_types(),
   217 		'allowedMimeTypes'                 => get_allowed_mime_types(),
   207 		'defaultEditorStyles'              => $default_editor_styles,
   218 		'defaultEditorStyles'              => $default_editor_styles,
   208 		'blockCategories'                  => get_default_block_categories(),
   219 		'blockCategories'                  => get_default_block_categories(),
   209 		'disableCustomColors'              => get_theme_support( 'disable-custom-colors' ),
       
   210 		'disableCustomFontSizes'           => get_theme_support( 'disable-custom-font-sizes' ),
       
   211 		'disableCustomGradients'           => get_theme_support( 'disable-custom-gradients' ),
       
   212 		'enableCustomLineHeight'           => get_theme_support( 'custom-line-height' ),
       
   213 		'enableCustomSpacing'              => get_theme_support( 'custom-spacing' ),
       
   214 		'enableCustomUnits'                => get_theme_support( 'custom-units' ),
       
   215 		'isRTL'                            => is_rtl(),
   220 		'isRTL'                            => is_rtl(),
   216 		'imageDefaultSize'                 => $image_default_size,
   221 		'imageDefaultSize'                 => $image_default_size,
   217 		'imageDimensions'                  => $image_dimensions,
   222 		'imageDimensions'                  => $image_dimensions,
   218 		'imageEditing'                     => true,
   223 		'imageEditing'                     => true,
   219 		'imageSizes'                       => $available_image_sizes,
   224 		'imageSizes'                       => $available_image_sizes,
   220 		'maxUploadFileSize'                => $max_upload_size,
   225 		'maxUploadFileSize'                => $max_upload_size,
   221 		// The following flag is required to enable the new Gallery block format on the mobile apps in 5.9.
   226 		// The following flag is required to enable the new Gallery block format on the mobile apps in 5.9.
   222 		'__unstableGalleryWithImageBlocks' => true,
   227 		'__unstableGalleryWithImageBlocks' => true,
   223 	);
   228 	);
   224 
   229 
   225 	// Theme settings.
   230 	$theme_settings = get_classic_theme_supports_block_editor_settings();
   226 	$color_palette = current( (array) get_theme_support( 'editor-color-palette' ) );
   231 	foreach ( $theme_settings as $key => $value ) {
   227 	if ( false !== $color_palette ) {
   232 		$editor_settings[ $key ] = $value;
   228 		$editor_settings['colors'] = $color_palette;
       
   229 	}
       
   230 
       
   231 	$font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) );
       
   232 	if ( false !== $font_sizes ) {
       
   233 		$editor_settings['fontSizes'] = $font_sizes;
       
   234 	}
       
   235 
       
   236 	$gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) );
       
   237 	if ( false !== $gradient_presets ) {
       
   238 		$editor_settings['gradients'] = $gradient_presets;
       
   239 	}
   233 	}
   240 
   234 
   241 	return $editor_settings;
   235 	return $editor_settings;
   242 }
   236 }
   243 
   237 
   291  * Collect the block editor assets that need to be loaded into the editor's iframe.
   285  * Collect the block editor assets that need to be loaded into the editor's iframe.
   292  *
   286  *
   293  * @since 6.0.0
   287  * @since 6.0.0
   294  * @access private
   288  * @access private
   295  *
   289  *
   296  * @global string $pagenow The filename of the current screen.
   290  * @global WP_Styles  $wp_styles  The WP_Styles current instance.
       
   291  * @global WP_Scripts $wp_scripts The WP_Scripts current instance.
   297  *
   292  *
   298  * @return array {
   293  * @return array {
   299  *     The block editor assets.
   294  *     The block editor assets.
   300  *
   295  *
   301  *     @type string|false $styles  String containing the HTML for styles.
   296  *     @type string|false $styles  String containing the HTML for styles.
   302  *     @type string|false $scripts String containing the HTML for scripts.
   297  *     @type string|false $scripts String containing the HTML for scripts.
   303  * }
   298  * }
   304  */
   299  */
   305 function _wp_get_iframed_editor_assets() {
   300 function _wp_get_iframed_editor_assets() {
   306 	global $pagenow;
   301 	global $wp_styles, $wp_scripts;
   307 
   302 
   308 	$script_handles = array();
   303 	// Keep track of the styles and scripts instance to restore later.
   309 	$style_handles  = array(
   304 	$current_wp_styles  = $wp_styles;
   310 		'wp-block-editor',
   305 	$current_wp_scripts = $wp_scripts;
   311 		'wp-block-library',
   306 
   312 		'wp-edit-blocks',
   307 	// Create new instances to collect the assets.
   313 	);
   308 	$wp_styles  = new WP_Styles();
       
   309 	$wp_scripts = new WP_Scripts();
       
   310 
       
   311 	/*
       
   312 	 * Register all currently registered styles and scripts. The actions that
       
   313 	 * follow enqueue assets, but don't necessarily register them.
       
   314 	 */
       
   315 	$wp_styles->registered  = $current_wp_styles->registered;
       
   316 	$wp_scripts->registered = $current_wp_scripts->registered;
       
   317 
       
   318 	/*
       
   319 	 * We generally do not need reset styles for the iframed editor.
       
   320 	 * However, if it's a classic theme, margins will be added to every block,
       
   321 	 * which is reset specifically for list items, so classic themes rely on
       
   322 	 * these reset styles.
       
   323 	 */
       
   324 	$wp_styles->done =
       
   325 		wp_theme_has_theme_json() ? array( 'wp-reset-editor-styles' ) : array();
       
   326 
       
   327 	wp_enqueue_script( 'wp-polyfill' );
       
   328 	// Enqueue the `editorStyle` handles for all core block, and dependencies.
       
   329 	wp_enqueue_style( 'wp-edit-blocks' );
   314 
   330 
   315 	if ( current_theme_supports( 'wp-block-styles' ) ) {
   331 	if ( current_theme_supports( 'wp-block-styles' ) ) {
   316 		$style_handles[] = 'wp-block-library-theme';
   332 		wp_enqueue_style( 'wp-block-library-theme' );
   317 	}
   333 	}
   318 
   334 
   319 	if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) {
   335 	/*
   320 		$style_handles[] = 'wp-widgets';
   336 	 * We don't want to load EDITOR scripts in the iframe, only enqueue
   321 		$style_handles[] = 'wp-edit-widgets';
   337 	 * front-end assets for the content.
   322 	}
   338 	 */
       
   339 	add_filter( 'should_load_block_editor_scripts_and_styles', '__return_false' );
       
   340 	do_action( 'enqueue_block_assets' );
       
   341 	remove_filter( 'should_load_block_editor_scripts_and_styles', '__return_false' );
   323 
   342 
   324 	$block_registry = WP_Block_Type_Registry::get_instance();
   343 	$block_registry = WP_Block_Type_Registry::get_instance();
   325 
   344 
       
   345 	/*
       
   346 	 * Additionally, do enqueue `editorStyle` assets for all blocks, which
       
   347 	 * contains editor-only styling for blocks (editor content).
       
   348 	 */
   326 	foreach ( $block_registry->get_all_registered() as $block_type ) {
   349 	foreach ( $block_registry->get_all_registered() as $block_type ) {
   327 		if ( ! empty( $block_type->style ) ) {
   350 		if ( isset( $block_type->editor_style_handles ) && is_array( $block_type->editor_style_handles ) ) {
   328 			$style_handles[] = $block_type->style;
   351 			foreach ( $block_type->editor_style_handles as $style_handle ) {
   329 		}
   352 				wp_enqueue_style( $style_handle );
   330 
   353 			}
   331 		if ( ! empty( $block_type->editor_style ) ) {
   354 		}
   332 			$style_handles[] = $block_type->editor_style;
   355 	}
   333 		}
   356 
   334 
   357 	/**
   335 		if ( ! empty( $block_type->script ) ) {
   358 	 * Remove the deprecated `print_emoji_styles` handler.
   336 			$script_handles[] = $block_type->script;
   359 	 * It avoids breaking style generation with a deprecation message.
   337 		}
   360 	 */
   338 	}
   361 	$has_emoji_styles = has_action( 'wp_print_styles', 'print_emoji_styles' );
   339 
   362 	if ( $has_emoji_styles ) {
   340 	$style_handles = array_unique( $style_handles );
   363 		remove_action( 'wp_print_styles', 'print_emoji_styles' );
   341 	$done          = wp_styles()->done;
   364 	}
   342 
   365 
   343 	ob_start();
   366 	ob_start();
   344 
   367 	wp_print_styles();
   345 	// We do not need reset styles for the iframed editor.
   368 	wp_print_font_faces();
   346 	wp_styles()->done = array( 'wp-reset-editor-styles' );
       
   347 	wp_styles()->do_items( $style_handles );
       
   348 	wp_styles()->done = $done;
       
   349 
       
   350 	$styles = ob_get_clean();
   369 	$styles = ob_get_clean();
   351 
   370 
   352 	$script_handles = array_unique( $script_handles );
   371 	if ( $has_emoji_styles ) {
   353 	$done           = wp_scripts()->done;
   372 		add_action( 'wp_print_styles', 'print_emoji_styles' );
       
   373 	}
   354 
   374 
   355 	ob_start();
   375 	ob_start();
   356 
   376 	wp_print_head_scripts();
   357 	wp_scripts()->done = array();
   377 	wp_print_footer_scripts();
   358 	wp_scripts()->do_items( $script_handles );
       
   359 	wp_scripts()->done = $done;
       
   360 
       
   361 	$scripts = ob_get_clean();
   378 	$scripts = ob_get_clean();
       
   379 
       
   380 	// Restore the original instances.
       
   381 	$wp_styles  = $current_wp_styles;
       
   382 	$wp_scripts = $current_wp_scripts;
   362 
   383 
   363 	return array(
   384 	return array(
   364 		'styles'  => $styles,
   385 		'styles'  => $styles,
   365 		'scripts' => $scripts,
   386 		'scripts' => $scripts,
   366 	);
   387 	);
       
   388 }
       
   389 
       
   390 /**
       
   391  * Finds the first occurrence of a specific block in an array of blocks.
       
   392  *
       
   393  * @since 6.3.0
       
   394  *
       
   395  * @param array  $blocks     Array of blocks.
       
   396  * @param string $block_name Name of the block to find.
       
   397  * @return array Found block, or empty array if none found.
       
   398  */
       
   399 function wp_get_first_block( $blocks, $block_name ) {
       
   400 	foreach ( $blocks as $block ) {
       
   401 		if ( $block_name === $block['blockName'] ) {
       
   402 			return $block;
       
   403 		}
       
   404 		if ( ! empty( $block['innerBlocks'] ) ) {
       
   405 			$found_block = wp_get_first_block( $block['innerBlocks'], $block_name );
       
   406 
       
   407 			if ( ! empty( $found_block ) ) {
       
   408 				return $found_block;
       
   409 			}
       
   410 		}
       
   411 	}
       
   412 
       
   413 	return array();
       
   414 }
       
   415 
       
   416 /**
       
   417  * Retrieves Post Content block attributes from the current post template.
       
   418  *
       
   419  * @since 6.3.0
       
   420  * @since 6.4.0 Return null if there is no post content block.
       
   421  * @access private
       
   422  *
       
   423  * @global int $post_ID
       
   424  *
       
   425  * @return array|null Post Content block attributes array or null if Post Content block doesn't exist.
       
   426  */
       
   427 function wp_get_post_content_block_attributes() {
       
   428 	global $post_ID;
       
   429 
       
   430 	$is_block_theme = wp_is_block_theme();
       
   431 
       
   432 	if ( ! $is_block_theme || ! $post_ID ) {
       
   433 		return null;
       
   434 	}
       
   435 
       
   436 	$template_slug = get_page_template_slug( $post_ID );
       
   437 
       
   438 	if ( ! $template_slug ) {
       
   439 		$post_slug      = 'singular';
       
   440 		$page_slug      = 'singular';
       
   441 		$template_types = get_block_templates();
       
   442 
       
   443 		foreach ( $template_types as $template_type ) {
       
   444 			if ( 'page' === $template_type->slug ) {
       
   445 				$page_slug = 'page';
       
   446 			}
       
   447 			if ( 'single' === $template_type->slug ) {
       
   448 				$post_slug = 'single';
       
   449 			}
       
   450 		}
       
   451 
       
   452 		$what_post_type = get_post_type( $post_ID );
       
   453 		switch ( $what_post_type ) {
       
   454 			case 'page':
       
   455 				$template_slug = $page_slug;
       
   456 				break;
       
   457 			default:
       
   458 				$template_slug = $post_slug;
       
   459 				break;
       
   460 		}
       
   461 	}
       
   462 
       
   463 	$current_template = get_block_templates( array( 'slug__in' => array( $template_slug ) ) );
       
   464 
       
   465 	if ( ! empty( $current_template ) ) {
       
   466 		$template_blocks    = parse_blocks( $current_template[0]->content );
       
   467 		$post_content_block = wp_get_first_block( $template_blocks, 'core/post-content' );
       
   468 
       
   469 		if ( isset( $post_content_block['attrs'] ) ) {
       
   470 			return $post_content_block['attrs'];
       
   471 		}
       
   472 	}
       
   473 
       
   474 	return null;
   367 }
   475 }
   368 
   476 
   369 /**
   477 /**
   370  * Returns the contextualized block editor settings for a selected editor context.
   478  * Returns the contextualized block editor settings for a selected editor context.
   371  *
   479  *
   405 			$preset_style['css'] = $actual_css;
   513 			$preset_style['css'] = $actual_css;
   406 			$global_styles[]     = $preset_style;
   514 			$global_styles[]     = $preset_style;
   407 		}
   515 		}
   408 	}
   516 	}
   409 
   517 
   410 	if ( WP_Theme_JSON_Resolver::theme_has_support() ) {
   518 	if ( wp_theme_has_theme_json() ) {
   411 		$block_classes = array(
   519 		$block_classes = array(
   412 			'css'            => 'styles',
   520 			'css'            => 'styles',
   413 			'__unstableType' => 'theme',
   521 			'__unstableType' => 'theme',
       
   522 			'isGlobalStyles' => true,
       
   523 		);
       
   524 		$actual_css    = wp_get_global_stylesheet( array( $block_classes['css'] ) );
       
   525 		if ( '' !== $actual_css ) {
       
   526 			$block_classes['css'] = $actual_css;
       
   527 			$global_styles[]      = $block_classes;
       
   528 		}
       
   529 
       
   530 		/*
       
   531 		 * Add the custom CSS as a separate stylesheet so any invalid CSS
       
   532 		 * entered by users does not break other global styles.
       
   533 		 */
       
   534 		$global_styles[] = array(
       
   535 			'css'            => wp_get_global_styles_custom_css(),
       
   536 			'__unstableType' => 'user',
       
   537 			'isGlobalStyles' => true,
       
   538 		);
       
   539 	} else {
       
   540 		// If there is no `theme.json` file, ensure base layout styles are still available.
       
   541 		$block_classes = array(
       
   542 			'css'            => 'base-layout-styles',
       
   543 			'__unstableType' => 'base-layout',
   414 			'isGlobalStyles' => true,
   544 			'isGlobalStyles' => true,
   415 		);
   545 		);
   416 		$actual_css    = wp_get_global_stylesheet( array( $block_classes['css'] ) );
   546 		$actual_css    = wp_get_global_stylesheet( array( $block_classes['css'] ) );
   417 		if ( '' !== $actual_css ) {
   547 		if ( '' !== $actual_css ) {
   418 			$block_classes['css'] = $actual_css;
   548 			$block_classes['css'] = $actual_css;
   473 	}
   603 	}
   474 	if ( isset( $editor_settings['__experimentalFeatures']['spacing']['padding'] ) ) {
   604 	if ( isset( $editor_settings['__experimentalFeatures']['spacing']['padding'] ) ) {
   475 		$editor_settings['enableCustomSpacing'] = $editor_settings['__experimentalFeatures']['spacing']['padding'];
   605 		$editor_settings['enableCustomSpacing'] = $editor_settings['__experimentalFeatures']['spacing']['padding'];
   476 		unset( $editor_settings['__experimentalFeatures']['spacing']['padding'] );
   606 		unset( $editor_settings['__experimentalFeatures']['spacing']['padding'] );
   477 	}
   607 	}
       
   608 	if ( isset( $editor_settings['__experimentalFeatures']['spacing']['customSpacingSize'] ) ) {
       
   609 		$editor_settings['disableCustomSpacingSizes'] = ! $editor_settings['__experimentalFeatures']['spacing']['customSpacingSize'];
       
   610 		unset( $editor_settings['__experimentalFeatures']['spacing']['customSpacingSize'] );
       
   611 	}
       
   612 
       
   613 	if ( isset( $editor_settings['__experimentalFeatures']['spacing']['spacingSizes'] ) ) {
       
   614 		$spacing_sizes_by_origin         = $editor_settings['__experimentalFeatures']['spacing']['spacingSizes'];
       
   615 		$editor_settings['spacingSizes'] = isset( $spacing_sizes_by_origin['custom'] ) ?
       
   616 			$spacing_sizes_by_origin['custom'] : (
       
   617 				isset( $spacing_sizes_by_origin['theme'] ) ?
       
   618 					$spacing_sizes_by_origin['theme'] :
       
   619 					$spacing_sizes_by_origin['default']
       
   620 			);
       
   621 	}
   478 
   622 
   479 	$editor_settings['__unstableResolvedAssets']         = _wp_get_iframed_editor_assets();
   623 	$editor_settings['__unstableResolvedAssets']         = _wp_get_iframed_editor_assets();
       
   624 	$editor_settings['__unstableIsBlockBasedTheme']      = wp_is_block_theme();
   480 	$editor_settings['localAutosaveInterval']            = 15;
   625 	$editor_settings['localAutosaveInterval']            = 15;
       
   626 	$editor_settings['disableLayoutStyles']              = current_theme_supports( 'disable-layout-styles' );
   481 	$editor_settings['__experimentalDiscussionSettings'] = array(
   627 	$editor_settings['__experimentalDiscussionSettings'] = array(
   482 		'commentOrder'         => get_option( 'comment_order' ),
   628 		'commentOrder'         => get_option( 'comment_order' ),
   483 		'commentsPerPage'      => get_option( 'comments_per_page' ),
   629 		'commentsPerPage'      => get_option( 'comments_per_page' ),
   484 		'defaultCommentsPage'  => get_option( 'default_comments_page' ),
   630 		'defaultCommentsPage'  => get_option( 'default_comments_page' ),
   485 		'pageComments'         => get_option( 'page_comments' ),
   631 		'pageComments'         => get_option( 'page_comments' ),
   494 				'default'       => get_option( 'avatar_default' ),
   640 				'default'       => get_option( 'avatar_default' ),
   495 			)
   641 			)
   496 		),
   642 		),
   497 	);
   643 	);
   498 
   644 
       
   645 	$post_content_block_attributes = wp_get_post_content_block_attributes();
       
   646 
       
   647 	if ( isset( $post_content_block_attributes ) ) {
       
   648 		$editor_settings['postContentAttributes'] = $post_content_block_attributes;
       
   649 	}
       
   650 
   499 	/**
   651 	/**
   500 	 * Filters the settings to pass to the block editor for all editor type.
   652 	 * Filters the settings to pass to the block editor for all editor type.
   501 	 *
   653 	 *
   502 	 * @since 5.8.0
   654 	 * @since 5.8.0
   503 	 *
   655 	 *
   532  *
   684  *
   533  * @global WP_Post    $post       Global post object.
   685  * @global WP_Post    $post       Global post object.
   534  * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
   686  * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
   535  * @global WP_Styles  $wp_styles  The WP_Styles object for printing styles.
   687  * @global WP_Styles  $wp_styles  The WP_Styles object for printing styles.
   536  *
   688  *
   537  * @param string[]                $preload_paths        List of paths to preload.
   689  * @param (string|string[])[]     $preload_paths        List of paths to preload.
   538  * @param WP_Block_Editor_Context $block_editor_context The current block editor context.
   690  * @param WP_Block_Editor_Context $block_editor_context The current block editor context.
   539  */
   691  */
   540 function block_editor_rest_api_preload( array $preload_paths, $block_editor_context ) {
   692 function block_editor_rest_api_preload( array $preload_paths, $block_editor_context ) {
   541 	global $post, $wp_scripts, $wp_styles;
   693 	global $post, $wp_scripts, $wp_styles;
   542 
   694 
   543 	/**
   695 	/**
   544 	 * Filters the array of REST API paths that will be used to preloaded common data for the block editor.
   696 	 * Filters the array of REST API paths that will be used to preloaded common data for the block editor.
   545 	 *
   697 	 *
   546 	 * @since 5.8.0
   698 	 * @since 5.8.0
   547 	 *
   699 	 *
   548 	 * @param string[]                $preload_paths        Array of paths to preload.
   700 	 * @param (string|string[])[]     $preload_paths        Array of paths to preload.
   549 	 * @param WP_Block_Editor_Context $block_editor_context The current block editor context.
   701 	 * @param WP_Block_Editor_Context $block_editor_context The current block editor context.
   550 	 */
   702 	 */
   551 	$preload_paths = apply_filters( 'block_editor_rest_api_preload_paths', $preload_paths, $block_editor_context );
   703 	$preload_paths = apply_filters( 'block_editor_rest_api_preload_paths', $preload_paths, $block_editor_context );
   552 
   704 
   553 	if ( ! empty( $block_editor_context->post ) ) {
   705 	if ( ! empty( $block_editor_context->post ) ) {
   559 		 * Preload common data by specifying an array of REST API paths that will be preloaded.
   711 		 * Preload common data by specifying an array of REST API paths that will be preloaded.
   560 		 *
   712 		 *
   561 		 * @since 5.0.0
   713 		 * @since 5.0.0
   562 		 * @deprecated 5.8.0 Use the {@see 'block_editor_rest_api_preload_paths'} filter instead.
   714 		 * @deprecated 5.8.0 Use the {@see 'block_editor_rest_api_preload_paths'} filter instead.
   563 		 *
   715 		 *
   564 		 * @param string[] $preload_paths Array of paths to preload.
   716 		 * @param (string|string[])[] $preload_paths Array of paths to preload.
   565 		 * @param WP_Post  $selected_post Post being edited.
   717 		 * @param WP_Post             $selected_post Post being edited.
   566 		 */
   718 		 */
   567 		$preload_paths = apply_filters_deprecated( 'block_editor_preload_paths', array( $preload_paths, $selected_post ), '5.8.0', 'block_editor_rest_api_preload_paths' );
   719 		$preload_paths = apply_filters_deprecated( 'block_editor_preload_paths', array( $preload_paths, $selected_post ), '5.8.0', 'block_editor_rest_api_preload_paths' );
   568 	}
   720 	}
   569 
   721 
   570 	if ( empty( $preload_paths ) ) {
   722 	if ( empty( $preload_paths ) ) {
   655 		}
   807 		}
   656 	}
   808 	}
   657 
   809 
   658 	return $styles;
   810 	return $styles;
   659 }
   811 }
       
   812 
       
   813 /**
       
   814  * Returns the classic theme supports settings for block editor.
       
   815  *
       
   816  * @since 6.2.0
       
   817  * @since 6.6.0 Add support for 'editor-spacing-sizes' theme support.
       
   818  *
       
   819  * @return array The classic theme supports settings.
       
   820  */
       
   821 function get_classic_theme_supports_block_editor_settings() {
       
   822 	$theme_settings = array(
       
   823 		'disableCustomColors'    => get_theme_support( 'disable-custom-colors' ),
       
   824 		'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
       
   825 		'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ),
       
   826 		'disableLayoutStyles'    => get_theme_support( 'disable-layout-styles' ),
       
   827 		'enableCustomLineHeight' => get_theme_support( 'custom-line-height' ),
       
   828 		'enableCustomSpacing'    => get_theme_support( 'custom-spacing' ),
       
   829 		'enableCustomUnits'      => get_theme_support( 'custom-units' ),
       
   830 	);
       
   831 
       
   832 	// Theme settings.
       
   833 	$color_palette = current( (array) get_theme_support( 'editor-color-palette' ) );
       
   834 	if ( false !== $color_palette ) {
       
   835 		$theme_settings['colors'] = $color_palette;
       
   836 	}
       
   837 
       
   838 	$font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) );
       
   839 	if ( false !== $font_sizes ) {
       
   840 		$theme_settings['fontSizes'] = $font_sizes;
       
   841 	}
       
   842 
       
   843 	$gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) );
       
   844 	if ( false !== $gradient_presets ) {
       
   845 		$theme_settings['gradients'] = $gradient_presets;
       
   846 	}
       
   847 
       
   848 	$spacing_sizes = current( (array) get_theme_support( 'editor-spacing-sizes' ) );
       
   849 	if ( false !== $spacing_sizes ) {
       
   850 		$theme_settings['spacingSizes'] = $spacing_sizes;
       
   851 	}
       
   852 
       
   853 	return $theme_settings;
       
   854 }