fix: Undefined index "colors" warning#2982
fix: Undefined index "colors" warning#2982gziolo merged 2 commits intoWordPress:masterfrom ayoolatj:fix/2198-undefined-index-colors
Conversation
gziolo
left a comment
There was a problem hiding this comment.
Thanks for opening this PR. It fixes the bug described in #2198:
<b>Notice</b>: Undefined index: colors in <b>/srv/www/editor/htdocs/wp-content/plugins/gutenberg/lib/client-assets.php</b> on line <b>654</b><br />but there is still another PHP notice in this code that needs to be fixed:
<b>Notice</b>: Undefined index: wide-images in <b>/srv/www/wordpress-default/public_html/wp-content/plugins/lib/client-assets.php</b> on line <b>791</b><br>|
I've updated my code to fix the second php notice |
lib/client-assets.php
Outdated
There was a problem hiding this comment.
I'm wondering if empty isn't powerful enough to make it possible to simplify it to:
if ( ! empty( $gutenberg_theme_support[0]['colors'] ) ) {There was a problem hiding this comment.
Sorry, I'm a little lost. Can you explain further?
There was a problem hiding this comment.
Determine whether a variable is considered to be empty. A variable is considered empty if it does not exist or if its value equals FALSE. empty() does not generate a warning if the variable does not exist.
You don't need to check if $gutenberg_theme_support is truthy, because empty does that, too. It makes this line shorter and works exactly the same.
There was a problem hiding this comment.
I just tested with the following code:
function mytheme_setup_theme_supported_features() {
add_theme_support( 'gutenberg', null );
}
add_action( 'after_setup_theme', 'mytheme_setup_theme_supported_features' );There was a problem hiding this comment.
Yeah that's right, should I update the PR with this?
There was a problem hiding this comment.
If you like it, then go for it. Totally up to you :)
|
That was quick, thanks. Testing your changes :) |
lib/client-assets.php
Outdated
There was a problem hiding this comment.
In this place it would get simplified to the following:
'wideImages' => ! empty( $gutenberg_theme_support[0]['wide-images'] ) ),|
Thanks for another update. It looks great now. 🎉 |
* master: (45 commits) Parser: Hide the core namespace in serialised data (WordPress#2950) fix: Undefined index warning (WordPress#2982) navigation via keydown PHPCS improvements (WordPress#2914) Update/html block description (WordPress#2917) Framework: Merge EditorSettingsProvider into EditorProvider Framework: Move the store initialization to a dedicated component Rotate header ellipsis to match block ellipsis add/459: Added support for ins, sub and sup Refresh nonce with heartbeat (WordPress#2790) Paste: add table support Bump version to 1.4.0. (WordPress#2954) Blocks: The custom classname should be persisted properly in the block's comment Editor: Fix the scroll position when reordering blocks Polish spacing in block ellipsis menu (WordPress#2955) Editor: HTML Editor per block (WordPress#2797) Show most frequently used blocks next to inserter (WordPress#2877) add/459: Added light grey background to selected inline boundaries Extend inline boundaries to other elements Move markdown fix to own plugin-compatibility file ...
* master: (45 commits) Parser: Hide the core namespace in serialised data (WordPress#2950) fix: Undefined index warning (WordPress#2982) navigation via keydown PHPCS improvements (WordPress#2914) Update/html block description (WordPress#2917) Framework: Merge EditorSettingsProvider into EditorProvider Framework: Move the store initialization to a dedicated component Rotate header ellipsis to match block ellipsis add/459: Added support for ins, sub and sup Refresh nonce with heartbeat (WordPress#2790) Paste: add table support Bump version to 1.4.0. (WordPress#2954) Blocks: The custom classname should be persisted properly in the block's comment Editor: Fix the scroll position when reordering blocks Polish spacing in block ellipsis menu (WordPress#2955) Editor: HTML Editor per block (WordPress#2797) Show most frequently used blocks next to inserter (WordPress#2877) add/459: Added light grey background to selected inline boundaries Extend inline boundaries to other elements Move markdown fix to own plugin-compatibility file ...
* master: (45 commits) Parser: Hide the core namespace in serialised data (WordPress#2950) fix: Undefined index warning (WordPress#2982) navigation via keydown PHPCS improvements (WordPress#2914) Update/html block description (WordPress#2917) Framework: Merge EditorSettingsProvider into EditorProvider Framework: Move the store initialization to a dedicated component Rotate header ellipsis to match block ellipsis add/459: Added support for ins, sub and sup Refresh nonce with heartbeat (WordPress#2790) Paste: add table support Bump version to 1.4.0. (WordPress#2954) Blocks: The custom classname should be persisted properly in the block's comment Editor: Fix the scroll position when reordering blocks Polish spacing in block ellipsis menu (WordPress#2955) Editor: HTML Editor per block (WordPress#2797) Show most frequently used blocks next to inserter (WordPress#2877) add/459: Added light grey background to selected inline boundaries Extend inline boundaries to other elements Move markdown fix to own plugin-compatibility file ...
Check that key exists and is not empty.
resolves: #2198