PluginProbe ʕ •ᴥ•ʔ
Essential Classy Addons for Elementor – 150+ Widgets, Templates & Performance Tools / 3.0.59
Essential Classy Addons for Elementor – 150+ Widgets, Templates & Performance Tools v3.0.59
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 2 weeks ago documents 2 weeks ago builder-content.php 2 weeks ago class-helper.php 2 weeks ago class-loader.php 2 weeks ago class-panel-options.php 2 weeks ago conditions-file.php 2 weeks ago conditions-rules.php 2 weeks ago elementor-document.php 2 weeks ago theme-builder.php 2 weeks ago widgets-passing-lists.php 2 weeks ago
theme-builder.php
498 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 protected $singular_template;
10
11 const Ecafe_Type = ECAFE_POST;
12 const Ecafe_Shortcode = 'ecafe-builder';
13
14 public $taxonomies_list = array();
15 public static function instance() {
16 if ( ! isset( self::$instance ) ) {
17 self::$instance = new self();
18 }
19 return self::$instance;
20 }
21
22 /**
23 * Constructor
24 */
25 public function __construct() {
26 add_action( 'wp', array( $this, 'ec_load_templates' ) );
27 add_action( 'init', array( $this, 'ec_template_builder_post_type' ), 0 );
28 add_action( 'admin_menu', array( $this, 'ec_change_menu_post_type' ), 9 );
29
30 add_action( 'manage_' . self::Ecafe_Type . '_posts_columns', array( __CLASS__, 'ec_admin_columns_headers' ) );
31 add_action( 'manage_' . self::Ecafe_Type . '_posts_custom_column', array( $this, 'ec_admin_columns_text' ), 10, 2 );
32
33 add_action( 'wp_ajax_ecafe_get_prev_list', array( $this, 'ec_get_prev_list_callback' ) );
34 add_action( 'add_meta_boxes', array( $this, 'ec_builder_condition_meta' ) );
35 add_action( 'save_post', array( $this, 'ec_builder_condition_save_meta' ) );
36
37 add_filter( 'template_include', array( $this, 'ecafe_single_template_overright' ), 1000 );
38 add_action( 'ecafe_content_render', array( $this, 'ec_singular_archives_content_render' ), 1000 );
39
40 if ( is_admin() ) {
41 add_action( 'manage_' . self::Ecafe_Type . '_posts_columns', array( $this, 'ec_admin_columns_shortcode' ), 15 );
42 add_action( 'manage_' . self::Ecafe_Type . '_posts_custom_column', array( $this, 'ec_admin_columns_shortcode_content' ), 15, 2 );
43 }
44
45 add_shortcode( self::Ecafe_Shortcode, array( $this, 'ec_create_shortcode' ) );
46 }
47
48 public function ec_template_builder_post_type() {
49 $labels = array(
50 'name' => _x( 'Theme Builder', 'Post Type General Name', 'essential-classy-addons-for-elementor' ),
51 'singular_name' => _x( 'Theme Builder', 'Post Type Singular Name', 'essential-classy-addons-for-elementor' ),
52 'menu_name' => _x( 'Theme Builder', 'Admin Menu text', 'essential-classy-addons-for-elementor' ),
53 'name_admin_bar' => _x( 'Theme Builder', 'Add New on Toolbar', 'essential-classy-addons-for-elementor' ),
54 'archives' => __( 'Theme Builder Archives', 'essential-classy-addons-for-elementor' ),
55 'attributes' => __( 'Theme Builder Attributes', 'essential-classy-addons-for-elementor' ),
56 'parent_item_colon' => __( 'Parent Theme Builder:', 'essential-classy-addons-for-elementor' ),
57 'all_items' => __( 'All Theme Builder', 'essential-classy-addons-for-elementor' ),
58 'add_new_item' => __( 'Add New Theme Builder', 'essential-classy-addons-for-elementor' ),
59 'add_new' => __( 'Add New', 'essential-classy-addons-for-elementor' ),
60 'new_item' => __( 'New Theme Builder', 'essential-classy-addons-for-elementor' ),
61 'edit_item' => __( 'Edit Theme Builder', 'essential-classy-addons-for-elementor' ),
62 'update_item' => __( 'Update Theme Builder', 'essential-classy-addons-for-elementor' ),
63 'view_item' => __( 'View Theme Builder', 'essential-classy-addons-for-elementor' ),
64 'view_items' => __( 'View Theme Builder', 'essential-classy-addons-for-elementor' ),
65 'search_items' => __( 'Search Theme Builder', 'essential-classy-addons-for-elementor' ),
66 'not_found' => __( 'Not found', 'essential-classy-addons-for-elementor' ),
67 'not_found_in_trash' => __( 'Not found in Trash', 'essential-classy-addons-for-elementor' ),
68 'featured_image' => __( 'Featured Image', 'essential-classy-addons-for-elementor' ),
69 'set_featured_image' => __( 'Set featured image', 'essential-classy-addons-for-elementor' ),
70 'remove_featured_image' => __( 'Remove featured image', 'essential-classy-addons-for-elementor' ),
71 'use_featured_image' => __( 'Use as featured image', 'essential-classy-addons-for-elementor' ),
72 'insert_into_item' => __( 'Insert into Theme Builder', 'essential-classy-addons-for-elementor' ),
73 'uploaded_to_this_item' => __( 'Uploaded to this Theme Builder', 'essential-classy-addons-for-elementor' ),
74 'items_list' => __( 'Theme Builder list', 'essential-classy-addons-for-elementor' ),
75 'items_list_navigation' => __( 'Theme Builder list navigation', 'essential-classy-addons-for-elementor' ),
76 'filter_items_list' => __( 'Filter Theme Builder list', 'essential-classy-addons-for-elementor' ),
77 );
78 $args = array(
79 'label' => __( 'Theme Builder', 'essential-classy-addons-for-elementor' ),
80 'description' => __( 'Description', 'essential-classy-addons-for-elementor' ),
81 'labels' => $labels,
82 'supports' => array( 'title', 'editor', 'revisions', 'elementor' ),
83 'taxonomies' => array(),
84 'public' => true,
85 'show_ui' => true,
86 'show_in_menu' => false,
87 'show_in_admin_bar' => false,
88 'show_in_nav_menus' => false,
89 'can_export' => true,
90 'has_archive' => false,
91 'hierarchical' => false,
92 'exclude_from_search' => true,
93 'capability_type' => 'post',
94 'rewrite' => false,
95 'query_var' => false,
96 'map_meta_cap' => true,
97 'show_in_rest' => true,
98 );
99 register_post_type( self::Ecafe_Type, $args );
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 ) + array(
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 = array(
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 = array();
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 = array(
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 = array();
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 } elseif ( $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 = array();
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(
235 $taxonomies,
236 array(
237 'public' => true,
238 'show_in_nav_menus' => true,
239 )
240 );
241 foreach ( $taxonomies_list as $slug => $object ) {
242 $taxonomy_list[ $object->name ] = $object->label;
243 }
244 }
245
246 return $taxonomy_list;
247 }
248
249 public function ec_get_taxonomy_list( $taxonomy ) {
250 $terms = get_terms(
251 array(
252 'taxonomy' => $taxonomy,
253 'hide_empty' => false,
254 )
255 );
256
257 $term_list = array();
258 if ( ! empty( $terms ) ) {
259 foreach ( $terms as $term ) {
260 $term_list[ $term->term_id ] = $term->name;
261 }
262 }
263 return $term_list;
264 }
265
266 public function ec_builder_condition_fields( $post ) {
267 // Retrieve existing value from the database
268 $template_type = get_post_meta( $post->ID, 'ecafe_build_template_type', true );
269 $template_display = get_post_meta( $post->ID, 'ecafe_build_template_display', true );
270 $display_singular = get_post_meta( $post->ID, 'ecafe_build_display_singular', true );
271 $display_archives = get_post_meta( $post->ID, 'ecafe_build_display_archives', true );
272
273 $display_prev = get_post_meta( $post->ID, 'ecafe_build_display_prev', true );
274 $options = array(
275 '' => __( 'None', 'essential-classy-addons-for-elementor' ),
276 'header' => __( 'Header', 'essential-classy-addons-for-elementor' ),
277 'footer' => __( 'Footer', 'essential-classy-addons-for-elementor' ),
278 'singular' => __( 'Singular', 'essential-classy-addons-for-elementor' ),
279 'archives' => __( 'Archives', 'essential-classy-addons-for-elementor' ),
280 'page404' => __( '404 Page', 'essential-classy-addons-for-elementor' ),
281 );
282 $get_post_types = $this->ec_get_public_post_types();
283 $get_taxonomies = $this->ec_get_public_taxonomy_list();
284
285 $get_prev = array();
286 if ( $template_type == 'singular' ) {
287 $get_prev = $this->ec_get_posts_list( $display_singular );
288 } elseif ( $template_type == 'archives' ) {
289 $get_prev = $this->ec_get_taxonomy_list( $display_archives );
290 }
291
292 wp_nonce_field( 'ec_template_builder_nonce', 'ec_template_builder_nonce' );
293 ?>
294 <div class="ecafe-build-field-wrap">
295 <div class="ecafe-field-col">
296 <label for="ecafe-build-temp-type"><?php echo esc_html__( 'Template Type :', 'essential-classy-addons-for-elementor' ); ?></label>
297 <select id="ecafe-build-temp-type" name="ecafe_build_template_type">
298 <?php foreach ( $options as $value => $label ) : ?>
299 <option value="<?php echo esc_attr( $value ); ?>" <?php selected( $template_type, $value ); ?>><?php echo esc_html( $label ); ?></option>
300 <?php endforeach; ?>
301 </select>
302 </div>
303 <div class="ecafe-field-col">
304 <label for="ecafe-build-temp-display"><?php echo esc_html__( 'Display :', 'essential-classy-addons-for-elementor' ); ?></label>
305 <select id="ecafe-build-temp-display" name="ecafe_build_template_display">
306 <option value="entire" <?php selected( $template_display, 'entire' ); ?>><?php esc_html_e( 'Entire Website', 'essential-classy-addons-for-elementor' ); ?></option>
307 </select>
308 </div>
309
310 <div class="ecafe-field-col">
311 <label for="ecafe-build-display-singular"><?php echo esc_html__( 'Display :', 'essential-classy-addons-for-elementor' ); ?></label>
312 <select id="ecafe-build-display-singular" name="ecafe_build_display_singular">
313 <?php foreach ( $get_post_types as $post_type => $label ) : ?>
314 <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>
315 <?php endforeach; ?>
316 </select>
317 </div>
318
319 <div class="ecafe-field-col">
320 <label for="ecafe-build-display-archives"><?php echo esc_html__( 'Display :', 'essential-classy-addons-for-elementor' ); ?></label>
321 <select id="ecafe-build-display-archives" name="ecafe_build_display_archives[]" multiple>
322 <?php
323 foreach ( $get_taxonomies as $key => $label ) :
324 $selected = in_array( $key, (array) $display_archives ) ? 'selected' : '';
325 ?>
326 <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>
327 <?php endforeach; ?>
328 </select>
329 </div>
330
331 <div class="ecafe-field-col">
332 <label for="ecafe-build-display-prev"><?php echo esc_html__( 'Preview :', 'essential-classy-addons-for-elementor' ); ?></label>
333 <select id="ecafe-build-display-prev" name="ecafe_build_display_prev">
334 <?php foreach ( $get_prev as $post_type => $label ) : ?>
335 <option value="<?php echo esc_attr( $post_type ); ?>" <?php selected( $display_prev, $post_type ); ?>><?php echo esc_html( $label ); ?></option>
336 <?php endforeach; ?>
337 </select>
338 </div>
339 </div>
340 <?php
341 }
342
343 public function ec_builder_condition_save_meta( $post_id ) {
344 // Check if nonce is set
345 if ( ! isset( $_POST['ec_template_builder_nonce'] ) ) {
346 return;
347 }
348 $ecafe_nonce = isset( $_POST['ec_template_builder_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['ec_template_builder_nonce'] ) ) : '';
349
350 // Verify nonce
351 if ( ! wp_verify_nonce( $ecafe_nonce, 'ec_template_builder_nonce' ) ) {
352 return;
353 }
354 // Check if autosave
355 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
356 return;
357 }
358
359 // Check permissions
360 if ( ! current_user_can( 'edit_post', $post_id ) ) {
361 return;
362 }
363 // Save Theme Builder field data
364 if ( isset( $_POST['ecafe_build_template_type'] ) ) {
365 update_post_meta( $post_id, 'ecafe_build_template_type', sanitize_text_field( wp_unslash( $_POST['ecafe_build_template_type'] ) ) );
366 }
367 if ( isset( $_POST['ecafe_build_template_display'] ) ) {
368 update_post_meta( $post_id, 'ecafe_build_template_display', sanitize_text_field( wp_unslash( $_POST['ecafe_build_template_display'] ) ) );
369 }
370 if ( isset( $_POST['ecafe_build_display_singular'] ) ) {
371 update_post_meta( $post_id, 'ecafe_build_display_singular', sanitize_text_field( wp_unslash( $_POST['ecafe_build_display_singular'] ) ) );
372 }
373 if ( isset( $_POST['ecafe_build_display_archives'] ) && ! empty( $_POST['ecafe_build_display_archives'] ) ) {
374 $display_archives = array_map( 'sanitize_text_field', (array) wp_unslash( $_POST['ecafe_build_display_archives'] ) );
375 update_post_meta( $post_id, 'ecafe_build_display_archives', $display_archives );
376 }
377 if ( isset( $_POST['ecafe_build_display_prev'] ) && ! empty( $_POST['ecafe_build_display_prev'] ) ) {
378 update_post_meta( $post_id, 'ecafe_build_display_prev', sanitize_text_field( wp_unslash( $_POST['ecafe_build_display_prev'] ) ) );
379 }
380 }
381
382 /* Overright Header/Footer Template */
383 public function ec_load_templates() {
384 $curr_temp = basename( get_page_template_slug() );
385
386 if ( $curr_temp == 'elementor_canvas' ) {
387 return;
388 }
389
390 new Ecafe_Theme_Template();
391 }
392
393 /* get Conditional Content*/
394 public function ec_render_builder_data_location( $location ) {
395 $temp = Ecafe_Condition_Rules::get_instance()->ec_get_location_type( $location );
396 if ( $location == 'header' || $location = 'footer' ) {
397 $load_template = $temp;
398 } else {
399 $_key = key( $temp );
400 $load_template = $temp[ $_key ];
401 }
402 return Ec_Template_Builder_Content::get_instance()->ec_get_render_content( $load_template );
403 }
404
405 public function ecafe_single_template_overright( $template ) {
406 if ( is_singular( array_keys( $this->ec_get_public_post_types() ) ) || is_404() ) {
407
408 $location = 'singular';
409 if ( is_404() ) {
410 $location = 'page404';
411 }
412 } elseif ( function_exists( 'is_shop' ) && \is_shop() ) {
413 $location = 'archives';
414 } elseif ( is_archive() || is_tax() || is_home() || is_search() ) {
415 $location = 'archives';
416 }
417
418 if ( ! empty( $location ) ) {
419 $location_documents = Ecafe_Condition_Rules::get_instance()->ec_get_location_type( $location );
420
421 if ( empty( $location_documents ) ) {
422 return $template;
423 }
424
425 if ( 'singular' === $location || 'archives' === $location || 'page404' === $location ) {
426
427 $first_key = key( $location_documents );
428 $theme_document = $location_documents[ $first_key ];
429
430 $templateType = get_post_meta( $theme_document, '_wp_page_template', true );
431
432 $this->singular_template = $theme_document;
433
434 if ( $theme_document ) {
435 switch ( $templateType ) {
436 case 'elementor_canvas':
437 $template = ECAFE_CLASSES_URL . 'builders/singular-canvas.php';
438 break;
439 case 'elementor_header_footer':
440 $template = ECAFE_CLASSES_URL . 'builders/singular-fullwidth.php';
441 break;
442 default:
443 $template = ECAFE_CLASSES_URL . 'builders/singular-fullwidth.php';
444 break;
445 }
446 }
447 }
448 }
449
450 return $template;
451 }
452
453 public function ec_singular_archives_content_render( $post ) {
454 $templates = $this->singular_template;
455 if ( ! empty( $templates ) ) {
456 $allowed_tags = wp_kses_allowed_html( 'post' );
457 $allowed_tags['script'] = array(
458 'type' => true,
459 'src' => true,
460 'defer' => true,
461 );
462 $allowed_tags['style'] = array(
463 'type' => true,
464 'media' => true,
465 );
466 echo Ec_Template_Builder_Content::get_instance()->ec_get_render_content( $templates );
467 } else {
468 the_content();
469 }
470 }
471
472 public function ec_admin_columns_shortcode( $columns ) {
473 $columns['ecafe-shortcode'] = __( 'Shortcode', 'essential-classy-addons-for-elementor' );
474
475 return $columns;
476 }
477
478 public function ec_admin_columns_shortcode_content( $column, $post_id ) {
479 if ( 'ecafe-shortcode' === $column ) {
480 // translator %s = shortcode, %d = post_id
481 $shortcode = esc_attr( sprintf( '[%s id="%d"]', self::Ecafe_Shortcode, $post_id ) );
482 printf( '<input type="text" class="ecafe-shortcode-input" onfocus="this.select()" value="%s" readonly style="font-size: 12px;"/>', esc_attr( $shortcode ) );
483 }
484 }
485
486 public function ec_create_shortcode( $option = array() ) {
487 if ( empty( $option['id'] ) ) {
488 return '';
489 }
490
491 ob_start();
492 echo Ec_Template_Builder_Content::get_instance()->ec_get_render_content( $option['id'] );
493 return ob_get_clean();
494 }
495 }
496
497 Ecafe_Theme_Builder::instance();
498