Make WordPress Core


Ignore:
Timestamp:
10/29/2018 03:15:11 AM (8 years ago)
Author:
pento
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.
Fixes #45206.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-admin/includes/template.php

    r43830 r43838  
    10531053                                                continue;
    10541054
    1055                                         // Don't show boxes in the block editor, if they're just here for back compat.
    1056                                         if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {
    1057                                                 continue;
    1058                                         }
    1059 
    1060                                         // Don't show boxes in the block editor that aren't compatible with the block editor.
    1061                                         if ( $screen->is_block_editor() && isset( $box['args']['__block_editor_compatible_meta_box'] ) && ! $box['args']['__block_editor_compatible_meta_box'] ) {
    1062                                                 continue;
    1063                                         }
    1064 
    1065                                         $block_compatible = true;
    1066                                         if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {
    1067                                                 $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];
    1068                                                 unset( $box['args']['__block_editor_compatible_meta_box'] );
    1069                                         }
    1070 
    1071                                         if ( isset( $box['args']['__back_compat_meta_box'] ) ) {
    1072                                                 $block_compatible |= (bool) $box['args']['__back_compat_meta_box'];
    1073                                                 unset( $box['args']['__back_compat_meta_box'] );
     1055                                        if ( is_array( $box[ 'args' ] ) ) {
     1056                                                // If a meta box is just here for back compat, don't show it in the block editor.
     1057                                                if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) {
     1058                                                        continue;
     1059                                                }
     1060
     1061                                                // If a meta box doesn't work in the block editor, don't show it in the block editor.
     1062                                                if ( $screen->is_block_editor() && isset( $box['args']['__block_editor_compatible_meta_box'] ) && ! $box['args']['__block_editor_compatible_meta_box'] ) {
     1063                                                        continue;
     1064                                                }
     1065
     1066                                                $block_compatible = true;
     1067                                                if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) {
     1068                                                        $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box'];
     1069                                                        unset( $box['args']['__block_editor_compatible_meta_box'] );
     1070                                                }
     1071
     1072                                                if ( isset( $box['args']['__back_compat_meta_box'] ) ) {
     1073                                                        $block_compatible = $block_compatible || (bool) $box['args']['__back_compat_meta_box'];
     1074                                                        unset( $box['args']['__back_compat_meta_box'] );
     1075                                                }
    10741076                                        }
    10751077
Note: See TracChangeset for help on using the changeset viewer.