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
This commit is contained in:
spacedmonkey 2023-09-29 10:20:30 +00:00
parent 829bbf3605
commit e74a3bfdb0
5 changed files with 6 additions and 6 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 ) {

View File

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