author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
18 | 1 |
<?php |
2 |
/** |
|
3 |
* Custom classname block support flag. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @since 5.6.0 |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Registers the custom classname block attribute for block types that support it. |
|
11 |
* |
|
12 |
* @since 5.6.0 |
|
13 |
* @access private |
|
14 |
* |
|
15 |
* @param WP_Block_Type $block_type Block Type. |
|
16 |
*/ |
|
17 |
function wp_register_custom_classname_support( $block_type ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
18 |
$has_custom_classname_support = block_has_support( $block_type, 'customClassName', true ); |
18 | 19 |
|
20 |
if ( $has_custom_classname_support ) { |
|
21 |
if ( ! $block_type->attributes ) { |
|
22 |
$block_type->attributes = array(); |
|
23 |
} |
|
24 |
||
25 |
if ( ! array_key_exists( 'className', $block_type->attributes ) ) { |
|
26 |
$block_type->attributes['className'] = array( |
|
27 |
'type' => 'string', |
|
28 |
); |
|
29 |
} |
|
30 |
} |
|
31 |
} |
|
32 |
||
33 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
34 |
* Adds the custom classnames to the output. |
18 | 35 |
* |
36 |
* @since 5.6.0 |
|
37 |
* @access private |
|
38 |
* |
|
39 |
* @param WP_Block_Type $block_type Block Type. |
|
40 |
* @param array $block_attributes Block attributes. |
|
41 |
* |
|
42 |
* @return array Block CSS classes and inline styles. |
|
43 |
*/ |
|
44 |
function wp_apply_custom_classname_support( $block_type, $block_attributes ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
45 |
$has_custom_classname_support = block_has_support( $block_type, 'customClassName', true ); |
18 | 46 |
$attributes = array(); |
47 |
if ( $has_custom_classname_support ) { |
|
48 |
$has_custom_classnames = array_key_exists( 'className', $block_attributes ); |
|
49 |
||
50 |
if ( $has_custom_classnames ) { |
|
51 |
$attributes['class'] = $block_attributes['className']; |
|
52 |
} |
|
53 |
} |
|
54 |
||
55 |
return $attributes; |
|
56 |
} |
|
57 |
||
58 |
// Register the block support. |
|
59 |
WP_Block_Supports::get_instance()->register( |
|
60 |
'custom-classname', |
|
61 |
array( |
|
62 |
'register_attribute' => 'wp_register_custom_classname_support', |
|
63 |
'apply' => 'wp_apply_custom_classname_support', |
|
64 |
) |
|
65 |
); |