PluginProbe
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder / 2.9.0
aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder v2.9.0
2.13.0 2.13.1 2.12.0 2.11.1 2.11.0 2.10.0 2.9.0 2.7.4 2.7.5 2.7.6 2.7.7 2.8.0 2.8.1 2.9.1 trunk 1.0 1.0-beta1 1.0-beta2 1.0-beta3 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 All 80 releases
ablocks / addons / theme-builder / abstract-compatibility-base.php

abstract-compatibility-base.php in aBlocks – Gutenberg Blocks, User Dashboard Builder, Popup Builder, Form Builder & Animation Builder 2.9.0, at addons/theme-builder/abstract-compatibility-base.php

99 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 protected $enabled_header;
17 protected $enabled_before_footer;
18 protected $enabled_footer;
19
20 public function __construct( $theme ) {
21 $this->theme = $theme;
22 }
23
24 public function init() {
25 $this->enabled_header = $this->enabled_header();
26 // Header
27 if ( $this->enabled_header ) {
28 add_action( 'get_header', [ $this, 'header_template' ] );
29 add_action( $this->header_hook, [ $this, 'render_header' ] );
30 }
31
32 // Footer
33 $this->enabled_footer = $this->enabled_footer();
34 $this->enabled_before_footer = $this->enabled_before_footer();
35 if ( $this->enabled_footer || $this->enabled_before_footer ) {
36 add_action( 'get_footer', [ $this, 'footer_template' ] );
37 }
38 // Before Footer
39 if ( $this->enabled_before_footer ) {
40 add_action( $this->before_footer_hook, [ $this, 'render_before_footer' ], 5 );
41 }
42 if ( $this->enabled_footer ) {
43 add_action( $this->footer_hook, [ $this, 'render_footer' ] );
44 }
45
46 do_action('ablocks_theme_builder_after_dispatch', [
47 'header' => $this->enabled_header,
48 'before_footer' => $this->enabled_before_footer,
49 'footer' => $this->enabled_footer,
50 ]);
51 }
52
53 public function enabled_header() {
54 return $this->get_settings( 'header' );
55 }
56
57 public function enabled_footer() {
58 return $this->get_settings( 'footer' );
59 }
60
61 public function enabled_before_footer() {
62 return $this->get_settings( 'before-footer' );
63 }
64
65 public function get_settings( $type ) {
66 return Helper::get_template_id( $type );
67 }
68
69 public function header_template() {
70 require ABLOCKS_ROOT_DIR_PATH . $this->get_template_path( 'header.php' );
71 $templates = [];
72 $templates[] = 'header.php';
73 // Avoid running wp_head hooks again.
74 remove_all_actions( 'wp_head' );
75 ob_start();
76 locate_template( $templates, true );
77 ob_get_clean();
78 }
79 public function footer_template() {
80 require ABLOCKS_ROOT_DIR_PATH . $this->get_template_path( 'footer.php' );
81 $templates = [];
82 $templates[] = 'footer.php';
83 // Avoid running wp_footer hooks again.
84 remove_all_actions( 'wp_footer' );
85 ob_start();
86 locate_template( $templates, true );
87 ob_get_clean();
88 }
89
90 public function get_template_path( $suffix ) {
91 $prefix = ! empty( $this->theme ) ? "{$this->theme}-" : '';
92 return "templates/theme-builder/{$prefix}{$suffix}";
93 }
94 // To be overridden by specific themes
95 abstract public function render_header();
96 abstract public function render_footer();
97 abstract public function render_before_footer();
98 }
99