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 |
* Generated classname block support flag. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @since 5.6.0 |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
10 |
* Gets the generated classname from a given block name. |
18 | 11 |
* |
12 |
* @since 5.6.0 |
|
13 |
* |
|
14 |
* @access private |
|
15 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
16 |
* @param string $block_name Block Name. |
18 | 17 |
* @return string Generated classname. |
18 |
*/ |
|
19 |
function wp_get_block_default_classname( $block_name ) { |
|
20 |
// Generated HTML classes for blocks follow the `wp-block-{name}` nomenclature. |
|
21 |
// Blocks provided by WordPress drop the prefixes 'core/' or 'core-' (historically used in 'core-embed/'). |
|
22 |
$classname = 'wp-block-' . preg_replace( |
|
23 |
'/^core-/', |
|
24 |
'', |
|
25 |
str_replace( '/', '-', $block_name ) |
|
26 |
); |
|
27 |
||
28 |
/** |
|
29 |
* Filters the default block className for server rendered blocks. |
|
30 |
* |
|
31 |
* @since 5.6.0 |
|
32 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
33 |
* @param string $class_name The current applied classname. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
34 |
* @param string $block_name The block name. |
18 | 35 |
*/ |
36 |
$classname = apply_filters( 'block_default_classname', $classname, $block_name ); |
|
37 |
||
38 |
return $classname; |
|
39 |
} |
|
40 |
||
41 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
42 |
* Adds the generated classnames to the output. |
18 | 43 |
* |
44 |
* @since 5.6.0 |
|
45 |
* |
|
46 |
* @access private |
|
47 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
48 |
* @param WP_Block_Type $block_type Block Type. |
18 | 49 |
* @return array Block CSS classes and inline styles. |
50 |
*/ |
|
51 |
function wp_apply_generated_classname_support( $block_type ) { |
|
52 |
$attributes = array(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
18
diff
changeset
|
53 |
$has_generated_classname_support = block_has_support( $block_type, 'className', true ); |
18 | 54 |
if ( $has_generated_classname_support ) { |
55 |
$block_classname = wp_get_block_default_classname( $block_type->name ); |
|
56 |
||
57 |
if ( $block_classname ) { |
|
58 |
$attributes['class'] = $block_classname; |
|
59 |
} |
|
60 |
} |
|
61 |
||
62 |
return $attributes; |
|
63 |
} |
|
64 |
||
65 |
// Register the block support. |
|
66 |
WP_Block_Supports::get_instance()->register( |
|
67 |
'generated-classname', |
|
68 |
array( |
|
69 |
'apply' => 'wp_apply_generated_classname_support', |
|
70 |
) |
|
71 |
); |