Skip to content
Prev Previous commit
Next Next commit
Re-add gutenberg_register_anchor_support() function
  • Loading branch information
t-hamano committed Mar 28, 2023
commit 64be27289769133c1b7050e2b928c9a0d9f24bd6
25 changes: 24 additions & 1 deletion lib/block-supports/anchor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@
* @package gutenberg
*/

/**
* Registers the anchor block attribute for block types that support it.
*
* @param WP_Block_Type $block_type Block Type.
*/
function gutenberg_register_anchor_support( $block_type ) {
$has_anchor_support = _wp_array_get( $block_type->supports, array( 'anchor' ), true );
if ( ! $has_anchor_support ) {
return;
}

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

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

/**
* Add the anchor to the output.
*
Expand Down Expand Up @@ -39,6 +61,7 @@ function gutenberg_apply_anchor_support( $block_type, $block_attributes ) {
WP_Block_Supports::get_instance()->register(
'anchor',
array(
'apply' => 'gutenberg_apply_anchor_support',
'register_attribute' => 'gutenberg_register_anchor_support',
'apply' => 'gutenberg_apply_anchor_support',
)
);