block_has_support example

protected function get_layout_styles( $block_metadata ) {
        $block_rules = '';
        $block_type  = null;

        // Skip outputting layout styles if explicitly disabled.         if ( current_theme_supports( 'disable-layout-styles' ) ) {
            return $block_rules;
        }

        if ( isset( $block_metadata['name'] ) ) {
            $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_metadata['name'] );
            if ( ! block_has_support( $block_type, array( 'layout' ), false ) && ! block_has_support( $block_type, array( '__experimentalLayout' ), false ) ) {
                return $block_rules;
            }
        }

        $selector                 = isset( $block_metadata['selector'] ) ? $block_metadata['selector'] : '';
        $has_block_gap_support    = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null;
        $has_fallback_gap_support = ! $has_block_gap_support; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback gap styles support.         $node                     = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
        $layout_definitions       = wp_get_layout_definitions();
        $layout_selector_pattern  = '/^[a-zA-Z0-9\-\.\ *+>:\(\)]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, child combinator and pseudo class selectors.
        
function wp_register_dimensions_support( $block_type ) {
    // Setup attributes and styles within that if needed.     if ( ! $block_type->attributes ) {
        $block_type->attributes = array();
    }

    // Check for existing style attribute definition e.g. from block.json.     if ( array_key_exists( 'style', $block_type->attributes ) ) {
        return;
    }

    $has_dimensions_support = block_has_support( $block_type, array( 'dimensions' ), false );

    if ( $has_dimensions_support ) {
        $block_type->attributes['style'] = array(
            'type' => 'object',
        );
    }
}

/** * Adds CSS classes for block dimensions to the incoming attributes array. * This will be applied to the block markup in the front-end. * * @since 5.9.0 * @since 6.2.0 Added `minHeight` support. * @access private * * @param WP_Block_Type $block_type Block Type. * @param array $block_attributes Block attributes. * @return array Block dimensions CSS classes and inline styles. */

function wp_apply_generated_classname_support( $block_type ) {
    $attributes                      = array();
    $has_generated_classname_support = block_has_support( $block_type, array( 'className' ), true );
    if ( $has_generated_classname_support ) {
        $block_classname = wp_get_block_default_classname( $block_type->name );

        if ( $block_classname ) {
            $attributes['class'] = $block_classname;
        }
    }

    return $attributes;
}



/** * Registers the style block attribute for block types that support it. * * @since 6.2.0 * @access private * * @param WP_Block_Type $block_type Block Type. */
function wp_register_position_support( $block_type ) {
    $has_position_support = block_has_support( $block_type, array( 'position' ), false );

    // Set up attributes and styles within that if needed.     if ( ! $block_type->attributes ) {
        $block_type->attributes = array();
    }

    if ( $has_position_support && ! array_key_exists( 'style', $block_type->attributes ) ) {
        $block_type->attributes['style'] = array(
            'type' => 'object',
        );
    }
}


