Skip to content

Commit

Permalink
Use allow-list for mobile editor settings endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mkevins committed Nov 22, 2023
1 parent 014d163 commit 16e6185
Showing 1 changed file with 87 additions and 1 deletion.
88 changes: 87 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,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) {

Check failure on line 21 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

The "keep_supported_block_editor_settings_mobile()" function should be guarded against redeclaration.

Check failure on line 21 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 spaces after opening parenthesis; 0 found

Check failure on line 21 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 spaces before closing parenthesis; 0 found
$result = array();

Check failure on line 22 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed

foreach ($allow_list_array as $key => $value) {

Check failure on line 24 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 24 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

No space after opening parenthesis is prohibited

Check failure on line 24 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

No space before closing parenthesis is prohibited
$initial_value = $initial_array[$key];

Check failure on line 25 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed

Check failure on line 25 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array keys must be surrounded by spaces unless they contain a string or an integer.

if (array_key_exists($key, $initial_array)) {

Check failure on line 27 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Tabs must be used to indent lines; spaces are not allowed
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 +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,

Check warning on line 69 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 24 space(s) between ""alignWide"" and double arrow, but found 1.
"allowedBlockTypes" => true,

Check warning on line 70 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 16 space(s) between ""allowedBlockTypes"" and double arrow, but found 1.
"allowedMimeTypes" => true,

Check warning on line 71 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 17 space(s) between ""allowedMimeTypes"" and double arrow, but found 1.
"defaultEditorStyles" => true,

Check warning on line 72 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 14 space(s) between ""defaultEditorStyles"" and double arrow, but found 1.
"blockCategories" => true,

Check warning on line 73 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 18 space(s) between ""blockCategories"" and double arrow, but found 1.
"isRTL" => true,

Check warning on line 74 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 28 space(s) between ""isRTL"" and double arrow, but found 1.
"imageDefaultSize" => true,

Check warning on line 75 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 17 space(s) between ""imageDefaultSize"" and double arrow, but found 1.
"imageDimensions" => true,

Check warning on line 76 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 18 space(s) between ""imageDimensions"" and double arrow, but found 1.
"imageEditing" => true,

Check warning on line 77 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 21 space(s) between ""imageEditing"" and double arrow, but found 1.
"imageSizes" => true,

Check warning on line 78 in lib/experimental/block-editor-settings-mobile.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Array double arrow not aligned correctly; expected 23 space(s) between ""imageSizes"" and double arrow, but found 1.
"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 );

0 comments on commit 16e6185

Please sign in to comment.