-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
mkevins
wants to merge
11
commits into
trunk
Choose a base branch
from
fix/use-allow-list-for-mobile-editor-settings
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
16e6185
Use allow-list for mobile editor settings endpoint
mkevins f65e77a
refactor: Format php
dcalhoun df2b3d5
refactor: Guard mobile allow list utility against redeclaration
dcalhoun 3e4a8c1
fix: Avoid error from selecting non-existent settings key
dcalhoun a4995db
fix: Add `__experimentalStyles` key to the allow list
dcalhoun 8f072e3
Rename mobile settings allow-list filter function
mkevins 7f3d705
Extract mobile editor settings allow list to a constant
mkevins 9c19187
Remove experimental dashboard link from the mobile allow list
mkevins ce92b82
Extract mobile editor settings filter to a separate file
mkevins 0a1e7bd
Load mobile-specific filter for the editor settings endpoint
mkevins a7cb39f
refactor: Format php
dcalhoun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
lib/experimental/block-editor-settings-mobile-allowed.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
/** | ||
* Filters settings for the mobile block editor. | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
if ( ! function_exists( 'filter_by_supported_block_editor_settings_mobile' ) ) { | ||
/** | ||
* Recursively filters for supported settings. | ||
* | ||
* 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 filter_by_supported_block_editor_settings_mobile( $initial_array, $allow_list_array ) { | ||
$result = array(); | ||
|
||
foreach ( $allow_list_array as $key => $value ) { | ||
if ( ! array_key_exists( $key, $initial_array ) ) { | ||
continue; | ||
} | ||
|
||
$initial_value = $initial_array[ $key ]; | ||
|
||
if ( array_key_exists( $key, $initial_array ) ) { | ||
if ( is_array( $value ) && is_array( $initial_value ) ) { | ||
$result[ $key ] = filter_by_supported_block_editor_settings_mobile( $initial_value, $value ); | ||
} else { | ||
$result[ $key ] = $initial_value; | ||
} | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} | ||
|
||
if ( ! function_exists( 'gutenberg_get_allowed_block_editor_settings_mobile' ) ) { | ||
/** | ||
* Keeps only supported settings for the mobile block editor. | ||
* | ||
* @param array $settings Existing block editor settings. | ||
* | ||
* @return array New block editor settings. | ||
*/ | ||
function gutenberg_get_allowed_block_editor_settings_mobile( $settings ) { | ||
|
||
if ( | ||
defined( 'REST_REQUEST' ) && | ||
REST_REQUEST && | ||
isset( $_GET['context'] ) && | ||
'mobile' === $_GET['context'] | ||
) { | ||
return filter_by_supported_block_editor_settings_mobile( | ||
$settings, | ||
BLOCK_EDITOR_SETTINGS_MOBILE_ALLOW_LIST | ||
); | ||
} else { | ||
return $settings; | ||
} | ||
} | ||
} | ||
|
||
if ( ! defined( 'BLOCK_EDITOR_SETTINGS_MOBILE_ALLOW_LIST' ) ) { | ||
define( | ||
'BLOCK_EDITOR_SETTINGS_MOBILE_ALLOW_LIST', | ||
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, | ||
'__experimentalStyles' => array( | ||
'elements' => true, | ||
'spacing' => true, | ||
'blocks' => true, | ||
'color' => true, | ||
'typography' => 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, | ||
'__experimentalEnableQuoteBlockV2' => true, | ||
'__experimentalEnableListBlockV2' => true, | ||
) | ||
); | ||
} | ||
|
||
add_filter( 'block_editor_settings_all', 'gutenberg_get_allowed_block_editor_settings_mobile', PHP_INT_MAX ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also add the
custom
attribute which is used for custom variables or other settings. The app uses it to get values for custom variables.