/** * Registers the align block attribute for block types that support it. * * @since 5.6.0 * @access private * * @param WP_Block_Type $block_type Block Type. */
function wp_register_alignment_support( $block_type ) {
    $has_align_support = block_has_support( $block_type, array( 'align' ), false );
    if ( $has_align_support ) {
        if ( ! $block_type->attributes ) {
            $block_type->attributes = array();
        }

        if ( ! array_key_exists( 'align', $block_type->attributes ) ) {
            $block_type->attributes['align'] = array(
                'type' => 'string',
                'enum' => array( 'left', 'center', 'right', 'wide', 'full', '' ),
            );
        }
    }
/** * Registers the layout block attribute for block types that support it. * * @since 5.8.0 * @since 6.3.0 Check for layout support via the `layout` key with fallback to `__experimentalLayout`. * @access private * * @param WP_Block_Type $block_type Block Type. */
function wp_register_layout_support( $block_type ) {
    $support_layout = block_has_support( $block_type, array( 'layout' ), false ) || block_has_support( $block_type, array( '__experimentalLayout' ), false );
    if ( $support_layout ) {
        if ( ! $block_type->attributes ) {
            $block_type->attributes = array();
        }

        if ( ! array_key_exists( 'layout', $block_type->attributes ) ) {
            $block_type->attributes['layout'] = array(
                'type' => 'object',
            );
        }
    }
}


/** * Registers the custom classname block attribute for block types that support it. * * @since 5.6.0 * @access private * * @param WP_Block_Type $block_type Block Type. */
function wp_register_custom_classname_support( $block_type ) {
    $has_custom_classname_support = block_has_support( $block_type, array( 'customClassName' ), true );

    if ( $has_custom_classname_support ) {
        if ( ! $block_type->attributes ) {
            $block_type->attributes = array();
        }

        if ( ! array_key_exists( 'className', $block_type->attributes ) ) {
            $block_type->attributes['className'] = array(
                'type' => 'string',
            );
        }
    }


/** * Registers the style and shadow block attributes for block types that support it. * * @since 6.3.0 * @access private * * @param WP_Block_Type $block_type Block Type. */
function wp_register_shadow_support( $block_type ) {
    $has_shadow_support = block_has_support( $block_type, array( 'shadow' ), false );

    if ( ! $has_shadow_support ) {
        return;
    }

    if ( ! $block_type->attributes ) {
        $block_type->attributes = array();
    }

    if ( array_key_exists( 'style', $block_type->attributes ) ) {
        $block_type->attributes['style'] = array(
            


/** * Registers the style block attribute for block types that support it. * * @since 5.8.0 * @access private * * @param WP_Block_Type $block_type Block Type. */
function wp_register_spacing_support( $block_type ) {
    $has_spacing_support = block_has_support( $block_type, array( 'spacing' ), false );

    // Setup attributes and styles within that if needed.     if ( ! $block_type->attributes ) {
        $block_type->attributes = array();
    }

    if ( $has_spacing_support && ! array_key_exists( 'style', $block_type->attributes ) ) {
        $block_type->attributes['style'] = array(
            'type' => 'object',
        );
    }
}

    public static function register_duotone_support( $block_type ) {
        /* * Previous `color.__experimentalDuotone` support flag is migrated * to `filter.duotone` via `block_type_metadata_settings` filter. */
        if ( block_has_support( $block_type, array( 'filter', 'duotone' ), null ) ) {
            if ( ! $block_type->attributes ) {
                $block_type->attributes = array();
            }

            if ( ! array_key_exists( 'style', $block_type->attributes ) ) {
                $block_type->attributes['style'] = array(
                    'type' => 'object',
                );
            }
        }
    }

    

function _wp_add_block_level_presets_class( $block_content$block ) {
    if ( ! $block_content ) {
        return $block_content;
    }

    // return early if the block doesn't have support for settings.     $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
    if ( ! block_has_support( $block_type, array( '__experimentalSettings' ), false ) ) {
        return $block_content;
    }

    // return early if no settings are found on the block attributes.     $block_settings = _wp_array_get( $block, array( 'attrs', 'settings' ), null );
    if ( empty( $block_settings ) ) {
        return $block_content;
    }

    // Like the layout hook this assumes the hook only applies to blocks with a single wrapper.     // Add the class name to the first element, presuming it's the wrapper, if it exists.

function wp_register_border_support( $block_type ) {
    // Setup attributes and styles within that if needed.     if ( ! $block_type->attributes ) {
        $block_type->attributes = array();
    }

    if ( block_has_support( $block_type, array( '__experimentalBorder' ) ) && ! array_key_exists( 'style', $block_type->attributes ) ) {
        $block_type->attributes['style'] = array(
            'type' => 'object',
        );
    }

    if ( wp_has_border_feature_support( $block_type, 'color' ) && ! array_key_exists( 'borderColor', $block_type->attributes ) ) {
        $block_type->attributes['borderColor'] = array(
            'type' => 'string',
        );
    }
}

Home | Imprint | This part of the site doesn't use cookies.