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( |
296 | 296 | |
297 | 297 | // Whether or not to load the 'postcustom' meta box is stored as a user meta |
298 | 298 | // 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() ) ), |
300 | 300 | ); |
301 | 301 | |
302 | 302 | $autosave = wp_get_post_autosave( $post_ID ); |
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 ) { |
1362 | 1362 | |
1363 | 1363 | if ( post_type_supports($post_type, 'custom-fields') ) { |
1364 | 1364 | $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 ) ) ) { |
1366 | 1366 | 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 ) ); |
1367 | 1367 | } |
1368 | 1368 | } |
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() { |
2143 | 2143 | * If the 'postcustom' meta box is enabled, then we need to perform some |
2144 | 2144 | * extra initialization on it. |
2145 | 2145 | */ |
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() ) ); |
2147 | 2147 | if ( $enable_custom_fields ) { |
2148 | 2148 | $script = "( function( $ ) { |
2149 | 2149 | if ( $('#postcustom').length ) { |
diff --git a/wp-admin/post.php b/wp-admin/post.php
index 7c10241..f89a373 100644
a
|
b
|
case 'toggle-custom-fields': |
284 | 284 | check_admin_referer( 'toggle-custom-fields' ); |
285 | 285 | |
286 | 286 | $current_user_id = get_current_user_id(); |
| 287 | $screen = get_current_screen(); |
287 | 288 | 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); |
290 | 296 | } |
291 | 297 | |
292 | 298 | wp_safe_redirect( wp_get_referer() ); |