| 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 |
|
| 15 |
public function init() { |
| 16 |
// Header |
| 17 |
if ( $this->enabled_header() ) { |
| 18 |
add_action( 'template_redirect', [ $this, 'astra_setup_header' ], 10 ); |
| 19 |
add_action( $this->header_hook, [ $this, 'render_header' ] ); |
| 20 |
} |
| 21 |
|
| 22 |
// Footer |
| 23 |
$enabled_footer = $this->enabled_footer(); |
| 24 |
$enabled_before_footer = $this->enabled_before_footer(); |
| 25 |
if ( $enabled_footer || $enabled_before_footer ) { |
| 26 |
add_action( 'template_redirect', [ $this, 'astra_setup_footer' ], 10 ); |
| 27 |
} |
| 28 |
|
| 29 |
if ( $this->enabled_before_footer() ) { |
| 30 |
add_action( $this->before_footer_hook, [ $this, 'render_before_footer' ] ); |
| 31 |
} |
| 32 |
|
| 33 |
if ( $this->enabled_footer() ) { |
| 34 |
add_action( $this->footer_hook, [ $this, 'render_footer' ] ); |
| 35 |
} |
| 36 |
|
| 37 |
} |
| 38 |
|
| 39 |
public function astra_setup_header() { |
| 40 |
remove_action( 'astra_header', 'astra_header_markup' ); |
| 41 |
|
| 42 |
// Remove the new header builder action. |
| 43 |
if ( class_exists( 'Astra_Builder_Helper' ) && \Astra_Builder_Helper::$is_header_footer_builder_active ) { |
| 44 |
remove_action( 'astra_header', [ \Astra_Builder_Header::get_instance(), 'prepare_header_builder_markup' ] ); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
public function astra_setup_footer() { |
| 49 |
remove_action( 'astra_footer', 'astra_footer_markup' ); |
| 50 |
|
| 51 |
// Remove the new footer builder action. |
| 52 |
if ( class_exists( 'Astra_Builder_Helper' ) && \Astra_Builder_Helper::$is_header_footer_builder_active ) { |
| 53 |
remove_action( 'astra_footer', [ \Astra_Builder_Footer::get_instance(), 'footer_markup' ] ); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
public function render_header() { |
| 58 |
echo $this->get_rendered_block_content_by_id( $this->get_settings( 'header' ) ); |
| 59 |
} |
| 60 |
|
| 61 |
public function render_footer() { |
| 62 |
echo $this->get_rendered_block_content_by_id( $this->get_settings( 'footer' ) ); |
| 63 |
} |
| 64 |
|
| 65 |
public function render_before_footer() { |
| 66 |
echo $this->get_rendered_block_content_by_id( $this->get_settings( 'before-footer' ) ); |
| 67 |
} |
| 68 |
} |
| 69 |
|