Make WordPress Core


Ignore:
Timestamp:
08/10/2023 04:47:00 PM (10 months ago)
Author:
flixos90
Message:

Editor: Simplify usage of block_has_support() function by supporting a string.

Most block feature checks are for a single feature string, and for such cases it is not intuitive to require an array for the $feature parameter of the block_has_support() function.

This changeset brings it in line with other functions like post_type_supports(), allowing to pass a string for the $feature. An array is still supported for more complex cases where support for sub-features needs to be determined. This change furthermore includes a very minor performance tweak by avoiding calls to the _wp_array_get() function if a single feature string is being checked for.

Props thekt12, nihar007, mukesh27, swissspidy.
Fixes #58532.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/layout.php

    r56055 r56382  
    203203 */
    204204function wp_register_layout_support( $block_type ) {
    205     $support_layout = block_has_support( $block_type, array( 'layout' ), false ) || block_has_support( $block_type, array( '__experimentalLayout' ), false );
     205    $support_layout = block_has_support( $block_type, 'layout', false ) || block_has_support( $block_type, '__experimentalLayout', false );
    206206    if ( $support_layout ) {
    207207        if ( ! $block_type->attributes ) {
     
    549549function wp_render_layout_support_flag( $block_content, $block ) {
    550550    $block_type       = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
    551     $support_layout   = block_has_support( $block_type, array( 'layout' ), false ) || block_has_support( $block_type, array( '__experimentalLayout' ), false );
     551    $support_layout   = block_has_support( $block_type, 'layout', false ) || block_has_support( $block_type, '__experimentalLayout', false );
    552552    $has_child_layout = isset( $block['attrs']['style']['layout']['selfStretch'] );
    553553
Note: See TracChangeset for help on using the changeset viewer.