From e74a3bfdb05c5086d2267efed9baef6fe65deaff Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Fri, 29 Sep 2023 10:20:30 +0000 Subject: [PATCH] Editor: Replace property_exists calls in block related functions with instanceof Replace calls to `property_exists` with `instanceof WP_Block_Type` in block related functions. This change not only improves type safety but also enhances performance. Follow on from [56678] and [56677]. Props gziolo, aristath, aaronrobertshaw, spacedmonkey. Fixes #59453 Built from https://develop.svn.wordpress.org/trunk@56742 git-svn-id: http://core.svn.wordpress.org/trunk@56254 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-supports/border.php | 2 +- wp-includes/block-supports/colors.php | 2 +- wp-includes/block-supports/typography.php | 4 ++-- wp-includes/class-wp-block-supports.php | 2 +- wp-includes/version.php | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wp-includes/block-supports/border.php b/wp-includes/block-supports/border.php index bb81e88134..a11c099d9e 100644 --- a/wp-includes/block-supports/border.php +++ b/wp-includes/block-supports/border.php @@ -152,7 +152,7 @@ function wp_apply_border_support( $block_type, $block_attributes ) { */ function wp_has_border_feature_support( $block_type, $feature, $default_value = false ) { // Check if all border support features have been opted into via `"__experimentalBorder": true`. - if ( property_exists( $block_type, 'supports' ) ) { + if ( $block_type instanceof WP_Block_Type ) { $block_type_supports_border = isset( $block_type->supports['__experimentalBorder'] ) ? $block_type->supports['__experimentalBorder'] : $default_value; diff --git a/wp-includes/block-supports/colors.php b/wp-includes/block-supports/colors.php index 053ec239dc..f14b718b88 100644 --- a/wp-includes/block-supports/colors.php +++ b/wp-includes/block-supports/colors.php @@ -17,7 +17,7 @@ */ function wp_register_colors_support( $block_type ) { $color_support = false; - if ( property_exists( $block_type, 'supports' ) ) { + if ( $block_type instanceof WP_Block_Type ) { $color_support = isset( $block_type->supports['color'] ) ? $block_type->supports['color'] : false; } $has_text_colors_support = true === $color_support || diff --git a/wp-includes/block-supports/typography.php b/wp-includes/block-supports/typography.php index 2358d304c4..bccde4f5c0 100644 --- a/wp-includes/block-supports/typography.php +++ b/wp-includes/block-supports/typography.php @@ -16,7 +16,7 @@ * @param WP_Block_Type $block_type Block Type. */ function wp_register_typography_support( $block_type ) { - if ( ! property_exists( $block_type, 'supports' ) ) { + if ( ! ( $block_type instanceof WP_Block_Type ) ) { return; } @@ -85,7 +85,7 @@ function wp_register_typography_support( $block_type ) { * @return array Typography CSS classes and inline styles. */ function wp_apply_typography_support( $block_type, $block_attributes ) { - if ( ! property_exists( $block_type, 'supports' ) ) { + if ( ! ( $block_type instanceof WP_Block_Type ) ) { return array(); } diff --git a/wp-includes/class-wp-block-supports.php b/wp-includes/class-wp-block-supports.php index ee2791dd17..afc011803b 100644 --- a/wp-includes/class-wp-block-supports.php +++ b/wp-includes/class-wp-block-supports.php @@ -142,7 +142,7 @@ class WP_Block_Supports { $block_registry = WP_Block_Type_Registry::get_instance(); $registered_block_types = $block_registry->get_all_registered(); foreach ( $registered_block_types as $block_type ) { - if ( ! property_exists( $block_type, 'supports' ) ) { + if ( ! ( $block_type instanceof WP_Block_Type ) ) { continue; } if ( ! $block_type->attributes ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 85bc18bb7e..ced110f7d7 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-beta1-56741'; +$wp_version = '6.4-beta1-56742'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.