Make WordPress Core


Ignore:
Timestamp:
04/21/2021 05:10:56 AM (4 years 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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.