PluginProbe
Gutenberg / 23.2.0
Gutenberg v23.2.0
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 / spacing.php
lib/block-supports
anchor.php 1.4 KB 7 months ago aria-label.php 1.6 KB 6 months ago background.php 4.6 KB 5 months ago block-style-variations.php 10.3 KB 7 months ago block-visibility.php 5.4 KB 5 months ago border.php 6.0 KB 1 year ago colors.php 5.7 KB 5 months ago custom-css.php 8.6 KB 4 months ago dimensions.php 5.4 KB 4 months ago duotone.php 12.3 KB 5 months ago elements.php 8.8 KB 7 months ago layout.php 45.7 KB 4 months ago position.php 4.2 KB 2 years ago settings.php 4.5 KB 1 year ago shadow.php 2.0 KB 2 years ago spacing.php 2.6 KB 7 months ago typography.php 27.5 KB 6 months ago

spacing.php in Gutenberg 23.2.0, at lib/block-supports/spacing.php

84 lines 2.6 KB Raw Download Zip
1 <?php
2 /**
3 * Spacing block support flag.
4 *
5 * For backwards compatibility with core, this remains separate to the
6 * dimensions.php block support despite both belonging under a single panel in
7 * the editor.
8 *
9 * @package gutenberg
10 */
11
12 /**
13 * Registers the style block attribute for block types that support it.
14 *
15 * @param WP_Block_Type $block_type Block Type.
16 */
17 function gutenberg_register_spacing_support( $block_type ) {
18 $has_spacing_support = block_has_support( $block_type, array( 'spacing' ), false );
19
20 // Setup attributes and styles within that if needed.
21 if ( ! $block_type->attributes ) {
22 $block_type->attributes = array();
23 }
24
25 if ( $has_spacing_support && ! array_key_exists( 'style', $block_type->attributes ) ) {
26 $block_type->attributes['style'] = array(
27 'type' => 'object',
28 );
29 }
30 }
31
32 /**
33 * Add CSS classes for block spacing 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 spacing CSS classes and inline styles.
40 */
41 function gutenberg_apply_spacing_support( $block_type, $block_attributes ) {
42 if ( wp_should_skip_block_supports_serialization( $block_type, 'spacing' ) ) {
43 return array();
44 }
45
46 $attributes = array();
47 $has_padding_support = block_has_support( $block_type, array( 'spacing', 'padding' ), false );
48 $has_margin_support = block_has_support( $block_type, array( 'spacing', 'margin' ), false );
49 $block_styles = $block_attributes['style'] ?? null;
50
51 if ( ! $block_styles ) {
52 return $attributes;
53 }
54
55 $skip_padding = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'padding' );
56 $skip_margin = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'margin' );
57 $spacing_block_styles = array(
58 'padding' => null,
59 'margin' => null,
60 );
61 if ( $has_padding_support && ! $skip_padding ) {
62 $spacing_block_styles['padding'] = $block_styles['spacing']['padding'] ?? null;
63 }
64 if ( $has_margin_support && ! $skip_margin ) {
65 $spacing_block_styles['margin'] = $block_styles['spacing']['margin'] ?? null;
66 }
67 $styles = gutenberg_style_engine_get_styles( array( 'spacing' => $spacing_block_styles ) );
68
69 if ( ! empty( $styles['css'] ) ) {
70 $attributes['style'] = $styles['css'];
71 }
72
73 return $attributes;
74 }
75
76 // Register the block support.
77 WP_Block_Supports::get_instance()->register(
78 'spacing',
79 array(
80 'register_attribute' => 'gutenberg_register_spacing_support',
81 'apply' => 'gutenberg_apply_spacing_support',
82 )
83 );
84