<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[50776] trunk: Editor: Abstract block editor configuration</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/50776">50776</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/50776","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>gziolo</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-04-21 05:10:56 +0000 (Wed, 21 Apr 2021)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Editor: Abstract block editor configuration
There are several WordPress hooks defined on the server that depend on $post object that isn't present on the new screens like edit site, edit widgets, or edit navigation. This patch deprecates existing filters and introduces replacements that are context-aware.
Props azaozz, andraganescu, jeremyfelt, nosolosw, youknowriad.
See <a href="https://core.trac.wordpress.org/ticket/52920">#52920</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadmineditformblocksphp">trunk/src/wp-admin/edit-form-blocks.php</a></li>
<li><a href="#trunksrcwpadminincludespostphp">trunk/src/wp-admin/includes/post.php</a></li>
<li><a href="#trunksrcwpsettingsphp">trunk/src/wp-settings.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblockeditorphp">trunk/src/wp-includes/block-editor.php</a></li>
<li><a href="#trunktestsphpunittestsblocksblockeditorphp">trunk/tests/phpunit/tests/blocks/block-editor.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadmineditformblocksphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/edit-form-blocks.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/edit-form-blocks.php 2021-04-21 01:31:45 UTC (rev 50775)
+++ trunk/src/wp-admin/edit-form-blocks.php 2021-04-21 05:10:56 UTC (rev 50776)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -23,6 +23,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> global $post_type, $post_type_object, $post, $title, $editor_styles, $wp_meta_boxes;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+$editor_name = 'post-editor';
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Flag that we're loading the block editor.
</span><span class="cx" style="display: block; padding: 0 10px"> $current_screen = get_current_screen();
</span><span class="cx" style="display: block; padding: 0 10px"> $current_screen->is_block_editor( true );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -56,6 +58,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> sprintf( '/wp/v2/%s/%d/autosaves?context=edit', $rest_base, $post->ID ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Preload common data by specifying an array of REST API paths that will be preloaded.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -135,32 +138,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'before'
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> /*
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Initialize the editor.
- */
-
-$align_wide = get_theme_support( 'align-wide' );
-$color_palette = current( (array) get_theme_support( 'editor-color-palette' ) );
-$font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) );
-$gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) );
-$custom_line_height = get_theme_support( 'custom-line-height' );
-$custom_units = get_theme_support( 'custom-units' );
-$custom_spacing = get_theme_support( 'custom-spacing' );
-
-/**
- * Filters the allowed block types for the editor, defaulting to true (all
- * block types supported).
- *
- * @since 5.0.0
- *
- * @param bool|array $allowed_block_types Array of block type slugs, or
- * boolean to enable/disable all.
- * @param WP_Post $post The post resource data.
- */
-$allowed_block_types = apply_filters( 'allowed_block_types', true, $post );
-
-/*
</del><span class="cx" style="display: block; padding: 0 10px"> * Get all available templates for the post/page attributes meta-box.
</span><span class="cx" style="display: block; padding: 0 10px"> * The "Default template" array element should only be added if the array is
</span><span class="cx" style="display: block; padding: 0 10px"> * not empty so we do not trigger the template select element without any options
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -175,12 +153,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $available_templates
</span><span class="cx" style="display: block; padding: 0 10px"> ) : $available_templates;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-// Media settings.
-$max_upload_size = wp_max_upload_size();
-if ( ! $max_upload_size ) {
- $max_upload_size = 0;
-}
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Editor Styles.
</span><span class="cx" style="display: block; padding: 0 10px"> $styles = array(
</span><span class="cx" style="display: block; padding: 0 10px"> array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -208,39 +180,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-// Image sizes.
-
-/** This filter is documented in wp-admin/includes/media.php */
-$image_size_names = apply_filters(
- 'image_size_names_choose',
- array(
- 'thumbnail' => __( 'Thumbnail' ),
- 'medium' => __( 'Medium' ),
- 'large' => __( 'Large' ),
- 'full' => __( 'Full Size' ),
- )
-);
-
-$available_image_sizes = array();
-foreach ( $image_size_names as $image_size_slug => $image_size_name ) {
- $available_image_sizes[] = array(
- 'slug' => $image_size_slug,
- 'name' => $image_size_name,
- );
-}
-
-$default_size = get_option( 'image_default_size', 'large' );
-$image_default_size = in_array( $default_size, array_keys( $image_size_names ), true ) ? $image_default_size : 'large';
-
-$image_dimensions = array();
-$all_sizes = wp_get_registered_image_subsizes();
-foreach ( $available_image_sizes as $size ) {
- $key = $size['slug'];
- if ( isset( $all_sizes[ $key ] ) ) {
- $image_dimensions[ $key ] = $all_sizes[ $key ];
- }
-}
-
</del><span class="cx" style="display: block; padding: 0 10px"> // Lock settings.
</span><span class="cx" style="display: block; padding: 0 10px"> $user_id = wp_check_post_lock( $post->ID );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $user_id ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -289,24 +228,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $body_placeholder = apply_filters( 'write_your_story', __( 'Type / to choose a block' ), $post );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $editor_settings = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'alignWide' => $align_wide,
</del><span class="cx" style="display: block; padding: 0 10px"> 'availableTemplates' => $available_templates,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'allowedBlockTypes' => $allowed_block_types,
- 'disableCustomColors' => get_theme_support( 'disable-custom-colors' ),
- 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
- 'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ),
</del><span class="cx" style="display: block; padding: 0 10px"> 'disablePostFormats' => ! current_theme_supports( 'post-formats' ),
</span><span class="cx" style="display: block; padding: 0 10px"> /** This filter is documented in wp-admin/edit-form-advanced.php */
</span><span class="cx" style="display: block; padding: 0 10px"> 'titlePlaceholder' => apply_filters( 'enter_title_here', __( 'Add title' ), $post ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'bodyPlaceholder' => $body_placeholder,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'isRTL' => is_rtl(),
</del><span class="cx" style="display: block; padding: 0 10px"> 'autosaveInterval' => AUTOSAVE_INTERVAL,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'maxUploadFileSize' => $max_upload_size,
- 'allowedMimeTypes' => get_allowed_mime_types(),
</del><span class="cx" style="display: block; padding: 0 10px"> 'styles' => $styles,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'imageSizes' => $available_image_sizes,
- 'imageDefaultSize' => $image_default_size,
- 'imageDimensions' => $image_dimensions,
</del><span class="cx" style="display: block; padding: 0 10px"> 'richEditingEnabled' => user_can_richedit(),
</span><span class="cx" style="display: block; padding: 0 10px"> 'postLock' => $lock_details,
</span><span class="cx" style="display: block; padding: 0 10px"> 'postLockUtils' => array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -320,9 +248,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // Whether or not to load the 'postcustom' meta box is stored as a user meta
</span><span class="cx" style="display: block; padding: 0 10px"> // field so that we're not always loading its assets.
</span><span class="cx" style="display: block; padding: 0 10px"> 'enableCustomFields' => (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'enableCustomLineHeight' => $custom_line_height,
- 'enableCustomUnits' => $custom_units,
- 'enableCustomSpacing' => $custom_spacing,
</del><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $autosave = wp_get_post_autosave( $post->ID );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -336,18 +261,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-if ( false !== $color_palette ) {
- $editor_settings['colors'] = $color_palette;
-}
-
-if ( false !== $font_sizes ) {
- $editor_settings['fontSizes'] = $font_sizes;
-}
-
-if ( false !== $gradient_presets ) {
- $editor_settings['gradients'] = $gradient_presets;
-}
-
</del><span class="cx" style="display: block; padding: 0 10px"> if ( ! empty( $post_type_object->template ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $editor_settings['template'] = $post_type_object->template;
</span><span class="cx" style="display: block; padding: 0 10px"> $editor_settings['templateLock'] = ! empty( $post_type_object->template_lock ) ? $post_type_object->template_lock : false;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -372,7 +285,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> wp_tinymce_inline_scripts();
</span><span class="cx" style="display: block; padding: 0 10px"> wp_enqueue_editor();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Styles
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -400,15 +312,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $editor_settings['enableCustomFields'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/**
- * Filters the settings to pass to the block editor.
- *
- * @since 5.0.0
- *
- * @param array $editor_settings Default editor settings.
- * @param WP_Post $post Post being edited.
- */
-$editor_settings = apply_filters( 'block_editor_settings', $editor_settings, $post );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+$editor_settings = get_block_editor_settings( $editor_name, $editor_settings );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $init_script = <<<JS
</span><span class="cx" style="display: block; padding: 0 10px"> ( function() {
</span></span></pre></div>
<a id="trunksrcwpadminincludespostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/post.php 2021-04-21 01:31:45 UTC (rev 50775)
+++ trunk/src/wp-admin/includes/post.php 2021-04-21 05:10:56 UTC (rev 50776)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2181,64 +2181,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Returns all the block categories that will be shown in the block editor.
- *
- * @since 5.0.0
- *
- * @param WP_Post $post Post object.
- * @return array[] Array of block categories.
- */
-function get_block_categories( $post ) {
- $default_categories = array(
- array(
- 'slug' => 'text',
- 'title' => _x( 'Text', 'block category' ),
- 'icon' => null,
- ),
- array(
- 'slug' => 'media',
- 'title' => _x( 'Media', 'block category' ),
- 'icon' => null,
- ),
- array(
- 'slug' => 'design',
- 'title' => _x( 'Design', 'block category' ),
- 'icon' => null,
- ),
- array(
- 'slug' => 'widgets',
- 'title' => _x( 'Widgets', 'block category' ),
- 'icon' => null,
- ),
- array(
- 'slug' => 'theme',
- 'title' => _x( 'Theme', 'block category' ),
- 'icon' => null,
- ),
- array(
- 'slug' => 'embed',
- 'title' => _x( 'Embeds', 'block category' ),
- 'icon' => null,
- ),
- array(
- 'slug' => 'reusable',
- 'title' => _x( 'Reusable Blocks', 'block category' ),
- 'icon' => null,
- ),
- );
-
- /**
- * Filters the default array of block categories.
- *
- * @since 5.0.0
- *
- * @param array[] $default_categories Array of block categories.
- * @param WP_Post $post Post being loaded.
- */
- return apply_filters( 'block_categories', $default_categories, $post );
-}
-
-/**
</del><span class="cx" style="display: block; padding: 0 10px"> * Prepares server-registered blocks for the block editor.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * Returns an associative array of registered block data keyed by block name. Data includes properties
</span></span></pre></div>
<a id="trunksrcwpincludesblockeditorphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/src/wp-includes/block-editor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-editor.php (rev 0)
+++ trunk/src/wp-includes/block-editor.php 2021-04-21 05:10:56 UTC (rev 50776)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,267 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Block Editor API.
+ *
+ * @package WordPress
+ * @subpackage Editor
+ * @since 5.8.0
+ */
+
+/**
+ * Returns the list of default categories for block types.
+ *
+ * @since 5.8.0.
+ *
+ * @return array[] Array of categories for block types.
+ */
+function get_default_block_categories() {
+ return array(
+ array(
+ 'slug' => 'text',
+ 'title' => _x( 'Text', 'block category' ),
+ 'icon' => null,
+ ),
+ array(
+ 'slug' => 'media',
+ 'title' => _x( 'Media', 'block category' ),
+ 'icon' => null,
+ ),
+ array(
+ 'slug' => 'design',
+ 'title' => _x( 'Design', 'block category' ),
+ 'icon' => null,
+ ),
+ array(
+ 'slug' => 'widgets',
+ 'title' => _x( 'Widgets', 'block category' ),
+ 'icon' => null,
+ ),
+ array(
+ 'slug' => 'theme',
+ 'title' => _x( 'Theme', 'block category' ),
+ 'icon' => null,
+ ),
+ array(
+ 'slug' => 'embed',
+ 'title' => _x( 'Embeds', 'block category' ),
+ 'icon' => null,
+ ),
+ array(
+ 'slug' => 'reusable',
+ 'title' => _x( 'Reusable Blocks', 'block category' ),
+ 'icon' => null,
+ ),
+ );
+}
+
+/**
+ * Returns all the categories for block types that will be shown in the block editor.
+ *
+ * @since 5.0.0
+ *
+ * @param string|WP_Post $editor_name_or_post The name of the editor (e.g. 'post-editor')
+ * or the post object.
+ *
+ * @return array[] Array of categories for block types.
+ */
+function get_block_categories( $editor_name_or_post ) {
+ // Assume the post editor when the WP_Post object passed.
+ $editor_name = is_object( $editor_name_or_post ) ? 'post-editor' : $editor_name_or_post;
+ $default_categories = get_default_block_categories();
+
+ /**
+ * Filters the default array of categories for block types.
+ *
+ * @since 5.8.0
+ *
+ * @param array[] $default_categories Array of categories for block types.
+ */
+ $block_categories = apply_filters( "block_categories_{$editor_name}", $default_categories );
+ if ( 'post-editor' === $editor_name ) {
+ $post = is_object( $editor_name_or_post ) ? $editor_name_or_post : get_post();
+
+ /**
+ * Filters the default array of categories for block types.
+ *
+ * @since 5.0.0
+ * @deprecated 5.8.0 The hook transitioned to support also screens that don't contain the $post instance.
+ *
+ * @param array[] $block_categories Array of categories for block types.
+ * @param WP_Post $post Post being loaded.
+ */
+ $block_categories = apply_filters_deprecated( 'block_categories', array( $block_categories, $post ), '5.8.0', "block_categories_{$editor_name}" );
+ }
+
+ return $block_categories;
+}
+
+/**
+ * Gets the list of allowed block types to use in the block editor.
+ *
+ * @since 5.8.0
+ *
+ * @param string $editor_name The name of the editor (e.g. 'post-editor').
+ *
+ * @return bool|array Array of block type slugs, or boolean to enable/disable all.
+ */
+function get_allowed_block_types( $editor_name ) {
+ $allowed_block_types = true;
+
+ /**
+ * Filters the allowed block types for the given editor, defaulting to true (all
+ * registered block types supported).
+ *
+ * @since 5.8.0
+ *
+ * @param bool|array $allowed_block_types Array of block type slugs, or
+ * boolean to enable/disable all.
+ */
+ $allowed_block_types = apply_filters( "allowed_block_types_{$editor_name}", $allowed_block_types );
+ if ( 'post-editor' === $editor_name ) {
+ $post = get_post();
+
+ /**
+ * Filters the allowed block types for the editor, defaulting to true (all
+ * block types supported).
+ *
+ * @since 5.0.0
+ * @deprecated 5.8.0 The hook transitioned to support also screens that don't contain $post instance.
+ *
+ * @param bool|array $allowed_block_types Array of block type slugs, or
+ * boolean to enable/disable all.
+ * @param WP_Post $post The post resource data.
+ */
+ $allowed_block_types = apply_filters_deprecated( 'allowed_block_types', array( $allowed_block_types, $post ), '5.8.0', "allowed_block_types_{$editor_name}" );
+ }
+
+ return $allowed_block_types;
+}
+
+/**
+ * Returns the default block editor settings.
+ *
+ * @since 5.8.0
+ *
+ * @return array The default block editor settings.
+ */
+function get_default_block_editor_settings() {
+ // Media settings.
+ $max_upload_size = wp_max_upload_size();
+ if ( ! $max_upload_size ) {
+ $max_upload_size = 0;
+ }
+
+ /** This filter is documented in wp-admin/includes/media.php */
+ $image_size_names = apply_filters(
+ 'image_size_names_choose',
+ array(
+ 'thumbnail' => __( 'Thumbnail' ),
+ 'medium' => __( 'Medium' ),
+ 'large' => __( 'Large' ),
+ 'full' => __( 'Full Size' ),
+ )
+ );
+
+ $available_image_sizes = array();
+ foreach ( $image_size_names as $image_size_slug => $image_size_name ) {
+ $available_image_sizes[] = array(
+ 'slug' => $image_size_slug,
+ 'name' => $image_size_name,
+ );
+ }
+
+ $default_size = get_option( 'image_default_size', 'large' );
+ $image_default_size = in_array( $default_size, array_keys( $image_size_names ), true ) ? $image_default_size : 'large';
+
+ $image_dimensions = array();
+ $all_sizes = wp_get_registered_image_subsizes();
+ foreach ( $available_image_sizes as $size ) {
+ $key = $size['slug'];
+ if ( isset( $all_sizes[ $key ] ) ) {
+ $image_dimensions[ $key ] = $all_sizes[ $key ];
+ }
+ }
+
+ $editor_settings = array(
+ 'alignWide' => get_theme_support( 'align-wide' ),
+ 'allowedBlockTypes' => true,
+ 'allowedMimeTypes' => get_allowed_mime_types(),
+ 'blockCategories' => get_default_block_categories(),
+ 'disableCustomColors' => get_theme_support( 'disable-custom-colors' ),
+ 'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
+ 'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ),
+ 'enableCustomLineHeight' => get_theme_support( 'custom-line-height' ),
+ 'enableCustomSpacing' => get_theme_support( 'custom-spacing' ),
+ 'enableCustomUnits' => get_theme_support( 'custom-units' ),
+ 'isRTL' => is_rtl(),
+ 'imageDefaultSize' => $image_default_size,
+ 'imageDimensions' => $image_dimensions,
+ 'imageEditing' => true,
+ 'imageSizes' => $available_image_sizes,
+ 'maxUploadFileSize' => $max_upload_size,
+ );
+
+ // Theme settings.
+ $color_palette = current( (array) get_theme_support( 'editor-color-palette' ) );
+ if ( false !== $color_palette ) {
+ $editor_settings['colors'] = $color_palette;
+ }
+
+ $font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) );
+ if ( false !== $font_sizes ) {
+ $editor_settings['fontSizes'] = $font_sizes;
+ }
+
+ $gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) );
+ if ( false !== $gradient_presets ) {
+ $editor_settings['gradients'] = $gradient_presets;
+ }
+
+ return $editor_settings;
+}
+
+/**
+ * Returns the contextualized block editor settings settings for a selected editor type.
+ *
+ * @since 5.8.0
+ *
+ * @param string $editor_name The name of the editor (e.g. 'post-editor').
+ * @param array $custom_settings Optional custom settings to use with the editor type.
+ *
+ * @return array The contextualized block editor settings.
+ */
+function get_block_editor_settings( $editor_name, $custom_settings = array() ) {
+ $editor_settings = array_merge(
+ get_default_block_editor_settings( $editor_name ),
+ array(
+ 'allowedBlockTypes' => get_allowed_block_types( $editor_name ),
+ 'blockCategories' => get_block_categories( $editor_name ),
+ ),
+ $custom_settings
+ );
+
+ /**
+ * Filters the settings to pass to the block editor for a given editor type.
+ *
+ * @since 5.8.0
+ *
+ * @param array $editor_settings Default editor settings.
+ */
+ $editor_settings = apply_filters( "block_editor_settings_{$editor_name}", $editor_settings );
+ if ( 'post-editor' === $editor_name ) {
+ $post = get_post();
+
+ /**
+ * Filters the settings to pass to the block editor.
+ *
+ * @since 5.0.0
+ * @deprecated 5.8.0 The hook transitioned to support also screens that don't contain $post instance.
+ *
+ * @param array $editor_settings Default editor settings.
+ * @param WP_Post $post Post being edited.
+ */
+ $editor_settings = apply_filters_deprecated( 'block_editor_settings', array( $editor_settings, $post ), '5.8.0', "block_editor_settings_{$editor_name}" );
+ }
+
+ return $editor_settings;
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/src/wp-includes/block-editor.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="trunksrcwpsettingsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-settings.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-settings.php 2021-04-21 01:31:45 UTC (rev 50775)
+++ trunk/src/wp-settings.php 2021-04-21 05:10:56 UTC (rev 50776)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -294,6 +294,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/class-wp-block-parser.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/blocks.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/blocks/index.php';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+require ABSPATH . WPINC . '/block-editor.php';
</ins><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/block-patterns.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/class-wp-block-supports.php';
</span><span class="cx" style="display: block; padding: 0 10px"> require ABSPATH . WPINC . '/block-supports/align.php';
</span></span></pre></div>
<a id="trunktestsphpunittestsblocksblockeditorphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: trunk/tests/phpunit/tests/blocks/block-editor.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/blocks/block-editor.php (rev 0)
+++ trunk/tests/phpunit/tests/blocks/block-editor.php 2021-04-21 05:10:56 UTC (rev 50776)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,312 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * WP_Block Tests
+ *
+ * @package WordPress
+ * @subpackage Blocks
+ * @since 5.5.0
+ */
+
+/**
+ * Tests for the block editor methods.
+ *
+ * @since 5.5.0
+ *
+ * @group blocks
+ */
+class WP_Test_Block_Editor extends WP_UnitTestCase {
+
+ /**
+ * Sets up each test method.
+ */
+ public function setUp() {
+ global $post;
+
+ parent::setUp();
+
+ $args = array(
+ 'post_title' => 'Example',
+ );
+
+ $post = $this->factory()->post->create_and_get( $args );
+ }
+
+ function filter_set_block_categories_post( $block_categories, $post ) {
+ if ( empty( $post ) ) {
+ return $block_categories;
+ }
+
+ return array(
+ array(
+ 'slug' => 'filtered-category',
+ 'title' => 'Filtered Category',
+ 'icon' => null,
+ ),
+ );
+ }
+
+ function filter_set_allowed_block_types_post( $allowed_block_types, $post ) {
+ if ( empty( $post ) ) {
+ return $allowed_block_types;
+ }
+
+ return array( 'test/filtered-block' );
+ }
+
+ function filter_set_block_editor_settings_post( $editor_settings, $post ) {
+ if ( empty( $post ) ) {
+ return $allowed_block_types;
+ }
+
+ return array(
+ 'filter' => 'deprecated',
+ );
+ }
+
+ /**
+ * @ticket 52920
+ * @expectedDeprecated block_categories
+ */
+ function test_get_block_categories_deprecated_filter_post_object() {
+ add_filter( 'block_categories', array( $this, 'filter_set_block_categories_post' ), 10, 2 );
+
+ $block_categories = get_block_categories( get_post() );
+
+ remove_filter( 'block_categories', array( $this, 'filter_set_block_categories_post' ) );
+
+ $this->assertSameSets(
+ array(
+ array(
+ 'slug' => 'filtered-category',
+ 'title' => 'Filtered Category',
+ 'icon' => null,
+ ),
+ ),
+ $block_categories
+ );
+ }
+
+ /**
+ * @ticket 52920
+ * @expectedDeprecated block_categories
+ */
+ function test_get_block_categories_deprecated_filter_post_editor() {
+ add_filter( 'block_categories', array( $this, 'filter_set_block_categories_post' ), 10, 2 );
+
+ $block_categories = get_block_categories( 'post-editor' );
+
+ remove_filter( 'block_categories', array( $this, 'filter_set_block_categories_post' ) );
+
+ $this->assertSameSets(
+ array(
+ array(
+ 'slug' => 'filtered-category',
+ 'title' => 'Filtered Category',
+ 'icon' => null,
+ ),
+ ),
+ $block_categories
+ );
+ }
+
+ /**
+ * @ticket 52920
+ */
+ function test_get_allowed_block_types_default() {
+ $allowed_block_types = get_allowed_block_types( 'post-editor' );
+
+ $this->assertTrue( $allowed_block_types );
+ }
+
+ /**
+ * @ticket 52920
+ * @expectedDeprecated allowed_block_types
+ */
+ function test_get_allowed_block_types_deprecated_filter_post_editor() {
+ add_filter( 'allowed_block_types', array( $this, 'filter_set_allowed_block_types_post' ), 10, 2 );
+
+ $allowed_block_types = get_allowed_block_types( 'post-editor' );
+
+ remove_filter( 'allowed_block_types', array( $this, 'filter_set_allowed_block_types_post' ) );
+
+ $this->assertSameSets( array( 'test/filtered-block' ), $allowed_block_types );
+ }
+
+ /**
+ * @ticket 52920
+ */
+ function test_get_default_block_editor_settings() {
+ $settings = get_default_block_editor_settings();
+
+ $this->assertCount( 16, $settings );
+ $this->assertFalse( $settings['alignWide'] );
+ $this->assertInternalType( 'array', $settings['allowedMimeTypes'] );
+ $this->assertTrue( $settings['allowedBlockTypes'] );
+ $this->assertSameSets(
+ array(
+ array(
+ 'slug' => 'text',
+ 'title' => 'Text',
+ 'icon' => null,
+ ),
+ array(
+ 'slug' => 'media',
+ 'title' => 'Media',
+ 'icon' => null,
+ ),
+ array(
+ 'slug' => 'design',
+ 'title' => 'Design',
+ 'icon' => null,
+ ),
+ array(
+ 'slug' => 'widgets',
+ 'title' => 'Widgets',
+ 'icon' => null,
+ ),
+ array(
+ 'slug' => 'theme',
+ 'title' => 'Theme',
+ 'icon' => null,
+ ),
+ array(
+ 'slug' => 'embed',
+ 'title' => 'Embeds',
+ 'icon' => null,
+ ),
+ array(
+ 'slug' => 'reusable',
+ 'title' => 'Reusable Blocks',
+ 'icon' => null,
+ ),
+ ),
+ $settings['blockCategories']
+ );
+ $this->assertFalse( $settings['disableCustomColors'] );
+ $this->assertFalse( $settings['disableCustomFontSizes'] );
+ $this->assertFalse( $settings['disableCustomGradients'] );
+ $this->assertFalse( $settings['enableCustomLineHeight'] );
+ $this->assertFalse( $settings['enableCustomSpacing'] );
+ $this->assertFalse( $settings['enableCustomUnits'] );
+ $this->assertFalse( $settings['isRTL'] );
+ $this->assertSame( 'large', $settings['imageDefaultSize'] );
+ $this->assertSameSets(
+ array(
+ array(
+ 'width' => 150,
+ 'height' => 150,
+ 'crop' => true,
+ ),
+ array(
+ 'width' => 300,
+ 'height' => 300,
+ 'crop' => false,
+ ),
+ array(
+ 'width' => 1024,
+ 'height' => 1024,
+ 'crop' => false,
+ ),
+ ),
+ $settings['imageDimensions']
+ );
+ $this->assertTrue( $settings['imageEditing'] );
+ $this->assertSameSets(
+ array(
+ array(
+ 'slug' => 'full',
+ 'name' => 'Full Size',
+ ),
+ array(
+ 'slug' => 'large',
+ 'name' => 'Large',
+ ),
+ array(
+ 'slug' => 'medium',
+ 'name' => 'Medium',
+ ),
+ array(
+ 'slug' => 'thumbnail',
+ 'name' => 'Thumbnail',
+ ),
+ ),
+ $settings['imageSizes']
+ );
+ $this->assertInternalType( 'int', $settings['maxUploadFileSize'] );
+ }
+
+ /**
+ * @ticket 52920
+ */
+ function test_get_block_editor_settings_returns_default_settings() {
+ $this->assertSameSets(
+ get_block_editor_settings( 'my-editor' ),
+ get_default_block_editor_settings()
+ );
+ }
+
+ /**
+ * @ticket 52920
+ */
+ function test_get_block_editor_settings_overrides_default_settings_my_editor() {
+ function filter_allowed_block_types_my_editor() {
+ return array( 'test/filtered-my-block' );
+ }
+ function filter_block_categories_my_editor() {
+ return array(
+ array(
+ 'slug' => 'filtered-my-category',
+ 'title' => 'Filtered My Category',
+ 'icon' => null,
+ ),
+ );
+ }
+ function filter_block_editor_settings_my_editor( $editor_settings ) {
+ $editor_settings['maxUploadFileSize'] = 12345;
+
+ return $editor_settings;
+ }
+
+ add_filter( 'allowed_block_types_my-editor', 'filter_allowed_block_types_my_editor', 10, 1 );
+ add_filter( 'block_categories_my-editor', 'filter_block_categories_my_editor', 10, 1 );
+ add_filter( 'block_editor_settings_my-editor', 'filter_block_editor_settings_my_editor', 10, 1 );
+
+ $settings = get_block_editor_settings( 'my-editor' );
+
+ remove_filter( 'allowed_block_types_my-editor', 'filter_allowed_block_types_my_editor' );
+ remove_filter( 'block_categories_my-editor', 'filter_block_categories_my_editor' );
+ remove_filter( 'block_editor_settings_my-editor', 'filter_block_editor_settings_my_editor' );
+
+ $this->assertSameSets( array( 'test/filtered-my-block' ), $settings['allowedBlockTypes'] );
+ $this->assertSameSets(
+ array(
+ array(
+ 'slug' => 'filtered-my-category',
+ 'title' => 'Filtered My Category',
+ 'icon' => null,
+ ),
+ ),
+ $settings['blockCategories']
+ );
+ $this->assertSame( 12345, $settings['maxUploadFileSize'] );
+ }
+
+ /**
+ * @ticket 52920
+ * @expectedDeprecated block_editor_settings
+ */
+ function test_get_block_editor_settings_deprecated_filter_post_editor() {
+ add_filter( 'block_editor_settings', array( $this, 'filter_set_block_editor_settings_post' ), 10, 2 );
+
+ $settings = get_block_editor_settings( 'post-editor' );
+
+ remove_filter( 'block_editor_settings', array( $this, 'filter_set_block_editor_settings_post' ) );
+
+ $this->assertSameSets(
+ array(
+ 'filter' => 'deprecated',
+ ),
+ $settings
+ );
+ }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: trunk/tests/phpunit/tests/blocks/block-editor.php
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span></div>
</body>
</html>