Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use allow-list for mobile editor settings endpoint #56424

Draft
wants to merge 11 commits into
base: trunk
Choose a base branch
from
93 changes: 92 additions & 1 deletion lib/experimental/block-editor-settings-mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,40 @@
* @package gutenberg
*/

if ( ! function_exists( 'keep_supported_block_editor_settings_mobile' ) ) {
/**
* 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.
*
Expand Down Expand Up @@ -33,7 +67,64 @@ function gutenberg_get_block_editor_settings_mobile( $settings ) {
$settings['__experimentalEnableListBlockV2'] = true;
}

return $settings;
return keep_supported_block_editor_settings_mobile(
dcalhoun marked this conversation as resolved.
Show resolved Hide resolved
$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,
dcalhoun marked this conversation as resolved.
Show resolved Hide resolved
'__experimentalEnableQuoteBlockV2' => true,
'__experimentalEnableListBlockV2' => true,
)
dcalhoun marked this conversation as resolved.
Show resolved Hide resolved
);
}

add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings_mobile', PHP_INT_MAX );
Loading