| 1 |
<?php |
| 2 |
namespace ABlocksThemeBuilder\Compatibility; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
use ABlocksThemeBuilder\AbstractCompatibilityBase; |
| 9 |
|
| 10 |
class Astra extends AbstractCompatibilityBase { |
| 11 |
protected $header_hook = 'astra_header'; |
| 12 |
protected $footer_hook = 'astra_footer'; |
| 13 |
protected $before_footer_hook = 'astra_footer_before'; |
| 14 |
protected $enabled_header; |
| 15 |
protected $enabled_before_footer; |
| 16 |
protected $enabled_footer; |
| 17 |
|
| 18 |
public function init() { |
| 19 |
$this->enabled_header = $this->enabled_header(); |
| 20 |
// Header |
| 21 |
if ( $this->enabled_header ) { |
| 22 |
add_action( 'template_redirect', [ $this, 'astra_setup_header' ], 10 ); |
| 23 |
add_action( $this->header_hook, [ $this, 'render_header' ] ); |
| 24 |
} |
| 25 |
|
| 26 |
// Footer |
| 27 |
$this->enabled_footer = $this->enabled_footer(); |
| 28 |
$this->enabled_before_footer = $this->enabled_before_footer(); |
| 29 |
|
| 30 |
if ( $this->enabled_footer || $this->enabled_before_footer ) { |
| 31 |
add_action( 'template_redirect', [ $this, 'astra_setup_footer' ], 10 ); |
| 32 |
} |
| 33 |
|
| 34 |
if ( $this->enabled_before_footer ) { |
| 35 |
add_action( $this->before_footer_hook, [ $this, 'render_before_footer' ] ); |
| 36 |
} |
| 37 |
|
| 38 |
if ( $this->enabled_footer ) { |
| 39 |
add_action( $this->footer_hook, [ $this, 'render_footer' ] ); |
| 40 |
} |
| 41 |
|
| 42 |
do_action('ablocks_theme_builder_after_dispatch', [ |
| 43 |
'header' => $this->enabled_header, |
| 44 |
'before_footer' => $this->enabled_before_footer, |
| 45 |
'footer' => $this->enabled_footer, |
| 46 |
]); |
| 47 |
} |
| 48 |
|
| 49 |
public function astra_setup_header() { |
| 50 |
remove_action( 'astra_header', 'astra_header_markup' ); |
| 51 |
|
| 52 |
// Remove the new header builder action. |
| 53 |
if ( class_exists( 'Astra_Builder_Helper' ) && \Astra_Builder_Helper::$is_header_footer_builder_active ) { |
| 54 |
remove_action( 'astra_header', [ \Astra_Builder_Header::get_instance(), 'prepare_header_builder_markup' ] ); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
public function astra_setup_footer() { |
| 59 |
remove_action( 'astra_footer', 'astra_footer_markup' ); |
| 60 |
|
| 61 |
// Remove the new footer builder action. |
| 62 |
if ( class_exists( 'Astra_Builder_Helper' ) && \Astra_Builder_Helper::$is_header_footer_builder_active ) { |
| 63 |
remove_action( 'astra_footer', [ \Astra_Builder_Footer::get_instance(), 'footer_markup' ] ); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
public function render_header() { |
| 68 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 69 |
echo $this->get_rendered_block_content_by_id( $this->get_settings( 'header' ) ); |
| 70 |
} |
| 71 |
|
| 72 |
public function render_footer() { |
| 73 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 74 |
echo $this->get_rendered_block_content_by_id( $this->get_settings( 'footer' ) ); |
| 75 |
} |
| 76 |
|
| 77 |
public function render_before_footer() { |
| 78 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 79 |
echo $this->get_rendered_block_content_by_id( $this->get_settings( 'before-footer' ) ); |
| 80 |
} |
| 81 |
} |
| 82 |
|