Skip to content

Commit

Permalink
Fix PHP 5.6 errors + added notes for the future
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Nov 3, 2022
1 parent 9254cb6 commit 52ae187
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,8 @@ class WP_Theme_JSON {
public static function get_element_class_name( $element ) {
$class_name = '';

if ( isset( static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES[ $element ] ) ) {
// Note: array_key_exists() should be replaced with an isset() check once WordPress drops support for PHP 5.6.
if ( array_key_exists( $element, static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES ) ) {
$class_name = static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES[ $element ];
}

Expand Down Expand Up @@ -630,7 +631,8 @@ protected static function sanitize( $input, $valid_block_names, $valid_element_n
foreach ( $valid_element_names as $element ) {
$schema_styles_elements[ $element ] = $styles_non_top_level;

if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] ) ) {
// Note: array_key_exists() should be replaced with an isset() check once WordPress drops support for PHP 5.6.
if ( array_key_exists( $element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) {
foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) {
$schema_styles_elements[ $element ][ $pseudo_selector ] = $styles_non_top_level;
}
Expand Down Expand Up @@ -1670,7 +1672,8 @@ protected static function compute_style_properties( $styles, $settings = array()
if ( is_array( $value_path ) ) {
$path_string = implode( '.', $value_path );
if (
isset( static::PROTECTED_PROPERTIES[ $path_string ] ) &&
// Note: array_key_exists() should be replaced with an isset() check once WordPress drops support for PHP 5.6.
array_key_exists( $path_string, static::PROTECTED_PROPERTIES ) &&
_wp_array_get( $settings, static::PROTECTED_PROPERTIES[ $path_string ], null ) === null
) {
continue;
Expand Down Expand Up @@ -1889,7 +1892,8 @@ protected static function get_style_nodes( $theme_json, $selectors = array() ) {
);

// Handle any pseudo selectors for the element.
if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] ) ) {
// Note: array_key_exists() should be replaced with an isset() check once WordPress drops support for PHP 5.6.
if ( array_key_exists( $element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) {
foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) {

if ( isset( $theme_json['styles']['elements'][ $element ][ $pseudo_selector ] ) ) {
Expand Down Expand Up @@ -1988,7 +1992,8 @@ private static function get_block_nodes( $theme_json ) {
);

// Handle any pseudo selectors for the element.
if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] ) ) {
// Note: array_key_exists() should be replaced with an isset() check once WordPress drops support for PHP 5.6.
if ( array_key_exists( $element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) {
foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) {
if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'][ $element ][ $pseudo_selector ] ) ) {
$nodes[] = array(
Expand Down Expand Up @@ -2067,7 +2072,8 @@ public function get_styles_for_block( $block_metadata ) {

$element_pseudo_allowed = array();

if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ] ) ) {
// Note: array_key_exists() should be replaced with an isset() check once WordPress drops support for PHP 5.6.
if ( array_key_exists( $current_element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) {
$element_pseudo_allowed = static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ];
}

Expand All @@ -2092,7 +2098,8 @@ function( $pseudo_selector ) use ( $selector ) {
* Otherwise just compute the styles for the default selector as normal.
*/
if ( $pseudo_selector && isset( $node[ $pseudo_selector ] ) &&
isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ] )
// Note: array_key_exists() should be replaced with an isset() check once WordPress drops support for PHP 5.6.
array_key_exists( $current_element, static::VALID_ELEMENT_PSEUDO_SELECTORS )
&& in_array( $pseudo_selector, static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ], true )
) {
$declarations = static::compute_style_properties( $node[ $pseudo_selector ], $settings, null, $this->theme_json, $selector, $use_root_padding );
Expand Down Expand Up @@ -2562,7 +2569,8 @@ public static function remove_insecure_properties( $theme_json ) {
* $output is stripped of pseudo selectors. Re-add and process them
* or insecure styles here.
*/
if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ] ) ) {
// Note: array_key_exists() should be replaced with an isset() check once WordPress drops support for PHP 5.6.
if ( array_key_exists( $current_element, static::VALID_ELEMENT_PSEUDO_SELECTORS ) ) {
foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $current_element ] as $pseudo_selector ) {
if ( isset( $input[ $pseudo_selector ] ) ) {
$output[ $pseudo_selector ] = static::remove_insecure_styles( $input[ $pseudo_selector ] );
Expand Down

0 comments on commit 52ae187

Please sign in to comment.