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

Elements: check value and whitelist before building style nodes #43622

Merged
merged 2 commits into from
Aug 29, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ protected static function get_style_nodes( $theme_json, $selectors = array() ) {

if ( isset( $theme_json['styles']['elements'] ) ) {
foreach ( self::ELEMENTS as $element => $selector ) {
if ( ! isset( $theme_json['styles']['elements'][ $element ] ) ) {
if ( ! isset( $theme_json['styles']['elements'][ $element ] ) || empty( static::ELEMENTS[ $element ] ) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will produce an Undefined index in PHP 5.6 - https://3v4l.org/vqKpS#v5.6.40, and we cannot use isset() since it will result in a fatal error.

So let's use array_key_exists, similar to #42567.

Copy link
Member Author

@ramonjd ramonjd Aug 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Mamaduka

Just checking, do you mean the isset( $theme_json['styles']['elements'][ $element ] ) or empty( static::ELEMENTS[ $element ] )?

Or isn't empty okay with constants either?

I'll update to

if ( ! isset( $theme_json['styles']['elements'][ $element ] ) || ! array_key_exists( $element, static::ELEMENTS ) ) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for not being clear; it's still early morning for me ☕

I mean - empty( static::ELEMENTS[ $element ] )

The isset and empty don't work as you expect with class constants in PHP 5.6.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah great. I knew about isset, but TIL about empty. Thanks a lot for the nudge.

Updated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick follow-up.

continue;
}

Expand Down