Make WordPress Core

Changeset 44174


Ignore:
Timestamp:
12/14/2018 09:38:09 AM (6 years ago)
Author:
atimmer
Message:

Meta boxes: Don't assume that callback args are an array.

While the documentation for add_meta_box() specifices that $callback_args should be an array, this has never been enforced, and we have workarounds in place for when it's passed as something other than an array.

Rather than break sites that are passing unexpected data, we can quietly just allow for it, instead.

Props johnjamesjacoby, birgire, pento.
Merges [43838] to trunk.
Fixes #45206.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/wp-admin/includes/template.php

    r44170 r44174  
    11381138                    }
    11391139
    1140                     // Don't show boxes in the block editor, if they're just here for back compat.
    1141                     if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {
    1142                         continue;
    1143                     }
    1144 
    1145                     // Don't show boxes in the block editor that aren't compatible with the block editor.
    1146                     if ( $screen->is_block_editor() && isset( $box['args']['__block_editor_compatible_meta_box'] ) && ! $box['args']['__block_editor_compatible_meta_box'] ) {
    1147                         continue;
    1148                     }
    1149 
    1150                     $block_compatible = true;
    1151                     if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {
    1152                         $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];
    1153                         unset( $box['args']['__block_editor_compatible_meta_box'] );
    1154                     }
    1155 
    1156                     if ( isset( $box['args']['__back_compat_meta_box'] ) ) {
    1157                         $block_compatible |= (bool) $box['args']['__back_compat_meta_box'];
    1158                         unset( $box['args']['__back_compat_meta_box'] );
     1140                    if ( is_array( $box[ 'args' ] ) ) {
     1141                        // If a meta box is just here for back compat, don't show it in the block editor.
     1142                        if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {
     1143                            continue;
     1144                        }
     1145
     1146                        // If a meta box doesn't work in the block editor, don't show it in the block editor.
     1147                        if ( $screen->is_block_editor() && isset( $box['args']['__block_editor_compatible_meta_box'] ) && ! $box['args']['__block_editor_compatible_meta_box'] ) {
     1148                            continue;
     1149                        }
     1150
     1151                        $block_compatible = true;
     1152                        if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {
     1153                            $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];
     1154                            unset( $box['args']['__block_editor_compatible_meta_box'] );
     1155                        }
     1156
     1157                        if ( isset( $box['args']['__back_compat_meta_box'] ) ) {
     1158                            $block_compatible = $block_compatible || (bool) $box['args']['__back_compat_meta_box'];
     1159                            unset( $box['args']['__back_compat_meta_box'] );
     1160                        }
    11591161                    }
    11601162
Note: See TracChangeset for help on using the changeset viewer.