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

git-svn-id: https://develop.svn.wordpress.org/trunk@56742 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris
2023-09-29 10:18:05 +00:00
parent a80165b78f
commit 71080fa580
4 changed files with 5 additions and 5 deletions

View File

@@ -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;

View File

@@ -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 ||

View File

@@ -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();
}

View File

@@ -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 ) {