From f44e3f17407c06a2ac40411bf860b0a3684cc00a Mon Sep 17 00:00:00 2001 From: Anton Timmermans Date: Fri, 14 Dec 2018 09:38:09 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@44174 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/template.php | 34 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/wp-admin/includes/template.php b/src/wp-admin/includes/template.php index 58505fa9f4..336e353a28 100644 --- a/src/wp-admin/includes/template.php +++ b/src/wp-admin/includes/template.php @@ -1137,25 +1137,27 @@ function do_meta_boxes( $screen, $context, $object ) { continue; } - // Don't show boxes in the block editor, if they're just here for back compat. - if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) { - continue; - } + if ( is_array( $box[ 'args' ] ) ) { + // If a meta box is just here for back compat, don't show it in the block editor. + if ( $screen->is_block_editor() && isset( $box['args']['__back_compat_meta_box'] ) && $box['args']['__back_compat_meta_box'] ) { + continue; + } - // Don't show boxes in the block editor that aren't compatible with the block editor. - if ( $screen->is_block_editor() && isset( $box['args']['__block_editor_compatible_meta_box'] ) && ! $box['args']['__block_editor_compatible_meta_box'] ) { - continue; - } + // If a meta box doesn't work in the block editor, don't show it in the block editor. + if ( $screen->is_block_editor() && isset( $box['args']['__block_editor_compatible_meta_box'] ) && ! $box['args']['__block_editor_compatible_meta_box'] ) { + continue; + } - $block_compatible = true; - if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) { - $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box']; - unset( $box['args']['__block_editor_compatible_meta_box'] ); - } + $block_compatible = true; + if ( isset( $box['args']['__block_editor_compatible_meta_box'] ) ) { + $block_compatible = (bool) $box['args']['__block_editor_compatible_meta_box']; + unset( $box['args']['__block_editor_compatible_meta_box'] ); + } - if ( isset( $box['args']['__back_compat_meta_box'] ) ) { - $block_compatible |= (bool) $box['args']['__back_compat_meta_box']; - unset( $box['args']['__back_compat_meta_box'] ); + if ( isset( $box['args']['__back_compat_meta_box'] ) ) { + $block_compatible = $block_compatible || (bool) $box['args']['__back_compat_meta_box']; + unset( $box['args']['__back_compat_meta_box'] ); + } } $i++;