WordPress.org

Make WordPress Core

Changeset 50776


Ignore:
Timestamp:
04/21/2021 05:10:56 AM (3 months ago)
Author:
gziolo
Message:

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 #52920.

Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-form-blocks.php

    r50761 r50776  
    2323 */
    2424global $post_type, $post_type_object, $post, $title, $editor_styles, $wp_meta_boxes;
     25
     26$editor_name = 'post-editor';
    2527
    2628// Flag that we're loading the block editor.
     
    5759);
    5860
     61
    5962/**
    6063 * Preload common data by specifying an array of REST API paths that will be preloaded.
     
    136139);
    137140
    138 
    139 /*
    140  * Initialize the editor.
    141  */
    142 
    143 $align_wide         = get_theme_support( 'align-wide' );
    144 $color_palette      = current( (array) get_theme_support( 'editor-color-palette' ) );
    145 $font_sizes         = current( (array) get_theme_support( 'editor-font-sizes' ) );
    146 $gradient_presets   = current( (array) get_theme_support( 'editor-gradient-presets' ) );
    147 $custom_line_height = get_theme_support( 'custom-line-height' );
    148 $custom_units       = get_theme_support( 'custom-units' );
    149 $custom_spacing     = get_theme_support( 'custom-spacing' );
    150 
    151 /**
    152  * Filters the allowed block types for the editor, defaulting to true (all
    153  * block types supported).
    154  *
    155  * @since 5.0.0
    156  *
    157  * @param bool|array $allowed_block_types Array of block type slugs, or
    158  *                                        boolean to enable/disable all.
    159  * @param WP_Post    $post                The post resource data.
    160  */
    161 $allowed_block_types = apply_filters( 'allowed_block_types', true, $post );
    162 
    163141/*
    164142 * Get all available templates for the post/page attributes meta-box.
     
    175153    $available_templates
    176154) : $available_templates;
    177 
    178 // Media settings.
    179 $max_upload_size = wp_max_upload_size();
    180 if ( ! $max_upload_size ) {
    181     $max_upload_size = 0;
    182 }
    183155
    184156// Editor Styles.
     
    209181}
    210182
    211 // Image sizes.
    212 
    213 /** This filter is documented in wp-admin/includes/media.php */
    214 $image_size_names = apply_filters(
    215     'image_size_names_choose',
    216     array(
    217         'thumbnail' => __( 'Thumbnail' ),
    218         'medium'    => __( 'Medium' ),
    219         'large'     => __( 'Large' ),
    220         'full'      => __( 'Full Size' ),
    221     )
    222 );
    223 
    224 $available_image_sizes = array();
    225 foreach ( $image_size_names as $image_size_slug => $image_size_name ) {
    226     $available_image_sizes[] = array(
    227         'slug' => $image_size_slug,
    228         'name' => $image_size_name,
    229     );
    230 }
    231 
    232 $default_size       = get_option( 'image_default_size', 'large' );
    233 $image_default_size = in_array( $default_size, array_keys( $image_size_names ), true ) ? $image_default_size : 'large';
    234 
    235 $image_dimensions = array();
    236 $all_sizes        = wp_get_registered_image_subsizes();
    237 foreach ( $available_image_sizes as $size ) {
    238     $key = $size['slug'];
    239     if ( isset( $all_sizes[ $key ] ) ) {
    240         $image_dimensions[ $key ] = $all_sizes[ $key ];
    241     }
    242 }
    243 
    244183// Lock settings.
    245184$user_id = wp_check_post_lock( $post->ID );
     
    290229
    291230$editor_settings = array(
    292     'alignWide'                            => $align_wide,
    293231    'availableTemplates'                   => $available_templates,
    294     'allowedBlockTypes'                    => $allowed_block_types,
    295     'disableCustomColors'                  => get_theme_support( 'disable-custom-colors' ),
    296     'disableCustomFontSizes'               => get_theme_support( 'disable-custom-font-sizes' ),
    297     'disableCustomGradients'               => get_theme_support( 'disable-custom-gradients' ),
    298232    'disablePostFormats'                   => ! current_theme_supports( 'post-formats' ),
    299233    /** This filter is documented in wp-admin/edit-form-advanced.php */
    300234    'titlePlaceholder'                     => apply_filters( 'enter_title_here', __( 'Add title' ), $post ),
    301235    'bodyPlaceholder'                      => $body_placeholder,
    302     'isRTL'                                => is_rtl(),
    303236    'autosaveInterval'                     => AUTOSAVE_INTERVAL,
    304     'maxUploadFileSize'                    => $max_upload_size,
    305     'allowedMimeTypes'                     => get_allowed_mime_types(),
    306237    'styles'                               => $styles,
    307     'imageSizes'                           => $available_image_sizes,
    308     'imageDefaultSize'                     => $image_default_size,
    309     'imageDimensions'                      => $image_dimensions,
    310238    'richEditingEnabled'                   => user_can_richedit(),
    311239    'postLock'                             => $lock_details,
     
    321249    // field so that we're not always loading its assets.
    322250    'enableCustomFields'                   => (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ),
    323     'enableCustomLineHeight'               => $custom_line_height,
    324     'enableCustomUnits'                    => $custom_units,
    325     'enableCustomSpacing'                  => $custom_spacing,
    326251);
    327252
     
    337262}
    338263
    339 if ( false !== $color_palette ) {
    340     $editor_settings['colors'] = $color_palette;
    341 }
    342 
    343 if ( false !== $font_sizes ) {
    344     $editor_settings['fontSizes'] = $font_sizes;
    345 }
    346 
    347 if ( false !== $gradient_presets ) {
    348     $editor_settings['gradients'] = $gradient_presets;
    349 }
    350 
    351264if ( ! empty( $post_type_object->template ) ) {
    352265    $editor_settings['template']     = $post_type_object->template;
     
    373286wp_enqueue_editor();
    374287
    375 
    376288/**
    377289 * Styles
     
    401313}
    402314
    403 /**
    404  * Filters the settings to pass to the block editor.
    405  *
    406  * @since 5.0.0
    407  *
    408  * @param array   $editor_settings Default editor settings.
    409  * @param WP_Post $post            Post being edited.
    410  */
    411 $editor_settings = apply_filters( 'block_editor_settings', $editor_settings, $post );
     315$editor_settings = get_block_editor_settings( $editor_name, $editor_settings );
    412316
    413317$init_script = <<<JS
  • trunk/src/wp-admin/includes/post.php

    r50618 r50776  
    21822182
    21832183/**
    2184  * Returns all the block categories that will be shown in the block editor.
    2185  *
    2186  * @since 5.0.0
    2187  *
    2188  * @param WP_Post $post Post object.
    2189  * @return array[] Array of block categories.
    2190  */
    2191 function get_block_categories( $post ) {
    2192     $default_categories = array(
    2193         array(
    2194             'slug'  => 'text',
    2195             'title' => _x( 'Text', 'block category' ),
    2196             'icon'  => null,
    2197         ),
    2198         array(
    2199             'slug'  => 'media',
    2200             'title' => _x( 'Media', 'block category' ),
    2201             'icon'  => null,
    2202         ),
    2203         array(
    2204             'slug'  => 'design',
    2205             'title' => _x( 'Design', 'block category' ),
    2206             'icon'  => null,
    2207         ),
    2208         array(
    2209             'slug'  => 'widgets',
    2210             'title' => _x( 'Widgets', 'block category' ),
    2211             'icon'  => null,
    2212         ),
    2213         array(
    2214             'slug'  => 'theme',
    2215             'title' => _x( 'Theme', 'block category' ),
    2216             'icon'  => null,
    2217         ),
    2218         array(
    2219             'slug'  => 'embed',
    2220             'title' => _x( 'Embeds', 'block category' ),
    2221             'icon'  => null,
    2222         ),
    2223         array(
    2224             'slug'  => 'reusable',
    2225             'title' => _x( 'Reusable Blocks', 'block category' ),
    2226             'icon'  => null,
    2227         ),
    2228     );
    2229 
    2230     /**
    2231      * Filters the default array of block categories.
    2232      *
    2233      * @since 5.0.0
    2234      *
    2235      * @param array[] $default_categories Array of block categories.
    2236      * @param WP_Post $post               Post being loaded.
    2237      */
    2238     return apply_filters( 'block_categories', $default_categories, $post );
    2239 }
    2240 
    2241 /**
    22422184 * Prepares server-registered blocks for the block editor.
    22432185 *
  • trunk/src/wp-settings.php

    r50761 r50776  
    295295require ABSPATH . WPINC . '/blocks.php';
    296296require ABSPATH . WPINC . '/blocks/index.php';
     297require ABSPATH . WPINC . '/block-editor.php';
    297298require ABSPATH . WPINC . '/block-patterns.php';
    298299require ABSPATH . WPINC . '/class-wp-block-supports.php';
Note: See TracChangeset for help on using the changeset viewer.