Make WordPress Core

Ticket #45285: get_hidden_meta_boxes-2.diff

File get_hidden_meta_boxes-2.diff, 2.9 KB (added by websupporter, 6 years ago)

Removes a tab, which is too much.

  • wp-admin/edit-form-blocks.php

    diff --git a/wp-admin/edit-form-blocks.php b/wp-admin/edit-form-blocks.php
    index 00fd098..a162c52 100644
    a b $editor_settings = array( 
    296296
    297297        // Whether or not to load the 'postcustom' meta box is stored as a user meta
    298298        // field so that we're not always loading its assets.
    299         'enableCustomFields'     => (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ),
     299        'enableCustomFields'     => ! in_array( 'postcustom', get_hidden_meta_boxes( get_current_screen() ) ),
    300300);
    301301
    302302$autosave = wp_get_post_autosave( $post_ID );
  • wp-admin/includes/meta-boxes.php

    diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php
    index 50b8713..301cdfd 100644
    a b function register_and_do_post_meta_boxes( $post ) { 
    13621362
    13631363        if ( post_type_supports($post_type, 'custom-fields') ) {
    13641364                $screen = get_current_screen();
    1365                 if ( ! $screen || ! $screen->is_block_editor() || (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true ) ) {
     1365                if ( ! $screen || ! $screen->is_block_editor() || ! in_array( 'postcustom', get_hidden_meta_boxes( $screen ) ) ) {
    13661366                        add_meta_box('postcustom', __('Custom Fields'), 'post_custom_meta_box', null, 'normal', 'core', array( '__back_compat_meta_box' => false, '__block_editor_compatible_meta_box' => true ) );
    13671367                }
    13681368        }
  • wp-admin/includes/post.php

    diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php
    index 462bde5..2471237 100644
    a b function the_block_editor_meta_boxes() { 
    21432143         * If the 'postcustom' meta box is enabled, then we need to perform some
    21442144         * extra initialization on it.
    21452145         */
    2146         $enable_custom_fields = (bool) get_user_meta( get_current_user_id(), 'enable_custom_fields', true );
     2146        $enable_custom_fields = ! in_array( 'postcustom', get_hidden_meta_boxes( get_current_screen() ) );
    21472147        if ( $enable_custom_fields ) {
    21482148                $script = "( function( $ ) {
    21492149                        if ( $('#postcustom').length ) {
  • wp-admin/post.php

    diff --git a/wp-admin/post.php b/wp-admin/post.php
    index 7c10241..f89a373 100644
    a b case 'toggle-custom-fields': 
    284284        check_admin_referer( 'toggle-custom-fields' );
    285285
    286286        $current_user_id = get_current_user_id();
     287        $screen = get_current_screen();
    287288        if ( $current_user_id ) {
    288                 $enable_custom_fields = (bool) get_user_meta( $current_user_id, 'enable_custom_fields', true );
    289                 update_user_meta( $current_user_id, 'enable_custom_fields', ! $enable_custom_fields );
     289                $hidden_meta_boxes = get_hidden_meta_boxes($screen);
     290                if ( in_array( 'postcustom', $hidden_meta_boxes ) ) {
     291                        unset( $hidden_meta_boxes[ array_search( 'postcustom', $hidden_meta_boxes ) ] );
     292                } else {
     293                        $hidden_meta_boxes[] = 'postcustom';
     294                }
     295                update_user_option($current_user_id, "metaboxhidden_" . $screen->id, $hidden_meta_boxes, true);
    290296        }
    291297
    292298        wp_safe_redirect( wp_get_referer() );