PluginProbe ʕ •ᴥ•ʔ
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More / trunk
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More vtrunk
4.1.0 4.0.9 4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 trunk 1.0.0 2.0.0 2.0.1 2.0.2 2.0.3 3.0 3.0.1 3.0.2 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.2.0 3.2.1 3.2.2 3.2.4 3.2.5 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.4.5 3.4.6 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1
superb-blocks / src / gutenberg / class-gutenberg-z-index-controller.php
superb-blocks / src / gutenberg Last commit date
block-api 2 weeks ago form 1 week ago import 2 weeks ago popup 2 weeks ago templates 2 weeks ago class-gutenberg-block-styles.php 2 weeks ago class-gutenberg-cache-util.php 2 weeks ago class-gutenberg-conditions-controller.php 2 weeks ago class-gutenberg-controller.php 2 weeks ago class-gutenberg-dynamic-content-controller.php 2 weeks ago class-gutenberg-enhancements-controller.php 1 week ago class-gutenberg-social-icons-controller.php 2 weeks ago class-gutenberg-sticky-controller.php 2 weeks ago class-gutenberg-z-index-controller.php 2 weeks ago
class-gutenberg-z-index-controller.php
61 lines
1 <?php
2
3 namespace SuperbAddons\Gutenberg\Controllers;
4
5 defined('ABSPATH') || exit();
6
7 use WP_HTML_Tag_Processor;
8
9 class GutenbergZIndexController
10 {
11 const Z_INDEX_MIN = -100;
12 const Z_INDEX_MAX = 999;
13
14 public static function Initialize()
15 {
16 add_filter('render_block', array(__CLASS__, 'FilterZIndexRender'), 9, 2);
17 }
18
19 public static function FilterZIndexRender($block_content, $block)
20 {
21 if (empty($block_content)) {
22 return $block_content;
23 }
24
25 $attrs = isset($block['attrs']) && is_array($block['attrs']) ? $block['attrs'] : array();
26 if (!isset($attrs['spbaddZIndex']) || !is_numeric($attrs['spbaddZIndex'])) {
27 return $block_content;
28 }
29
30 $zindex = intval($attrs['spbaddZIndex']);
31 if ($zindex < self::Z_INDEX_MIN) {
32 $zindex = self::Z_INDEX_MIN;
33 } elseif ($zindex > self::Z_INDEX_MAX) {
34 $zindex = self::Z_INDEX_MAX;
35 }
36
37 $processor = new WP_HTML_Tag_Processor($block_content);
38 if (!$processor->next_tag()) {
39 return $block_content;
40 }
41
42 $existing_style = $processor->get_attribute('style');
43 $existing_style = is_string($existing_style) ? $existing_style : '';
44 $existing_style_lower = strtolower($existing_style);
45
46 $addition = 'z-index:' . $zindex . ';';
47 // z-index only applies to positioned elements. Add position:relative as a
48 // safe default when the block hasn't already set position explicitly.
49 if (strpos($existing_style_lower, 'position:') === false) {
50 $addition .= 'position:relative;';
51 }
52
53 if ($existing_style !== '' && substr($existing_style, -1) !== ';') {
54 $existing_style .= ';';
55 }
56 $processor->set_attribute('style', $existing_style . $addition);
57
58 return $processor->get_updated_html();
59 }
60 }
61