Make WordPress Core

Changeset 44260


Ignore:
Timestamp:
12/17/2018 03:51:08 AM (6 years ago)
Author:
desrosj
Message:

Editor: Add custom fields meta box support in the block editor.

This brings support for the custom fields meta box into the new block editor.

The webpack and copy-webpack-plugin packages have also been updated.

This does not bump the @wordpress packages like in [43861] because of conflicts with package versions already installed in trunk. The packages will be brought up to date in a subsequent merge.

Merges [43861] and [43863] into trunk.

See #45145.
Fixes #45257.

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/package-lock.json

    r44233 r44260  
    35633563        },
    35643564        "copy-webpack-plugin": {
    3565             "version": "4.5.2",
    3566             "resolved": "https://registry.npmjs.org/copy-webpack-plugin/-/copy-webpack-plugin-4.5.2.tgz",
    3567             "integrity": "sha512-zmC33E8FFSq3AbflTvqvPvBo621H36Afsxlui91d+QyZxPIuXghfnTsa1CuqiAaCPgJoSUWfTFbKJnadZpKEbQ==",
     3565            "version": "4.6.0",
     3566            "resolved": "https://registry.npmjs.org/copy-webpack-plugin/-/copy-webpack-plugin-4.6.0.tgz",
     3567            "integrity": "sha512-Y+SQCF+0NoWQryez2zXn5J5knmr9z/9qSQt7fbL78u83rxmigOy8X5+BFn8CFSuX+nKT8gpYwJX68ekqtQt6ZA==",
    35683568            "dev": true,
    35693569            "requires": {
  • trunk/package.json

    r44233 r44260  
    1818        "autoprefixer": "^9.1.5",
    1919        "check-node-version": "3.2.0",
    20         "copy-webpack-plugin": "^4.5.2",
     20        "copy-webpack-plugin": "^4.6.0",
    2121        "cssnano": "^4.1.4",
    2222        "grunt": "~1.0.3",
     
    5050        "uglify-js": "^3.4.9",
    5151        "uglifyjs-webpack-plugin": "^2.0.1",
    52         "webpack": "^4.20.2",
     52        "webpack": "^4.24.0",
    5353        "webpack-dev-server": "^3.1.9",
    5454        "webpack-livereload-plugin": "^2.1.1"
  • trunk/src/wp-admin/edit-form-blocks.php

    r44251 r44260  
    203203}
    204204
     205// Image sizes.
     206$image_sizes   = get_intermediate_image_sizes();
     207$image_sizes[] = 'full';
     208
     209/** This filter is documented in wp-admin/includes/media.php */
     210$image_size_names = apply_filters(
     211    'image_size_names_choose',
     212    array(
     213        'thumbnail' => __( 'Thumbnail' ),
     214        'medium'    => __( 'Medium' ),
     215        'large'     => __( 'Large' ),
     216        'full'      => __( 'Full Size' ),
     217    )
     218);
     219
     220$available_image_sizes = array();
     221foreach ( $image_sizes as $image_size_slug ) {
     222    $available_image_sizes[] = array(
     223        'slug' => $image_size_slug,
     224        'name' => isset( $image_size_names[ $image_size_slug ] ) ? $image_size_names[ $image_size_slug ] : $image_size_slug,
     225    );
     226}
     227
    205228// Lock settings.
    206229$user_id = wp_check_post_lock( $post->ID );
     
    258281    'allowedMimeTypes'       => get_allowed_mime_types(),
    259282    'styles'                 => $styles,
     283    'availableImageSizes'    => $available_image_sizes,
    260284    'postLock'               => $lock_details,
    261285    'postLockUtils'          => array(
     
    264288        'ajaxUrl'     => admin_url( 'admin-ajax.php' ),
    265289    ),
     290
     291    // Whether or not to load the 'postcustom' meta box is stored as a user meta
     292    // field so that we're not always loading its assets.
     293    'enableCustomFields'     => (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ),
    266294);
    267295
  • trunk/src/wp-admin/includes/meta-boxes.php

    r44244 r44260  
    14641464
    14651465    if ( post_type_supports( $post_type, 'custom-fields' ) ) {
    1466         $args = array(
    1467             '__back_compat_meta_box'             => ! (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ),
    1468             '__block_editor_compatible_meta_box' => true,
    1469         );
    1470         add_meta_box( 'postcustom', __( 'Custom Fields' ), 'post_custom_meta_box', null, 'normal', 'core', $args );
     1466        $screen = get_current_screen();
     1467        if ( ! $screen || ! $screen->is_block_editor() || (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ) ) {
     1468            add_meta_box(
     1469                'postcustom',
     1470                __( 'Custom Fields' ),
     1471                'post_custom_meta_box',
     1472                null,
     1473                'normal',
     1474                'core',
     1475                array(
     1476                    '__back_compat_meta_box'             => false,
     1477                    '__block_editor_compatible_meta_box' => true,
     1478                )
     1479            );
     1480        }
    14711481    }
    14721482
  • trunk/src/wp-admin/includes/post.php

    r44243 r44260  
    21132113            'slug'  => 'common',
    21142114            'title' => __( 'Common Blocks' ),
    2115             'icon'  => 'screenoptions',
     2115            'icon'  => null,
    21162116        ),
    21172117        array(
     
    22152215    <?php the_block_editor_meta_box_post_form_hidden_fields( $post ); ?>
    22162216    </form>
     2217    <form id="toggle-custom-fields-form" method="post" action="<?php echo esc_attr( admin_url( 'post.php' ) ); ?>">
     2218        <?php wp_nonce_field( 'toggle-custom-fields' ); ?>
     2219        <input type="hidden" name="action" value="toggle-custom-fields" />
     2220    </form>
    22172221    <?php foreach ( $locations as $location ) : ?>
    22182222        <form class="metabox-location-<?php echo esc_attr( $location ); ?>" onsubmit="return false;">
     
    22902294    }
    22912295
     2296    /**
     2297     * If the 'postcustom' meta box is enabled, then we need to perform some
     2298     * extra initialization on it.
     2299     */
     2300    $enable_custom_fields = (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true );
     2301    if ( $enable_custom_fields ) {
     2302        $script = "( function( $ ) {
     2303            if ( $('#postcustom').length ) {
     2304                $( '#the-list' ).wpList( {
     2305                    addBefore: function( s ) {
     2306                        s.data += '&post_id=$post->ID';
     2307                        return s;
     2308                    },
     2309                    addAfter: function() {
     2310                        $('table#list-table').show();
     2311                    }
     2312                });
     2313            }
     2314        } )( jQuery );";
     2315        wp_enqueue_script( 'wp-lists' );
     2316        wp_add_inline_script( 'wp-lists', $script );
     2317    }
     2318
    22922319    // Reset meta box data.
    22932320    $wp_meta_boxes = $_original_meta_boxes;
  • trunk/src/wp-admin/post.php

    r44165 r44260  
    313313        exit();
    314314
     315    case 'toggle-custom-fields':
     316        check_admin_referer( 'toggle-custom-fields' );
     317
     318        $current_user_id = get_current_user_id();
     319        if ( $current_user_id ) {
     320            $enable_custom_fields = (bool) get_user_meta( $current_user_id, 'enable_custom_fields', true );
     321            update_user_meta( $current_user_id, 'enable_custom_fields', ! $enable_custom_fields );
     322        }
     323
     324        wp_safe_redirect( wp_get_referer() );
     325        exit();
     326
    315327    default:
    316328        /**
  • trunk/src/wp-includes/script-loader.php

    r44252 r44260  
    236236            'lodash',
    237237            'wp-compose',
     238            'wp-deprecated',
    238239            'wp-element',
    239240            'wp-is-shallow-equal',
     
    352353            'wp-blocks',
    353354            'wp-data',
     355            'wp-deprecated',
    354356            'wp-escape-html',
    355357            'wp-polyfill',
Note: See TracChangeset for help on using the changeset viewer.