| @@ -1,8 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace ABlocks\Blocks\ModalPanel; |
| 4 | 4 | |
| 5 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | + exit; | |
| 7 | +} | |
| 8 | + | |
| 5 | 9 | use ABlocks\Classes\BlockBaseAbstract; |
| 6 | 10 | use ABlocks\Classes\CssGenerator; |
| 7 | 11 | |
| 8 | 12 | class Block extends BlockBaseAbstract { |
| @@ -8,11 +12,27 @@ | ||
| 8 | 12 | class Block extends BlockBaseAbstract { |
| 9 | 13 | protected $parent_block_name = 'modal'; |
| 10 | 14 | protected $block_name = 'modal-panel'; |
| 11 | 15 | |
| 16 | + public function __construct() { | |
| 17 | + parent::__construct(); | |
| 18 | + add_filter( 'ablocks/get_render_block_content', [ $this, 'render_static_block_content' ], 10, 3 ); | |
| 19 | + } | |
| 20 | + | |
| 12 | 21 | public function build_css( $attributes ) { |
| 13 | 22 | $css_generator = new CssGenerator( $attributes ); |
| 14 | 23 | return $css_generator->generate_css(); |
| 24 | + } | |
| 25 | + | |
| 26 | + public function render_static_block_content( $content, $attributes, $block_instance ) { | |
| 27 | + if ( $block_instance->name === $this->namespace . '/' . $this->block_name ) { | |
| 28 | + return preg_replace( | |
| 29 | + '/<div\s+class="ablocks-block-modal---panel-wrap"(?![^>]*style=)/i', | |
| 30 | + '<div class="ablocks-block-modal---panel-wrap" style="opacity:0;visibility:hidden;"', | |
| 31 | + $content | |
| 32 | + ); | |
| 33 | + } | |
| 34 | + return $content; | |
| 15 | 35 | } |
| 16 | 36 | |
| 17 | 37 | |
| 18 | 38 | } |