PluginProbe ʕ •ᴥ•ʔ
Essential Classy Addons for Elementor – 150+ Widgets, Templates & Performance Tools / 3.0.38
Essential Classy Addons for Elementor – 150+ Widgets, Templates & Performance Tools v3.0.38
3.0.59 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 3.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.18 3.0.2 3.0.20 3.0.21 3.0.22 3.0.23 3.0.24 3.0.25 3.0.26 3.0.27 3.0.28 3.0.29 3.0.3 3.0.30 3.0.31 3.0.32 3.0.33 3.0.34 3.0.35 3.0.36 3.0.37 3.0.38 3.0.39 3.0.4 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.0.46 3.0.47 3.0.48 3.0.49 3.0.5 3.0.50 3.0.51 3.0.52 3.0.53 3.0.54 3.0.55 3.0.56 3.0.57 3.0.58 3.0.6 3.0.7 3.0.8 3.0.9
essential-classy-addons-for-elementor / classes / theme-builder.php
essential-classy-addons-for-elementor / classes Last commit date
builders 1 year ago documents 1 year ago builder-content.php 1 year ago class-helper.php 1 year ago class-loader.php 1 year ago class-panel-options.php 1 year ago conditions-file.php 1 year ago conditions-rules.php 1 year ago elementor-document.php 1 year ago theme-builder.php 1 year ago widgets-passing-lists.php 1 year ago
theme-builder.php
493 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5
6 class Ecafe_Theme_Builder {
7
8 public static $instance = null;
9
10 const Ecafe_Type = ECAFE_POST;
11 const Ecafe_Shortcode = 'ecafe-builder';
12
13 public $taxonomies_list = [];
14 public static function instance() {
15 if ( ! isset( self::$instance ) ) {
16 self::$instance = new self;
17 }
18 return self::$instance;
19 }
20
21 /**
22 * Constructor
23 */
24 public function __construct() {
25 add_action('wp', array($this, 'ec_load_templates'));
26 add_action('init', [$this, 'ec_template_builder_post_type'], 0);
27 add_action('admin_menu', [$this, 'ec_change_menu_post_type'], 9);
28
29 add_action('manage_' . self::Ecafe_Type . '_posts_columns', [__CLASS__, 'ec_admin_columns_headers']);
30 add_action('manage_' . self::Ecafe_Type . '_posts_custom_column', [$this, 'ec_admin_columns_text'], 10, 2);
31
32 add_action('wp_ajax_ecafe_get_prev_list', [$this, 'ec_get_prev_list_callback'] );
33 add_action('add_meta_boxes', [$this, 'ec_builder_condition_meta'] );
34 add_action('save_post', [$this, 'ec_builder_condition_save_meta'] );
35
36 add_filter('template_include', [$this, 'ecafe_single_template_overright'], 1000);
37 add_action('ecafe_content_render', [$this, 'ec_singular_archives_content_render'], 1000);
38
39 if ( is_admin() ) {
40 add_action( 'manage_' . self::Ecafe_Type . '_posts_columns', [ $this, 'ec_admin_columns_shortcode' ],15 );
41 add_action( 'manage_' . self::Ecafe_Type . '_posts_custom_column', [ $this, 'ec_admin_columns_shortcode_content' ], 15, 2 );
42 }
43
44 add_shortcode( self::Ecafe_Shortcode, [ $this, 'ec_create_shortcode' ] );
45 }
46
47 public function ec_template_builder_post_type(){
48 $labels = array(
49 'name' => _x('Theme Builder', 'Post Type General Name', 'essential-classy-addons-for-elementor'),
50 'singular_name' => _x('Theme Builder', 'Post Type Singular Name', 'essential-classy-addons-for-elementor'),
51 'menu_name' => _x('Theme Builder', 'Admin Menu text', 'essential-classy-addons-for-elementor'),
52 'name_admin_bar' => _x('Theme Builder', 'Add New on Toolbar', 'essential-classy-addons-for-elementor'),
53 'archives' => __('Theme Builder Archives', 'essential-classy-addons-for-elementor'),
54 'attributes' => __('Theme Builder Attributes', 'essential-classy-addons-for-elementor'),
55 'parent_item_colon' => __('Parent Theme Builder:', 'essential-classy-addons-for-elementor'),
56 'all_items' => __('All Theme Builder', 'essential-classy-addons-for-elementor'),
57 'add_new_item' => __('Add New Theme Builder', 'essential-classy-addons-for-elementor'),
58 'add_new' => __('Add New', 'essential-classy-addons-for-elementor'),
59 'new_item' => __('New Theme Builder', 'essential-classy-addons-for-elementor'),
60 'edit_item' => __('Edit Theme Builder', 'essential-classy-addons-for-elementor'),
61 'update_item' => __('Update Theme Builder', 'essential-classy-addons-for-elementor'),
62 'view_item' => __('View Theme Builder', 'essential-classy-addons-for-elementor'),
63 'view_items' => __('View Theme Builder', 'essential-classy-addons-for-elementor'),
64 'search_items' => __('Search Theme Builder', 'essential-classy-addons-for-elementor'),
65 'not_found' => __('Not found', 'essential-classy-addons-for-elementor'),
66 'not_found_in_trash' => __('Not found in Trash', 'essential-classy-addons-for-elementor'),
67 'featured_image' => __('Featured Image', 'essential-classy-addons-for-elementor'),
68 'set_featured_image' => __('Set featured image', 'essential-classy-addons-for-elementor'),
69 'remove_featured_image' => __('Remove featured image', 'essential-classy-addons-for-elementor'),
70 'use_featured_image' => __('Use as featured image', 'essential-classy-addons-for-elementor'),
71 'insert_into_item' => __('Insert into Theme Builder', 'essential-classy-addons-for-elementor'),
72 'uploaded_to_this_item' => __('Uploaded to this Theme Builder', 'essential-classy-addons-for-elementor'),
73 'items_list' => __('Theme Builder list', 'essential-classy-addons-for-elementor'),
74 'items_list_navigation' => __('Theme Builder list navigation', 'essential-classy-addons-for-elementor'),
75 'filter_items_list' => __('Filter Theme Builder list', 'essential-classy-addons-for-elementor'),
76 );
77 $args = array(
78 'label' => __('Theme Builder', 'essential-classy-addons-for-elementor'),
79 'description' => __('Description', 'essential-classy-addons-for-elementor'),
80 'labels' => $labels,
81 'supports' => array('title', 'editor', 'revisions','elementor'),
82 'taxonomies' => array(),
83 'public' => true,
84 'show_ui' => true,
85 'show_in_menu' => false,
86 'show_in_admin_bar' => false,
87 'show_in_nav_menus' => false,
88 'can_export' => true,
89 'has_archive' => false,
90 'hierarchical' => false,
91 'exclude_from_search' => true,
92 'capability_type' => 'post',
93 'rewrite' => false,
94 'query_var' => false,
95 'map_meta_cap' => true,
96 'show_in_rest' => true,
97 );
98 register_post_type( self::Ecafe_Type, $args );
99
100 }
101
102 public function ec_change_menu_post_type() {
103 add_submenu_page(
104 'ecafe_welcome',
105 __( 'Theme Builder', 'essential-classy-addons-for-elementor' ),
106 __( 'Theme Builder', 'essential-classy-addons-for-elementor' ),
107 'manage_options',
108 'edit.php?post_type='.sanitize_text_field(self::Ecafe_Type),
109 false
110 );
111 }
112
113 public static function ec_admin_columns_headers($posts_columns) {
114 $offset = 2;
115
116 $posts_columns = array_slice($posts_columns, 0, $offset, true) + [
117 'type' => __('Type', 'essential-classy-addons-for-elementor'),
118 ] + array_slice($posts_columns, $offset, null, true);
119
120 return $posts_columns;
121 }
122
123 public function ec_admin_columns_text( $column_name, $post_id ) {
124
125 if ('type' === $column_name) {
126 $type = get_post_meta($post_id, 'ecafe_build_template_type', true);
127 if(!empty($type)){
128 echo esc_html(ucfirst($type));
129 }
130 }
131 }
132
133 public function ec_builder_condition_meta(){
134 add_meta_box(
135 'ecafe-template-settings',
136 __('Template Settings','essential-classy-addons-for-elementor'),
137 array($this, 'ec_builder_condition_fields'),
138 self::Ecafe_Type,
139 'normal',
140 'default'
141 );
142 }
143
144 public function ec_get_public_post_types() {
145 $post_type_args = [
146 'show_in_nav_menus' => true,
147 ];
148
149 $post_type_args = wp_parse_args($post_type_args);
150
151 $ecpost_types = get_post_types($post_type_args, 'objects');
152
153 $post_types = [];
154
155 foreach ($ecpost_types as $post_type => $object) {
156 if($post_type!='e-landing-page'){
157 $post_types[$post_type] = $object->label;
158 }
159 }
160
161 return $post_types;
162 }
163
164 public function ec_get_posts_list( $post_type = 'post'){
165 $arg = [
166 'posts_per_page' => -1,
167 'post_status' => 'publish',
168 'post_type' => $post_type
169 ];
170
171 $posts = get_posts($arg);
172 $post_array = array();
173 if(!empty($posts)){
174 foreach ($posts as $post) {
175 $post_array[$post->ID] = $post->post_title;
176 }
177 }
178
179 return $post_array;
180 }
181
182 function ec_get_prev_list_callback() {
183 if (!isset($_POST['ecafe_nonce'])) {
184 return;
185 }
186 $ecafe_nonce = isset( $_POST['ecafe_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['ecafe_nonce'] ) ) : '';
187
188 // Verify nonce
189 if (!wp_verify_nonce($ecafe_nonce, 'ecafe-temp-nonce')) {
190 return;
191 }
192
193 // Check user capability
194 if (!current_user_can('manage_options')) {
195 return;
196 }
197
198 // Check permissions
199 if (!current_user_can('edit_posts')) {
200 return;
201 }
202
203 $data = [];
204 $template_type = (isset($_POST['template_type']) && !empty($_POST['template_type'])) ? sanitize_text_field(wp_unslash($_POST['template_type'])) : 'singular';
205
206 if($template_type == 'singular' ){
207 $post_type = (isset($_POST['template_data']) && !empty($_POST['template_data'])) ? sanitize_text_field(wp_unslash($_POST['template_data'])) : 'post';
208 $data = $this->ec_get_posts_list($post_type);
209 }else if($template_type == 'archives'){
210 $taxonomy = (isset($_POST['template_data']) && !empty($_POST['template_data'])) ? sanitize_text_field(wp_unslash($_POST['template_data'])) : 'category';
211 $taxonomy = explode(',', $taxonomy);
212 $data = $this->ec_get_taxonomy_list($taxonomy);
213 }
214
215 $output = '';
216 if(!empty($data)){
217 foreach($data as $key => $val){
218 $output .='<option value="'.esc_attr($key).'">'.esc_html($val).'</option>';
219 }
220 }
221 wp_send_json_success($output);
222 }
223
224 public function ec_get_public_taxonomy_list(){
225 $post_types = $this->ec_get_public_post_types();
226 $taxonomy_list = [];
227 foreach ( $post_types as $post_type => $post_label ) {
228
229 if ( ! get_post_type_archive_link( $post_type ) ) {
230 continue;
231 }
232
233 $taxonomies = get_object_taxonomies( $post_type, 'objects' );
234 $taxonomies_list = wp_filter_object_list( $taxonomies, [
235 'public' => true,
236 'show_in_nav_menus' => true,
237 ] );
238 foreach ( $taxonomies_list as $slug => $object ) {
239 $taxonomy_list[$object->name] = $object->label;
240 }
241 }
242
243 return $taxonomy_list;
244 }
245
246 public function ec_get_taxonomy_list($taxonomy){
247 $terms = get_terms([
248 'taxonomy' => $taxonomy,
249 'hide_empty' => false,
250 ]);
251
252 $term_list = [];
253 if( !empty($terms)){
254 foreach ($terms as $term) {
255 $term_list[$term->term_id] = $term->name;
256 }
257 }
258 return $term_list;
259 }
260
261 public function ec_builder_condition_fields($post) {
262 // Retrieve existing value from the database
263 $template_type = get_post_meta($post->ID, 'ecafe_build_template_type', true);
264 $template_display = get_post_meta($post->ID, 'ecafe_build_template_display', true);
265 $display_singular = get_post_meta($post->ID, 'ecafe_build_display_singular', true);
266 $display_archives = get_post_meta($post->ID, 'ecafe_build_display_archives', true);
267
268 $display_prev = get_post_meta($post->ID, 'ecafe_build_display_prev', true);
269 $options = array(
270 '' => __('None', 'essential-classy-addons-for-elementor'),
271 'header' => __('Header', 'essential-classy-addons-for-elementor'),
272 'footer' => __('Footer', 'essential-classy-addons-for-elementor'),
273 'singular' => __('Singular', 'essential-classy-addons-for-elementor'),
274 'archives' => __('Archives', 'essential-classy-addons-for-elementor'),
275 'page404' => __('404 Page', 'essential-classy-addons-for-elementor'),
276 );
277 $get_post_types = $this->ec_get_public_post_types();
278 $get_taxonomies = $this->ec_get_public_taxonomy_list();
279
280 $get_prev = [];
281 if( $template_type == 'singular'){
282 $get_prev = $this->ec_get_posts_list($display_singular);
283 }else if( $template_type == 'archives'){
284 $get_prev = $this->ec_get_taxonomy_list($display_archives);
285 }
286
287 wp_nonce_field('ec_template_builder_nonce', 'ec_template_builder_nonce');
288 ?>
289 <div class="ecafe-build-field-wrap">
290 <div class="ecafe-field-col">
291 <label for="ecafe-build-temp-type"><?php echo esc_html__('Template Type :', 'essential-classy-addons-for-elementor'); ?></label>
292 <select id="ecafe-build-temp-type" name="ecafe_build_template_type">
293 <?php foreach ($options as $value => $label) : ?>
294 <option value="<?php echo esc_attr($value); ?>" <?php selected($template_type, $value); ?>><?php echo esc_html($label); ?></option>
295 <?php endforeach; ?>
296 </select>
297 </div>
298 <div class="ecafe-field-col">
299 <label for="ecafe-build-temp-display"><?php echo esc_html__('Display :', 'essential-classy-addons-for-elementor'); ?></label>
300 <select id="ecafe-build-temp-display" name="ecafe_build_template_display">
301 <option value="entire" <?php selected($template_display, 'entire'); ?>><?php esc_html_e('Entire Website', 'essential-classy-addons-for-elementor'); ?></option>
302 </select>
303 </div>
304
305 <div class="ecafe-field-col">
306 <label for="ecafe-build-display-singular"><?php echo esc_html__('Display :', 'essential-classy-addons-for-elementor'); ?></label>
307 <select id="ecafe-build-display-singular" name="ecafe_build_display_singular">
308 <?php foreach ($get_post_types as $post_type => $label) : ?>
309 <option value="<?php echo esc_attr($post_type); ?>" <?php selected($display_singular, $post_type); ?>><?php echo esc_html__('All ', 'essential-classy-addons-for-elementor').esc_html($label); ?></option>
310 <?php endforeach; ?>
311 </select>
312 </div>
313
314 <div class="ecafe-field-col">
315 <label for="ecafe-build-display-archives"><?php echo esc_html__('Display :', 'essential-classy-addons-for-elementor'); ?></label>
316 <select id="ecafe-build-display-archives" name="ecafe_build_display_archives[]" multiple>
317 <?php foreach ($get_taxonomies as $key => $label) :
318 $selected = in_array($key, (array) $display_archives) ? 'selected' : '';
319 ?>
320 <option value="<?php echo esc_attr($key); ?>" <?php echo esc_attr($selected); ?>><?php echo esc_html__('All ', 'essential-classy-addons-for-elementor').esc_html($label); ?></option>
321 <?php endforeach; ?>
322 </select>
323 </div>
324
325 <div class="ecafe-field-col">
326 <label for="ecafe-build-display-prev"><?php echo esc_html__('Preview :', 'essential-classy-addons-for-elementor'); ?></label>
327 <select id="ecafe-build-display-prev" name="ecafe_build_display_prev">
328 <?php foreach ($get_prev as $post_type => $label) : ?>
329 <option value="<?php echo esc_attr($post_type); ?>" <?php selected($display_prev, $post_type); ?>><?php echo esc_html($label); ?></option>
330 <?php endforeach; ?>
331 </select>
332 </div>
333 </div>
334 <?php
335 }
336
337 public function ec_builder_condition_save_meta($post_id) {
338 // Check if nonce is set
339 if (!isset($_POST['ec_template_builder_nonce'])) {
340 return;
341 }
342 $ecafe_nonce = isset( $_POST['ec_template_builder_nonce'] ) ? sanitize_text_field( wp_unslash($_POST['ec_template_builder_nonce']) ) : '';
343
344 // Verify nonce
345 if (!wp_verify_nonce($ecafe_nonce, 'ec_template_builder_nonce')) {
346 return;
347 }
348 // Check if autosave
349 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
350 return;
351 }
352
353 // Check permissions
354 if (!current_user_can('edit_post', $post_id)) {
355 return;
356 }
357 // Save Theme Builder field data
358 if(isset($_POST['ecafe_build_template_type'])){
359 update_post_meta($post_id, 'ecafe_build_template_type', sanitize_text_field(wp_unslash($_POST['ecafe_build_template_type'])) );
360 }
361 if(isset($_POST['ecafe_build_template_display'])){
362 update_post_meta($post_id, 'ecafe_build_template_display', sanitize_text_field(wp_unslash($_POST['ecafe_build_template_display'])) );
363 }
364 if(isset($_POST['ecafe_build_display_singular'])){
365 update_post_meta($post_id, 'ecafe_build_display_singular', sanitize_text_field(wp_unslash($_POST['ecafe_build_display_singular'])) );
366 }
367 if(isset($_POST['ecafe_build_display_archives']) && !empty($_POST['ecafe_build_display_archives'])){
368 $display_archives = array_map( 'sanitize_text_field', (array) wp_unslash( $_POST['ecafe_build_display_archives'] ) );
369 update_post_meta($post_id, 'ecafe_build_display_archives', $display_archives );
370 }
371 if(isset($_POST['ecafe_build_display_prev']) && !empty($_POST['ecafe_build_display_prev'])){
372 update_post_meta($post_id, 'ecafe_build_display_prev', sanitize_text_field(wp_unslash($_POST['ecafe_build_display_prev'])) );
373 }
374 }
375
376 /* Overright Header/Footer Template */
377 public function ec_load_templates(){
378 $curr_temp = basename(get_page_template_slug());
379
380 if ($curr_temp == 'elementor_canvas') {
381 return;
382 }
383
384 new Ecafe_Theme_Template();
385 }
386
387 /* get Conditional Content*/
388 public function ec_render_builder_data_location( $location ){
389 $temp = Ecafe_Condition_Rules::get_instance()->ec_get_location_type($location);
390 if($location == 'header' || $location = 'footer'){
391 $load_template = $temp;
392 }else{
393 $_key = key($temp);
394 $load_template = $temp[$_key];
395 }
396 return Ec_Template_Builder_Content::get_instance()->ec_get_render_content($load_template);
397 }
398
399 public function ecafe_single_template_overright( $template ){
400 if (is_singular(array_keys($this->ec_get_public_post_types())) || is_404()) {
401
402 $location = 'singular';
403 if(is_404()){
404 $location = 'page404';
405 }
406
407 } elseif (function_exists('is_shop') && \is_shop()) {
408 $location = 'archives';
409 } elseif (is_archive() || is_tax() || is_home() || is_search()) {
410 $location = 'archives';
411 }
412
413 if ( !empty( $location ) ) {
414 $location_documents = Ecafe_Condition_Rules::get_instance()->ec_get_location_type($location);
415
416 if (empty($location_documents)) {
417 return $template;
418 }
419
420
421 if ('singular' === $location || 'archives' === $location || 'page404' === $location ) {
422
423 $first_key = key($location_documents);
424 $theme_document = $location_documents[$first_key];
425
426 $templateType = get_post_meta($theme_document, '_wp_page_template', true);
427
428 $this->singular_template = $theme_document;
429
430 if ($theme_document) {
431 switch ($templateType) {
432 case "elementor_canvas":
433 $template = ECAFE_CLASSES_URL . 'builders/singular-canvas.php';
434 break;
435 case "elementor_header_footer":
436 $template = ECAFE_CLASSES_URL . 'builders/singular-fullwidth.php';
437 break;
438 default:
439 $template = ECAFE_CLASSES_URL . 'builders/singular-fullwidth.php';
440 break;
441 }
442 }
443 }
444 }
445
446 return $template;
447 }
448
449 public function ec_singular_archives_content_render($post) {
450 $templates = $this->singular_template;
451 if (!empty($templates)) {
452 $allowed_tags = wp_kses_allowed_html( 'post' );
453 $allowed_tags['script'] = array(
454 'type' => true,
455 'src' => true,
456 'defer' => true,
457 );
458 $allowed_tags['style'] = array(
459 'type' => true,
460 'media' => true,
461 );
462 echo Ec_Template_Builder_Content::get_instance()->ec_get_render_content($templates);
463 } else {
464 the_content();
465 }
466 }
467
468 public function ec_admin_columns_shortcode( $columns ) {
469 $columns['ecafe-shortcode'] = __( 'Shortcode', 'essential-classy-addons-for-elementor' );
470
471 return $columns;
472 }
473
474 public function ec_admin_columns_shortcode_content( $column, $post_id ) {
475 if ( 'ecafe-shortcode' === $column ) {
476 //translator %s = shortcode, %d = post_id
477 $shortcode = esc_attr( sprintf( '[%s id="%d"]', self::Ecafe_Shortcode, $post_id ) );
478 printf( '<input type="text" class="ecafe-shortcode-input" onfocus="this.select()" value="%s" readonly style="font-size: 12px;"/>', esc_attr($shortcode) );
479 }
480 }
481
482 public function ec_create_shortcode( $option = [] ) {
483 if ( empty( $option['id'] ) ) {
484 return '';
485 }
486
487 ob_start();
488 echo Ec_Template_Builder_Content::get_instance()->ec_get_render_content($option['id']);
489 return ob_get_clean();
490 }
491 }
492
493 Ecafe_Theme_Builder::instance();