PluginProbe
Gutenberg / 9.7.2
Gutenberg v9.7.2
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / lib / block-supports / align.php

align.php in Gutenberg 9.7.2, at lib/block-supports/align.php

66 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Align block support flag.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Registers the align block attribute for block types that support it.
10 *
11 * @param WP_Block_Type $block_type Block Type.
12 */
13 function gutenberg_register_alignment_support( $block_type ) {
14 $has_align_support = false;
15 if ( property_exists( $block_type, 'supports' ) ) {
16 $has_align_support = gutenberg_experimental_get( $block_type->supports, array( 'align' ), false );
17 }
18 if ( $has_align_support ) {
19 if ( ! $block_type->attributes ) {
20 $block_type->attributes = array();
21 }
22
23 if ( ! array_key_exists( 'align', $block_type->attributes ) ) {
24 $block_type->attributes['align'] = array(
25 'type' => 'string',
26 'enum' => array( 'left', 'center', 'right', 'wide', 'full', '' ),
27 );
28 }
29 }
30 }
31
32 /**
33 * Add CSS classes for block alignment to the incoming attributes array.
34 * This will be applied to the block markup in the front-end.
35 *
36 * @param WP_Block_Type $block_type Block Type.
37 * @param array $block_attributes Block attributes.
38 *
39 * @return array Block alignment CSS classes and inline styles.
40 */
41 function gutenberg_apply_alignment_support( $block_type, $block_attributes ) {
42 $attributes = array();
43 $has_align_support = false;
44 if ( property_exists( $block_type, 'supports' ) ) {
45 $has_align_support = gutenberg_experimental_get( $block_type->supports, array( 'align' ), false );
46 }
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' => 'gutenberg_register_alignment_support',
63 'apply' => 'gutenberg_apply_alignment_support',
64 )
65 );
66