5 * @package WordPress |
5 * @package WordPress |
6 * @since 5.6.0 |
6 * @since 5.6.0 |
7 */ |
7 */ |
8 |
8 |
9 /** |
9 /** |
10 * Get the generated classname from a given block name. |
10 * Gets the generated classname from a given block name. |
11 * |
11 * |
12 * @since 5.6.0 |
12 * @since 5.6.0 |
13 * |
13 * |
14 * @access private |
14 * @access private |
15 * |
15 * |
16 * @param string $block_name Block Name. |
16 * @param string $block_name Block Name. |
17 * @return string Generated classname. |
17 * @return string Generated classname. |
18 */ |
18 */ |
19 function wp_get_block_default_classname( $block_name ) { |
19 function wp_get_block_default_classname( $block_name ) { |
20 // Generated HTML classes for blocks follow the `wp-block-{name}` nomenclature. |
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/'). |
21 // Blocks provided by WordPress drop the prefixes 'core/' or 'core-' (historically used in 'core-embed/'). |
28 /** |
28 /** |
29 * Filters the default block className for server rendered blocks. |
29 * Filters the default block className for server rendered blocks. |
30 * |
30 * |
31 * @since 5.6.0 |
31 * @since 5.6.0 |
32 * |
32 * |
33 * @param string $class_name The current applied classname. |
33 * @param string $class_name The current applied classname. |
34 * @param string $block_name The block name. |
34 * @param string $block_name The block name. |
35 */ |
35 */ |
36 $classname = apply_filters( 'block_default_classname', $classname, $block_name ); |
36 $classname = apply_filters( 'block_default_classname', $classname, $block_name ); |
37 |
37 |
38 return $classname; |
38 return $classname; |
39 } |
39 } |
40 |
40 |
41 /** |
41 /** |
42 * Add the generated classnames to the output. |
42 * Adds the generated classnames to the output. |
43 * |
43 * |
44 * @since 5.6.0 |
44 * @since 5.6.0 |
45 * |
45 * |
46 * @access private |
46 * @access private |
47 * |
47 * |
48 * @param WP_Block_Type $block_type Block Type. |
48 * @param WP_Block_Type $block_type Block Type. |
49 * |
|
50 * @return array Block CSS classes and inline styles. |
49 * @return array Block CSS classes and inline styles. |
51 */ |
50 */ |
52 function wp_apply_generated_classname_support( $block_type ) { |
51 function wp_apply_generated_classname_support( $block_type ) { |
53 $attributes = array(); |
52 $attributes = array(); |
54 $has_generated_classname_support = block_has_support( $block_type, array( 'className' ), true ); |
53 $has_generated_classname_support = block_has_support( $block_type, 'className', true ); |
55 if ( $has_generated_classname_support ) { |
54 if ( $has_generated_classname_support ) { |
56 $block_classname = wp_get_block_default_classname( $block_type->name ); |
55 $block_classname = wp_get_block_default_classname( $block_type->name ); |
57 |
56 |
58 if ( $block_classname ) { |
57 if ( $block_classname ) { |
59 $attributes['class'] = $block_classname; |
58 $attributes['class'] = $block_classname; |