author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
18 | 1 |
<?php |
2 |
/** |
|
3 |
* Align block support flag. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @since 5.6.0 |
|
7 |
*/ |
|
8 |
||
9 |
/** |
|
10 |
* Registers the align 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_alignment_support( $block_type ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
18 |
$has_align_support = block_has_support( $block_type, 'align', false ); |
18 | 19 |
if ( $has_align_support ) { |
20 |
if ( ! $block_type->attributes ) { |
|
21 |
$block_type->attributes = array(); |
|
22 |
} |
|
23 |
||
24 |
if ( ! array_key_exists( 'align', $block_type->attributes ) ) { |
|
25 |
$block_type->attributes['align'] = array( |
|
26 |
'type' => 'string', |
|
27 |
'enum' => array( 'left', 'center', 'right', 'wide', 'full', '' ), |
|
28 |
); |
|
29 |
} |
|
30 |
} |
|
31 |
} |
|
32 |
||
33 |
/** |
|
19 | 34 |
* Adds CSS classes for block alignment to the incoming attributes array. |
18 | 35 |
* This will be applied to the block markup in the front-end. |
36 |
* |
|
37 |
* @since 5.6.0 |
|
38 |
* @access private |
|
39 |
* |
|
40 |
* @param WP_Block_Type $block_type Block Type. |
|
41 |
* @param array $block_attributes Block attributes. |
|
42 |
* @return array Block alignment CSS classes and inline styles. |
|
43 |
*/ |
|
44 |
function wp_apply_alignment_support( $block_type, $block_attributes ) { |
|
45 |
$attributes = array(); |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
46 |
$has_align_support = block_has_support( $block_type, 'align', false ); |
18 | 47 |
if ( $has_align_support ) { |
48 |
$has_block_alignment = array_key_exists( 'align', $block_attributes ); |
|
49 |
||
50 |
if ( $has_block_alignment ) { |
|
51 |
$attributes['class'] = sprintf( 'align%s', $block_attributes['align'] ); |
|
52 |
} |
|
53 |
} |
|
54 |
||
55 |
return $attributes; |
|
56 |
} |
|
57 |
||
58 |
// Register the block support. |
|
59 |
WP_Block_Supports::get_instance()->register( |
|
60 |
'align', |
|
61 |
array( |
|
62 |
'register_attribute' => 'wp_register_alignment_support', |
|
63 |
'apply' => 'wp_apply_alignment_support', |
|
64 |
) |
|
65 |
); |