PluginProbe
Getwid – Gutenberg Blocks / 3.0.2
Getwid – Gutenberg Blocks v3.0.2
3.0.2 3.0.1 3.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 trunk 1.8.7 1.9.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9
getwid / includes / blocks / abstract-block.php

abstract-block.php in Getwid – Gutenberg Blocks 3.0.2, at includes/blocks/abstract-block.php

106 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Getwid\Blocks;
4
5 abstract class AbstractBlock {
6
7 protected $block_name;
8
9 public function __construct( $block_name ) {
10
11 $this->block_name = $block_name;
12
13 if ( $this->is_disabled() ) {
14
15 // https://developer.wordpress.org/reference/functions/render_block/
16 add_filter( 'pre_render_block', array( $this, 'pre_render_block' ), 10, 2 );
17 }
18 }
19
20 /**
21 * Assets optimization. Currently in Beta.
22 * @since 1.5.3
23 */
24 public function has_block() {
25
26 /**
27 * has_block doesn't return true when a block is inside a reusable block
28 * https://github.com/WordPress/gutenberg/issues/18272
29 */
30
31 $has_block = has_block( $this->block_name );
32
33 /**
34 * Determines whether a $post contains a specific block.
35 */
36 return apply_filters( 'getwid/blocks/has_block', $has_block, $this->block_name );
37 }
38
39 public function get_block_name() {
40 return $this->block_name;
41 }
42
43 public function get_label() {
44 return $this->block_name;
45 }
46
47 public function get_disabled_option_key() {
48 return $this->block_name . '::disabled';
49 }
50
51 public function is_disabled() {
52
53 $disabled = rest_sanitize_boolean( get_option( $this->get_disabled_option_key(), false ) );
54
55 getwid_maybe_add_option( $this->get_disabled_option_key(), false, true );
56
57 return apply_filters( 'getwid/blocks/is_disabled', $disabled, $this->block_name );
58 }
59
60 public function is_enabled() {
61
62 return ! $this->is_disabled();
63 }
64
65 public function can_be_disabled() {
66 return true;
67 }
68
69 public function pre_render_block( $block_content, $block ) {
70
71 if ( $block['blockName'] === $this->block_name ) {
72
73 $block_content = '<!-- ' . esc_html( $block['blockName'] ) . ' block is disabled -->' . PHP_EOL;
74
75 if ( current_user_can( 'manage_options' ) ) {
76 $block_content .= '<p>';
77 $block_content .= sprintf(
78 // translators: %1$s is a block name, %2$s is a link
79 __( '%1$s block is disabled in plugin settings. <a href="%2$s">Manage Blocks</a>', 'getwid' ),
80 esc_html( $this->get_label() ),
81 esc_url( getwid()->settingsPage()->getTabUrl( 'blocks' ) )
82 );
83 $block_content .= '</p>';
84 }
85 }
86
87 return $block_content;
88 }
89
90 protected function validate_heading_html_tag( $tag ) {
91
92 $allowed_tags = array(
93 'h1',
94 'h2',
95 'h3',
96 'h4',
97 'h5',
98 'h6',
99 'span',
100 'p',
101 );
102
103 return in_array( strtolower( $tag ), $allowed_tags ) ? $tag : 'span';
104 }
105 }
106