PluginProbe ʕ •ᴥ•ʔ
Royal Addons for Elementor – Addons and Templates Kit for Elementor / 1.7.1064
Royal Addons for Elementor – Addons and Templates Kit for Elementor v1.7.1064
1.7.1064 1.7.1063 1.7.1062 1.7.1061 1.7.1060 1.7.1059 1.7.1058 trunk 1.0.0 1.1.0 1.2 1.3 1.3.1 1.3.2 1.3.21 1.3.22 1.3.23 1.3.24 1.3.25 1.3.26 1.3.27 1.3.28 1.3.29 1.3.30 1.3.31 1.3.32 1.3.33 1.3.34 1.3.35 1.3.36 1.3.37 1.3.38 1.3.39 1.3.40 1.3.41 1.3.42 1.3.43 1.3.44 1.3.45 1.3.46 1.3.47 1.3.48 1.3.49 1.3.50 1.3.51 1.3.52 1.3.53 1.3.54 1.3.55 1.3.56 1.3.57 1.3.58 1.3.59 1.3.60 1.3.61 1.3.62 1.3.63 1.3.64 1.3.65 1.3.66 1.3.67 1.3.68 1.3.69 1.3.70 1.3.71 1.3.72 1.3.73 1.3.74 1.3.75 1.3.76 1.3.77 1.3.78 1.3.79 1.3.80 1.3.81 1.3.82 1.3.83 1.3.84 1.3.85 1.3.86 1.3.87 1.3.88 1.3.89 1.3.90 1.3.91 1.3.92 1.3.93 1.3.94 1.3.95 1.3.96 1.3.97 1.3.971 1.3.972 1.3.973 1.3.974 1.3.975 1.3.976 1.3.977 1.3.978 1.3.979 1.3.980 1.3.981 1.3.982 1.3.983 1.3.984 1.3.985 1.3.986 1.3.987 1.7.1 1.7.1001 1.7.1002 1.7.1003 1.7.1004 1.7.1005 1.7.1006 1.7.1007 1.7.1008 1.7.1009 1.7.1010 1.7.1011 1.7.1012 1.7.1013 1.7.1014 1.7.1015 1.7.1016 1.7.1017 1.7.1018 1.7.1019 1.7.1020 1.7.1021 1.7.1022 1.7.1023 1.7.1024 1.7.1025 1.7.1026 1.7.1027 1.7.1028 1.7.1029 1.7.1030 1.7.1031 1.7.1032 1.7.1033 1.7.1034 1.7.1035 1.7.1036 1.7.1037 1.7.1038 1.7.1039 1.7.1040 1.7.1041 1.7.1042 1.7.1043 1.7.1044 1.7.1045 1.7.1046 1.7.1047 1.7.1048 1.7.1049 1.7.1050 1.7.1051 1.7.1052 1.7.1053 1.7.1054 1.7.1055 1.7.1056 1.7.1057
royal-elementor-addons / admin / includes / wpr-render-templates.php
royal-elementor-addons / admin / includes Last commit date
wpr-conditions-manager.php 5 days ago wpr-editor-hooks.php 5 days ago wpr-render-templates.php 5 days ago wpr-templates-actions.php 5 days ago wpr-templates-category-filter.php 5 days ago wpr-templates-library.php 5 days ago wpr-templates-loop.php 5 days ago wpr-templates-modal-popups.php 5 days ago wpr-templates-shortcode.php 5 days ago
wpr-render-templates.php
314 lines
1 <?php
2 namespace WprAddons\Admin\Includes;
3
4 use WprAddons\Classes\Utilities;
5 use Elementor\Core\Base\Elements_Iteration_Actions\Assets;
6 use Elementor\Core\Files\CSS\Post as Post_CSS;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * WPR_Render_Templates setup
14 *
15 * @since 1.0
16 */
17 class WPR_Render_Templates {
18
19 /**
20 ** Instance of Elemenntor Frontend class.
21 *
22 ** @var \Elementor\Frontend()
23 */
24 private static $elementor_instance;
25
26 /**
27 ** Get Current Theme.
28 */
29 public $current_theme;
30
31 /**
32 ** Royal Themes Array.
33 */
34 public $royal_themes;
35
36
37 /**
38 ** Constructor
39 */
40 public function __construct( $only_hf = false ) {
41
42 // Elementor Frontend
43 self::$elementor_instance = \Elementor\Plugin::instance();
44
45 // Ative Theme
46 $this->current_theme = get_template();
47
48 // Royal Themes
49 $this->royal_themes = ['ashe', 'ashe-pro', 'ashe-pro-premium', 'bard', 'bard-pro', 'bard-pro-premium'];
50
51 // Popular Themes
52 if ( 'astra' === $this->current_theme ) {
53 require_once(__DIR__ . '/../templates/views/astra/class-astra-compat.php');
54
55 } elseif ( 'generatepress' === $this->current_theme ) {
56 require_once(__DIR__ . '/../templates/views/generatepress/class-generatepress-compat.php');
57
58 } elseif ( 'oceanwp' === $this->current_theme ) {
59 require_once(__DIR__ . '/../templates/views/oceanwp/class-oceanwp-compat.php');
60
61 } elseif ( 'storefront' === $this->current_theme ) {
62 require_once(__DIR__ . '/../templates/views/storefront/class-storefront-compat.php');
63
64 // Other Themes
65 } else {
66 add_action( 'wp', [ $this, 'global_compatibility' ] );
67 }
68
69 // Scripts and Styles
70 add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
71
72 // Theme Builder
73 if ( !$only_hf ) { // Prevent Loading in Header or Footer Templates
74 add_filter( 'template_include', [ $this, 'convert_to_canvas' ], 12 ); // 12 after WP Pages and WooCommerce.
75 add_action( 'elementor/page_templates/canvas/wpr_print_content', [ $this, 'canvas_page_content_display' ] );
76 }
77 }
78
79 public function global_compatibility() {
80 add_action( 'get_header', [ $this, 'replace_header' ] );
81 add_action( 'elementor/page_templates/canvas/before_content', [ $this, 'add_canvas_header' ] );
82
83 add_action( 'get_footer', [ $this, 'replace_footer' ] );
84 add_action( 'elementor/page_templates/canvas/after_content', [ $this, 'add_canvas_footer' ], 9 );
85 }
86
87 /**
88 ** Check if a Template has Conditions
89 */
90 public function is_template_available( $type ) {
91 if ( 'content' === $type ) {
92 return !is_null(WPR_Conditions_Manager::canvas_page_content_display_conditions()) ? true : false;
93 } else {
94 $conditions = json_decode( get_option('wpr_'. $type .'_conditions', '[]'), true );
95 $template = WPR_Conditions_Manager::header_footer_display_conditions( $conditions );
96
97 return (!empty( $conditions ) && !is_null($template)) ? true : false;
98 }
99 }
100
101 /**
102 ** Header
103 */
104 public function replace_header() {
105 if ( $this->is_template_available('header') ) {
106 if ( ! in_array($this->current_theme, $this->royal_themes) ) {
107 require __DIR__ . '/../templates/views/theme-header.php';
108 } else {
109 require __DIR__ . '/../templates/views/royal/theme-header-royal.php';
110 }
111
112 $templates = [];
113 $templates[] = 'header.php';
114
115 remove_all_actions( 'wp_head' ); // Avoid running wp_head hooks again.
116
117 ob_start();
118 locate_template( $templates, true );
119 ob_get_clean();
120 }
121 }
122
123 public function add_canvas_header() {
124 if ( $this->is_template_available('header') ) {
125 $conditions = json_decode( get_option('wpr_header_conditions', '[]'), true );
126 $template_slug = WPR_Conditions_Manager::header_footer_display_conditions($conditions);
127 $template_id = Utilities::get_template_id($template_slug);
128
129 $show_on_canvas = get_post_meta($template_id, 'wpr_header_show_on_canvas', true);
130
131 if ( defined('ICL_LANGUAGE_CODE') ) {
132 $default_language_code = apply_filters('wpml_default_language', null);
133 $current_language_code = apply_filters('wpml_current_language', null);
134
135 if ( $current_language_code && $current_language_code !== $default_language_code ) {
136 $show_on_canvas = 'true';
137 $translated_id = apply_filters('wpml_object_id', $template_id, 'wpr_templates', true, $current_language_code);
138 if ( $translated_id && (int) $translated_id !== (int) $template_id ) {
139 $template_id = $translated_id;
140 }
141 }
142 }
143
144 // if ( !empty($show_on_canvas) && 'true' === $show_on_canvas && 0 === strpos($template_slug, 'user-header-') ) {
145 if ( !empty($show_on_canvas) && 'true' === $show_on_canvas && !is_null($template_slug) ) {
146 Utilities::render_elementor_template($template_slug, $template_id);
147 }
148 }
149 }
150
151 /**
152 ** Footer
153 */
154 public function replace_footer() {
155 if ( $this->is_template_available('footer') ) {
156 if ( ! in_array($this->current_theme, $this->royal_themes) ) {
157 require __DIR__ . '/../templates/views/theme-footer.php';
158 } else {
159 require __DIR__ . '/../templates/views/royal/theme-footer-royal.php';
160 }
161
162 $templates = [];
163 $templates[] = 'footer.php';
164
165 remove_all_actions( 'wp_footer' ); // Avoid running wp_footer hooks again.
166
167 ob_start();
168 locate_template( $templates, true );
169 ob_get_clean();
170 }
171 }
172
173 public function add_canvas_footer() {
174 if ( $this->is_template_available('footer') ) {
175 $conditions = json_decode( get_option('wpr_footer_conditions', '[]'), true );
176 $template_slug = WPR_Conditions_Manager::header_footer_display_conditions($conditions);
177 $template_id = Utilities::get_template_id($template_slug);
178
179 $show_on_canvas = get_post_meta($template_id, 'wpr_footer_show_on_canvas', true);
180
181 if ( defined('ICL_LANGUAGE_CODE') ) {
182 $default_language_code = apply_filters('wpml_default_language', null);
183 $current_language_code = apply_filters('wpml_current_language', null);
184
185 if ( $current_language_code && $current_language_code !== $default_language_code ) {
186 $show_on_canvas = 'true';
187 $translated_id = apply_filters('wpml_object_id', $template_id, 'wpr_templates', true, $current_language_code);
188 if ( $translated_id && (int) $translated_id !== (int) $template_id ) {
189 $template_id = $translated_id;
190 }
191 }
192 }
193
194 // if ( !empty($show_on_canvas) && 'true' === $show_on_canvas && 0 === strpos($template_slug, 'user-footer-') ) {
195 if ( !empty($show_on_canvas) && 'true' === $show_on_canvas && !is_null($template_slug) ) {
196 Utilities::render_elementor_template($template_slug, $template_id);
197 }
198 }
199 }
200
201 public function convert_to_canvas( $template ) {
202 $is_theme_builder_edit = \Elementor\Plugin::$instance->preview->is_preview_mode() && Utilities::is_theme_builder_template() ? true : false;
203 $_wp_page_template = get_post_meta(get_the_ID(), '_wp_page_template', true);
204
205 if ( $this->is_template_available('content') || $is_theme_builder_edit ) {
206 if ( (is_page() || is_single()) && 'elementor_canvas' === $_wp_page_template && !$is_theme_builder_edit ) {
207 return $template;
208 } else {
209 return WPR_ADDONS_PATH . 'admin/templates/wpr-canvas.php';
210 }
211 } else {
212 return $template;
213 }
214 }
215
216 /**
217 ** Theme Builder Content Display
218 */
219 public function canvas_page_content_display() {
220 // Get Template
221 $template = WPR_Conditions_Manager::canvas_page_content_display_conditions();
222
223 // Display Template
224 Utilities::render_elementor_template( $template );
225 }
226
227 /**
228 * Enqueue styles and scripts.
229 */
230 public function enqueue_scripts() {
231
232 if ( !class_exists( '\Elementor\Plugin' ) ) {
233 return;
234 }
235
236 // Elementor Frontend // Maybe we dont need this (should be extra, because we have everything below)
237 // self::$elementor_instance->frontend->enqueue_styles();
238
239 // if ( class_exists( '\ElementorPro\Plugin' ) ) {
240 // $elementor_pro = \ElementorPro\Plugin::instance();
241 // $elementor_pro->enqueue_frontend_scripts();
242 // }
243
244 // Load Header Template CSS File
245 $heder_conditions = json_decode( get_option('wpr_header_conditions', '[]'), true );
246 $heder_template = WPR_Conditions_Manager::header_footer_display_conditions($heder_conditions);
247 $header_template_id = !is_null($heder_template) ? Utilities::get_template_id($heder_template) : false;
248
249 if ( false !== $header_template_id ) {
250
251 // Load Header Template Assets (Elementor Widget)
252 if ( ! self::$elementor_instance->preview->is_preview_mode() ) {
253 $page_assets = get_post_meta( $header_template_id, Assets::ASSETS_META_KEY, true );
254 if ( ! empty( $page_assets ) ) {
255 self::$elementor_instance->assets_loader->enable_assets( $page_assets );
256 }
257
258 $css_file = Post_CSS::create( get_the_ID() );
259 $css_file->enqueue();
260 }
261
262 // Header Template CSS File
263 if ( class_exists( '\Elementor\Core\Files\CSS\Post' ) ) {
264 $header_css_file = new \Elementor\Core\Files\CSS\Post( $header_template_id );
265 } elseif ( class_exists( '\Elementor\Post_CSS_File' ) ) {
266 $header_css_file = new \Elementor\Post_CSS_File( $header_template_id );
267 }
268
269 $header_css_file->enqueue();
270 }
271
272 // Load Footer Template CSS File
273 $footer_conditions = json_decode( get_option('wpr_footer_conditions', '[]'), true );
274 $footer_template = WPR_Conditions_Manager::header_footer_display_conditions($footer_conditions);
275 $footer_template_id = !is_null($footer_template) ? Utilities::get_template_id($footer_template) : false;
276
277 if ( false !== $footer_template_id ) {
278 // Load Footer Template Assets (Elementor Widget)
279 if ( ! self::$elementor_instance->preview->is_preview_mode() ) {
280 $page_assets = get_post_meta( $footer_template_id, Assets::ASSETS_META_KEY, true );
281 if ( ! empty( $page_assets ) ) {
282 self::$elementor_instance->assets_loader->enable_assets( $page_assets );
283 }
284
285 $css_file = Post_CSS::create( get_the_ID() );
286 $css_file->enqueue();
287 }
288
289 // Footer Template CSS File
290 if ( class_exists( '\Elementor\Core\Files\CSS\Post' ) ) {
291 $footer_css_file = new \Elementor\Core\Files\CSS\Post( $footer_template_id );
292 } elseif ( class_exists( '\Elementor\Post_CSS_File' ) ) {
293 $footer_css_file = new \Elementor\Post_CSS_File( $footer_template_id );
294 }
295
296 $footer_css_file->enqueue();
297 }
298
299 // Load Canvas Content Template CSS File
300 $canvas_conditions = WPR_Conditions_Manager::canvas_page_content_display_conditions();
301 $canvas_template_id = !empty($canvas_conditions) ? Utilities::get_template_id($canvas_conditions) : false;
302
303 if ( false !== $canvas_template_id ) {
304 if ( class_exists( '\Elementor\Core\Files\CSS\Post' ) ) {
305 $footer_css_file = new \Elementor\Core\Files\CSS\Post( $canvas_template_id );
306 } elseif ( class_exists( '\Elementor\Post_CSS_File' ) ) {
307 $footer_css_file = new \Elementor\Post_CSS_File( $canvas_template_id );
308 }
309
310 $footer_css_file->enqueue();
311 }
312 }
313
314 }