wp_apply_anchor_support()WP 7.0.0

Add the anchor id to the output.

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

No Hooks.

Returns

Array. string> Attributes with block anchor id.

Usage

wp_apply_anchor_support( $block_type, $block_attributes ): array;
$block_type(WP_Block_Type) (required)
Block Type.
$block_attributes(array) (required)
.

Changelog

Since 7.0.0 Introduced.

wp_apply_anchor_support() code WP 7.0

function wp_apply_anchor_support( WP_Block_Type $block_type, array $block_attributes ): array {
	if ( empty( $block_attributes ) ) {
		return array();
	}

	if ( ! block_has_support( $block_type, array( 'anchor' ) ) ) {
		return array();
	}

	if ( ! isset( $block_attributes['anchor'] ) || ! is_string( $block_attributes['anchor'] ) || '' === $block_attributes['anchor'] ) {
		return array();
	}

	return array( 'id' => $block_attributes['anchor'] );
}