| 1 |
<?php |
| 2 |
namespace ABlocksThemeBuilder; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
use ABlocksThemeBuilder\Traits\RenderContent; |
| 9 |
|
| 10 |
abstract class AbstractCompatibilityBase { |
| 11 |
use RenderContent; |
| 12 |
protected $theme; |
| 13 |
protected $header_hook = 'ablocks/templates/theme_builder/header'; |
| 14 |
protected $footer_hook = 'ablocks/templates/theme_builder/footer'; |
| 15 |
protected $before_footer_hook = 'ablocks/templates/theme_builder/footer'; |
| 16 |
|
| 17 |
public function __construct( $theme ) { |
| 18 |
$this->theme = $theme; |
| 19 |
} |
| 20 |
|
| 21 |
public function init() { |
| 22 |
// Header |
| 23 |
if ( $this->enabled_header() ) { |
| 24 |
add_action( 'get_header', [ $this, 'header_template' ] ); |
| 25 |
add_action( $this->header_hook, [ $this, 'render_header' ] ); |
| 26 |
} |
| 27 |
|
| 28 |
// Footer |
| 29 |
$enabled_footer = $this->enabled_footer(); |
| 30 |
$enabled_before_footer = $this->enabled_before_footer(); |
| 31 |
if ( $enabled_footer || $enabled_before_footer ) { |
| 32 |
add_action( 'get_footer', [ $this, 'footer_template' ] ); |
| 33 |
} |
| 34 |
// Before Footer |
| 35 |
if ( $enabled_before_footer ) { |
| 36 |
add_action( $this->before_footer_hook, [ $this, 'render_before_footer' ], 5 ); |
| 37 |
} |
| 38 |
if ( $enabled_footer ) { |
| 39 |
add_action( $this->footer_hook, [ $this, 'render_footer' ] ); |
| 40 |
} |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
public function enabled_header() { |
| 45 |
return $this->get_settings( 'header' ); |
| 46 |
} |
| 47 |
|
| 48 |
public function enabled_footer() { |
| 49 |
return $this->get_settings( 'footer' ); |
| 50 |
} |
| 51 |
|
| 52 |
public function enabled_before_footer() { |
| 53 |
return $this->get_settings( 'before-footer' ); |
| 54 |
} |
| 55 |
|
| 56 |
public function get_settings( $type ) { |
| 57 |
return Helper::get_template_id( $type ); |
| 58 |
} |
| 59 |
|
| 60 |
public function header_template() { |
| 61 |
require ABLOCKS_ROOT_DIR_PATH . $this->get_template_path( 'header.php' ); |
| 62 |
$templates = []; |
| 63 |
$templates[] = 'header.php'; |
| 64 |
// Avoid running wp_head hooks again. |
| 65 |
remove_all_actions( 'wp_head' ); |
| 66 |
ob_start(); |
| 67 |
locate_template( $templates, true ); |
| 68 |
ob_get_clean(); |
| 69 |
} |
| 70 |
public function footer_template() { |
| 71 |
require ABLOCKS_ROOT_DIR_PATH . $this->get_template_path( 'footer.php' ); |
| 72 |
$templates = []; |
| 73 |
$templates[] = 'footer.php'; |
| 74 |
// Avoid running wp_footer hooks again. |
| 75 |
remove_all_actions( 'wp_footer' ); |
| 76 |
ob_start(); |
| 77 |
locate_template( $templates, true ); |
| 78 |
ob_get_clean(); |
| 79 |
} |
| 80 |
|
| 81 |
public function get_template_path( $suffix ) { |
| 82 |
$prefix = ! empty( $this->theme ) ? "{$this->theme}-" : ''; |
| 83 |
return "templates/theme-builder/{$prefix}{$suffix}"; |
| 84 |
} |
| 85 |
// To be overridden by specific themes |
| 86 |
abstract public function render_header(); |
| 87 |
abstract public function render_footer(); |
| 88 |
abstract public function render_before_footer(); |
| 89 |
} |
| 90 |
|