diff --git a/lib/experimental/block-editor-settings-mobile.php b/lib/experimental/block-editor-settings-mobile.php index 91e3694c199f83..2557c96992d387 100644 --- a/lib/experimental/block-editor-settings-mobile.php +++ b/lib/experimental/block-editor-settings-mobile.php @@ -5,6 +5,38 @@ * @package gutenberg */ +/** + * Keeps only supported settings for the mobile block editor. + * + * This is used to control the editor settings payload. Keys can be specified + * as `true` to be allowed, which will also allow entire nested structures. + * Alternatively, nested structures can have nested allow-lists for their keys. + * + * @param array $initial_array Existing block editor settings. + * + * @param array $allow_list_array Structured allow-list. + * + * @return array New block editor settings. + */ +function keep_supported_block_editor_settings_mobile($initial_array, $allow_list_array) { + $result = array(); + + foreach ($allow_list_array as $key => $value) { + $initial_value = $initial_array[$key]; + + if (array_key_exists($key, $initial_array)) { + if (is_array($value) && is_array($initial_value)) { + $result[$key] = keep_supported_block_editor_settings_mobile($initial_value, $value); + } else { + $result[$key] = $initial_value; + } + } + } + + return $result; +} + + /** * Adds settings to the mobile block editor. * @@ -33,7 +65,61 @@ function gutenberg_get_block_editor_settings_mobile( $settings ) { $settings['__experimentalEnableListBlockV2'] = true; } - return $settings; + return keep_supported_block_editor_settings_mobile($settings, array( + "alignWide" => true, + "allowedBlockTypes" => true, + "allowedMimeTypes" => true, + "defaultEditorStyles" => true, + "blockCategories" => true, + "isRTL" => true, + "imageDefaultSize" => true, + "imageDimensions" => true, + "imageEditing" => true, + "imageSizes" => true, + "maxUploadFileSize" => true, + "__unstableGalleryWithImageBlocks" => true, + "disableCustomColors" => true, + "disableCustomFontSizes" => true, + "disableCustomGradients" => true, + "disableLayoutStyles" => true, + "enableCustomLineHeight" => true, + "enableCustomSpacing" => true, + "enableCustomUnits" => true, + "colors" => true, + "fontSizes" => true, + "__experimentalFeatures" => array( + "appearanceTools" => true, + "useRootPaddingAwareAlignments" => true, + "border" => true, + "color" => true, + "shadow" => true, + "spacing" => true, + "typography" => array( + "dropCap" => true, + "fontSizes" => true, + "fontStyle" => true, + "fontWeight" => true, + "letterSpacing" => true, + "textColumns" => true, + "textDecoration" => true, + "textTransform" => true, + "writingMode" => true, + ), + "blocks" => true, + "background" => true, + "dimensions" => true, + "position" => true, + ), + "gradients" => true, + "disableCustomSpacingSizes" => true, + "spacingSizes" => true, + "__unstableIsBlockBasedTheme" => true, + "localAutosaveInterval" => true, + "__experimentalDiscussionSettings" => true, + "__experimentalDashboardLink" => true, + "__experimentalEnableQuoteBlockV2" => true, + "__experimentalEnableListBlockV2" => true, + )); } add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings_mobile', PHP_INT_MAX );