PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 3.1.0
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v3.1.0
4.9.2 4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / core / page-templates / hooks / base.php
shopengine / core / page-templates / hooks Last commit date
archive.php 3 years ago base-content.php 3 years ago base.php 3 years ago cart.php 3 years ago checkout.php 3 years ago shop.php 3 years ago single.php 3 years ago
base.php
246 lines
1 <?php
2
3 namespace ShopEngine\Core\Page_Templates\Hooks;
4
5 use Elementor\Core\Files\CSS\Post as Post_CSS;
6 use ShopEngine\Compatibility\Conflicts\Theme_Hooks;
7 use ShopEngine\Core\Builders\Templates;
8 use ShopEngine\Core\Template_Cpt;
9 use ShopEngine\Utils\Helper;
10
11 defined('ABSPATH') || exit;
12
13 abstract class Base {
14 protected $template_loaded = false;
15 protected $config;
16 protected $template_name = null;
17 protected $prod_tpl_id;
18 protected $tpl_loaded = false;
19
20 abstract protected function template_include_pre_condition(): bool;
21
22 /**
23 * Fires Before the_content()
24 *
25 * @return void
26 */
27 public function before_hooks() {}
28
29 /**
30 * Fires After the_content()
31 *
32 * @return void
33 */
34 public function after_hooks() {}
35
36 abstract public function init(): void;
37
38 public function __construct() {
39
40 if(!$this->template_include_pre_condition()) {
41 return;
42 }
43
44 add_filter('body_class', [$this, 'hook_body_class']);
45
46 $this->prod_tpl_id = $this->get_registered_template_id($this->get_page_type_option_slug());
47
48 //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- It's a fronted user part, not possible to verify nonce here
49 if(isset($_GET['elementor-preview'])) {
50 /**
51 * Remove checkout template extra markup;
52 */
53 remove_action('woocommerce_before_checkout_form', 'woocommerce_checkout_coupon_form', 10);
54 }
55
56 if(empty($this->prod_tpl_id) || !$this->is_template_active()) {
57 return;
58 }
59
60 if(\ShopEngine\Core\Builders\Action::edit_with($this->prod_tpl_id) == 'elementor' && !Helper::is_elementor_active()) {
61 return;
62 }
63
64 if(\ShopEngine\Core\Builders\Action::edit_with($this->prod_tpl_id) == 'gutenberg' && !did_action('shopengine-gutenberg-addon/before_loaded')) {
65 return;
66 }
67
68 Base_Content::instance()->set_tpl_data($this->prod_tpl_id, $this->get_page_type_option_slug());
69
70
71 $this->config = Templates::get_template_types()[$this->page_type];
72
73 add_filter('template_include', [$this, 'redirect_page_template'], 999);
74
75 add_action('wp_enqueue_scripts', [$this, 'enqueue_scripts'], 999);
76
77 add_action('shopengine/templates/elementor/content/before', [$this, 'theme_conflicts_in_widget']);
78 add_action('shopengine/builder/gutenberg/before-content', [$this, 'theme_conflicts_in_widget']);
79
80 $this->init();
81
82 /**
83 * This variable is used inside compatibility\conflicts\manifest.php file
84 */
85 global $is_used_shopengine_template;
86 $is_used_shopengine_template = true;
87 }
88
89 public function theme_conflicts_in_widget($template_type = null) {
90 if(!$template_type) $template_type = $this->page_type ;
91
92 if(in_array($template_type, ['shop', 'archive'])) {
93
94 Theme_Hooks::instance()->theme__conflicts__shop_and_archive();
95
96 } elseif(in_array($template_type, ['single'])) {
97
98 Theme_Hooks::instance()->theme__conflicts__single_page();
99
100 } elseif(in_array($template_type, ['cart'])) {
101
102 Theme_Hooks::instance()->theme_conflicts_cart_page();
103
104 } elseif(in_array($template_type, ['my_account'])) {
105
106 Theme_Hooks::instance()->theme_conflicts_my_account_page();
107
108 } elseif(in_array($template_type, ['empty_cart'])) {
109
110 Theme_Hooks::instance()->theme_conflicts_empty_cart_page();
111 }
112 }
113
114 public function enqueue_scripts() {
115
116 if(\ShopEngine\Core\Builders\Action::is_edit_with_gutenberg($this->prod_tpl_id)) {
117
118 add_action('wp_head', function () {
119 $css = \Wpmet\Gutenova\BlockManager::instance()->render_css($this->prod_tpl_id);
120 shopengine_content_render($css);
121 }, 999);
122
123 } else {
124
125 if(Helper::is_elementor_active()) {
126 $css_file = Post_CSS::create($this->prod_tpl_id);
127
128 if('internal' !== get_option('elementor_css_print_method')) {
129 $css_file->enqueue();
130 }
131 }
132 }
133 }
134
135 public function redirect_page_template($template) {
136
137 $this->tpl_loaded = true;
138
139 if(\ShopEngine\Core\Builders\Action::is_edit_with_gutenberg($this->prod_tpl_id)) {
140
141 $user_template = get_post_meta( $this->prod_tpl_id, '_wp_page_template', true );
142
143 $template = $this->get_builder_template_dir() . '/gutenberg-'.$user_template.'.php';
144
145 if(empty($user_template)) {
146
147 $template = $this->get_builder_template_dir() . '/gutenberg-default.php';
148 }
149
150 add_action('shopengine/builder/gutenberg/simple', function () {
151
152 include_once $this->get_template_part();
153 });
154
155 return $template;
156 }
157
158 if(Helper::is_elementor_active()) {
159
160 //this code is from elementor: /elementor/modules/page-templates/module.php:82
161 $elementor_document = \Elementor\Plugin::$instance->documents->get_doc_for_frontend($this->prod_tpl_id);
162 $elementor_template_module = \Elementor\Plugin::$instance->modules_manager->get_modules('page-templates');
163
164 if($elementor_document && $elementor_document::get_property('support_wp_page_templates')) {
165 $page_template = $elementor_document->get_meta('_wp_page_template');
166 $page_template = (in_array($page_template, ['elementor_header_footer', 'elementor_canvas']) ? $page_template : 'elementor_header_footer');
167
168 $template_path = $elementor_template_module->get_template_path($page_template);
169
170 if('elementor_theme' !== $page_template && !$template_path && $elementor_document->is_built_with_elementor()) {
171 $kit_default_template = \Elementor\Plugin::$instance->kits_manager->get_current_settings('default_page_template');
172 $template_path = $elementor_template_module->get_template_path($kit_default_template);
173 }
174
175 if($template_path) {
176 $template = $template_path;
177 }
178 }
179
180 $elementor_template_module->set_print_callback(function () {
181 include_once $this->get_template_part();
182 });
183 }
184
185 return $template;
186 }
187
188 public function get_registered_template_id($type) {
189
190 return \ShopEngine\Core\Builders\Templates::get_registered_template_id($type);
191 }
192
193 protected function get_page_type_option_slug(): string {
194
195 return $this->page_type;
196 }
197
198 public function get_template_part() {
199 return $this->get_builder_template_dir() . $this->template_part;
200 }
201
202 public function hook_body_class($classes) {
203
204 $post_type = get_post_type();
205
206 if($post_type != Template_Cpt::TYPE && !$this->template_include_pre_condition()) {
207 return $classes;
208 }
209
210 $classes[] = 'woocommerce';
211 $classes[] = $this->get_body_class();
212 $classes[] = Templates::BODY_CLASS;
213 $classes[] = (empty($this->get_page_type_option_slug()) ? '' : 'shopengine-' . $this->get_page_type_option_slug());
214 $classes[] = ($this->config['css'] ?? '');
215
216 return $classes;
217 }
218
219 protected function get_body_class() {
220 // child class may include custom classes here.
221 }
222
223 protected function get_builder_template_dir() {
224
225 return \ShopEngine::core_dir() . 'page-templates/screens/';
226 }
227
228 protected function is_template_cpt() {
229 $post_id = get_the_ID();
230 $post_type = get_post_type();
231
232 return (Template_Cpt::TYPE === $post_type) && ($this->prod_tpl_id == $post_id);
233 }
234
235 protected function is_template_active() {
236
237 $prod_tpl_post_obj = get_post($this->prod_tpl_id);
238
239 if(empty($prod_tpl_post_obj)) {
240 return false;
241 }
242
243 return $prod_tpl_post_obj->post_status == 'publish';
244 }
245 }
246