| @@ -3,26 +3,26 @@ | ||
| 3 | 3 | namespace Getwid\Blocks; |
| 4 | 4 | |
| 5 | 5 | abstract class AbstractBlock { |
| 6 | 6 | |
| 7 | - private $blockName; | |
| 7 | + protected $block_name; | |
| 8 | 8 | |
| 9 | - public function __construct( $blockName ) { | |
| 9 | + public function __construct( $block_name ) { | |
| 10 | 10 | |
| 11 | - $this->blockName = $blockName; | |
| 11 | + $this->block_name = $block_name; | |
| 12 | 12 | |
| 13 | - if ( $this->isDisabled() ) { | |
| 13 | + if ( $this->is_disabled() ) { | |
| 14 | 14 | |
| 15 | 15 | // https://developer.wordpress.org/reference/functions/render_block/ |
| 16 | - add_filter( 'pre_render_block', [ $this, 'pre_render_block' ], 10, 2 ); | |
| 16 | + add_filter( 'pre_render_block', array( $this, 'pre_render_block' ), 10, 2 ); | |
| 17 | 17 | } |
| 18 | - } | |
| 18 | + } | |
| 19 | 19 | |
| 20 | 20 | /** |
| 21 | 21 | * Assets optimization. Currently in Beta. |
| 22 | 22 | * @since 1.5.3 |
| 23 | 23 | */ |
| 24 | - public function hasBlock() { | |
| 24 | + public function has_block() { | |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | 27 | * has_block doesn't return true when a block is inside a reusable block |
| 28 | 28 | * https://github.com/WordPress/gutenberg/issues/18272 |
| @@ -27,55 +27,59 @@ | ||
| 27 | 27 | * has_block doesn't return true when a block is inside a reusable block |
| 28 | 28 | * https://github.com/WordPress/gutenberg/issues/18272 |
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | - $has_block = has_block( $this->blockName ); | |
| 31 | + $has_block = has_block( $this->block_name ); | |
| 32 | 32 | |
| 33 | 33 | /** |
| 34 | 34 | * Determines whether a $post contains a specific block. |
| 35 | 35 | */ |
| 36 | - return apply_filters( 'getwid/blocks/has_block', $has_block, $this->blockName ); | |
| 36 | + return apply_filters( 'getwid/blocks/has_block', $has_block, $this->block_name ); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - public static function getBlockName() { | |
| 40 | - return static::$blockName; | |
| 39 | + public function get_block_name() { | |
| 40 | + return $this->block_name; | |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - public function getLabel() { | |
| 44 | - return static::$blockName; | |
| 43 | + public function get_label() { | |
| 44 | + return $this->block_name; | |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - public function getDisabledOptionKey() { | |
| 48 | - return $this->blockName . '::disabled'; | |
| 47 | + public function get_disabled_option_key() { | |
| 48 | + return $this->block_name . '::disabled'; | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - public function isDisabled() { | |
| 51 | + public function is_disabled() { | |
| 52 | 52 | |
| 53 | - $disabled = rest_sanitize_boolean( get_option( $this->getDisabledOptionKey(), false ) ); | |
| 53 | + $disabled = rest_sanitize_boolean( get_option( $this->get_disabled_option_key(), false ) ); | |
| 54 | 54 | |
| 55 | - getwid_maybe_add_option( $this->getDisabledOptionKey(), false, true ); | |
| 55 | + getwid_maybe_add_option( $this->get_disabled_option_key(), false, true ); | |
| 56 | 56 | |
| 57 | - return apply_filters( 'getwid/blocks/is_disabled', $disabled, $this->blockName ); | |
| 57 | + return apply_filters( 'getwid/blocks/is_disabled', $disabled, $this->block_name ); | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - public function isEnabled() { | |
| 60 | + public function is_enabled() { | |
| 61 | 61 | |
| 62 | - return ! $this->isDisabled(); | |
| 62 | + return ! $this->is_disabled(); | |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | + public function can_be_disabled() { | |
| 66 | + return true; | |
| 67 | + } | |
| 68 | + | |
| 65 | 69 | public function pre_render_block( $block_content, $block ) { |
| 66 | 70 | |
| 67 | - if ( $block['blockName'] === static::$blockName ) { | |
| 71 | + if ( $block['blockName'] === $this->block_name ) { | |
| 68 | 72 | |
| 69 | 73 | $block_content = '<!-- ' . esc_html( $block['blockName'] ) . ' block is disabled -->' . PHP_EOL; |
| 70 | 74 | |
| 71 | - if ( current_user_can('manage_options') ) { | |
| 75 | + if ( current_user_can( 'manage_options' ) ) { | |
| 72 | 76 | $block_content .= '<p>'; |
| 73 | - $block_content .= sprintf( | |
| 74 | - //translators: %1$s is a block name, %2$s is a link | |
| 75 | - __( '%1$s block is disabled in plugin settings. <a href="%2$s">Manage Blocks</a>', 'getwid'), | |
| 76 | - esc_html( $this->getLabel() ), | |
| 77 | - esc_url( getwid()->settingsPage()->getTabUrl('blocks') ) | |
| 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' ) ) | |
| 78 | 82 | ); |
| 79 | 83 | $block_content .= '</p>'; |
| 80 | 84 | } |
| 81 | 85 | } |
| @@ -82,9 +86,9 @@ | ||
| 82 | 86 | |
| 83 | 87 | return $block_content; |
| 84 | 88 | } |
| 85 | 89 | |
| 86 | - protected function validateHeadingHTMLTag( $tag ) { | |
| 90 | + protected function validate_heading_html_tag( $tag ) { | |
| 87 | 91 | |
| 88 | 92 | $allowed_tags = array( |
| 89 | 93 | 'h1', |
| 90 | 94 | 'h2', |