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 / shadow.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

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

80 lines 2.0 KB Raw Download Zip
1 <?php
2 /**
3 * Shadow block support flag.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Registers the style and shadow block attributes for block types that support it.
10 *
11 * @param WP_Block_Type $block_type Block Type.
12 */
13 function gutenberg_register_shadow_support( $block_type ) {
14 $has_shadow_support = block_has_support( $block_type, array( 'shadow' ), false );
15
16 if ( ! $has_shadow_support ) {
17 return;
18 }
19
20 if ( ! $block_type->attributes ) {
21 $block_type->attributes = array();
22 }
23
24 if ( $has_shadow_support && ! array_key_exists( 'style', $block_type->attributes ) ) {
25 $block_type->attributes['style'] = array(
26 'type' => 'object',
27 );
28 }
29
30 if ( $has_shadow_support && ! array_key_exists( 'shadow', $block_type->attributes ) ) {
31 $block_type->attributes['shadow'] = array(
32 'type' => 'string',
33 );
34 }
35 }
36
37 /**
38 * Add CSS classes and inline styles for shadow features to the incoming attributes array.
39 * This will be applied to the block markup in
40 * the front-end.
41 *
42 * @param WP_Block_Type $block_type Block type.
43 * @param array $block_attributes Block attributes.
44 *
45 * @return array Shadow CSS classes and inline styles.
46 */
47 function gutenberg_apply_shadow_support( $block_type, $block_attributes ) {
48 $has_shadow_support = block_has_support( $block_type, array( 'shadow' ), false );
49
50 if (
51 ! $has_shadow_support ||
52 wp_should_skip_block_supports_serialization( $block_type, 'shadow' )
53 ) {
54 return array();
55 }
56
57 $shadow_block_styles = array();
58
59 $custom_shadow = $block_attributes['style']['shadow'] ?? null;
60 $shadow_block_styles['shadow'] = $custom_shadow;
61
62 $attributes = array();
63 $styles = gutenberg_style_engine_get_styles( $shadow_block_styles );
64
65 if ( ! empty( $styles['css'] ) ) {
66 $attributes['style'] = $styles['css'];
67 }
68
69 return $attributes;
70 }
71
72 // Register the block support.
73 WP_Block_Supports::get_instance()->register(
74 'shadow',
75 array(
76 'register_attribute' => 'gutenberg_register_shadow_support',
77 'apply' => 'gutenberg_apply_shadow_support',
78 )
79 );
80