PluginProbe ʕ •ᴥ•ʔ
Essential Classy Addons for Elementor – 150+ Widgets, Templates & Performance Tools / 3.0.27
Essential Classy Addons for Elementor – 150+ Widgets, Templates & Performance Tools v3.0.27
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 / documents / class-ele-builder-documents.php
essential-classy-addons-for-elementor / classes / documents Last commit date
class-ele-builder-document-base.php 1 year ago class-ele-builder-documents.php 1 year ago class-ele-document-singular.php 1 year ago
class-ele-builder-documents.php
234 lines
1 <?php
2 /**
3 * Essential Classy Addons For Elementor Documents
4 *
5 * @package Ecafe
6 * @since 3.0.24
7 */
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 if( ! class_exists( 'Ecafe_Elementor_Builder_Documents' ) ) {
13 class Ecafe_Elementor_Builder_Documents {
14
15 /**
16 * Instance
17 */
18 private static $instance;
19
20 /**
21 * Document Type Singular/Archives
22 */
23 protected $doc_type = null;
24
25 /**
26 * Initiator
27 */
28 public static function get_instance() {
29 if ( ! isset( self::$instance ) ) {
30 self::$instance = new self();
31 }
32 return self::$instance;
33 }
34
35 /**
36 * Constructor
37 */
38 public function __construct() {
39
40 add_action( 'elementor/documents/register', [ $this, 'ec_register_elementor_documents' ] );
41
42 add_action( 'elementor/template-library/before_get_source_data', [ $this, 'ec_preview_query_switch' ] );
43 add_action( 'elementor/template-library/after_get_source_data', [ $this, 'ec_current_query_restore' ] );
44 add_action( 'elementor/dynamic_tags/before_render', [ $this, 'ec_preview_query_switch' ] );
45 add_action( 'elementor/dynamic_tags/after_render', [ $this, 'ec_current_query_restore' ] );
46
47 add_filter( 'post_class', array( $this, 'ec_set_post_class' ) );
48 add_filter( 'body_class', array( $this, 'ec_set_body_class' ) );
49 add_filter( 'the_content', array( $this, 'ec_add_post_product_wrapper' ), 1000000 );
50 }
51
52 /**
53 * Add product wrapper to content
54 */
55 public function ec_add_post_product_wrapper( $content ) {
56
57 if ( is_singular( ECAFE_POST ) && isset( $_GET['elementor-preview'] ) ) {
58 $content = sprintf( '<div class="product">%s</div>', $content );
59 }
60
61 return $content;
62 }
63
64 /**
65 * Register appropriate document types for 'ec_theme_builder' post type
66 *
67 * @param Elementor\Core\Documents_Manager $documents_manager [description]
68 *
69 */
70 public function ec_register_elementor_documents( $documents_manager ){
71
72 $doc_path = ECAFE_CLASSES_URL . 'documents/';
73 require $doc_path. 'class-ele-builder-document-base.php';
74 require $doc_path . 'class-ele-document-singular.php';
75
76 $documents_manager->register_document_type( 'ec_theme_builder', 'Ecafe_Ele_Document' );
77
78 }
79
80 /**
81 * Add 'product' class
82 */
83 public function ec_set_post_class( $classes ) {
84
85 if ( is_singular( ECAFE_POST ) ) {
86 $classes[] = 'product';
87 }
88
89 return $classes;
90 }
91
92 /**
93 * Add 'single-product' class to body on build post
94 */
95 public function ec_set_body_class( $classes ) {
96
97 if ( is_singular( ECAFE_POST ) ) {
98 $classes[] = 'woocommerce single-product';
99 }
100
101 return $classes;
102 }
103
104 /**
105 * Set document type
106 */
107 public function set_current_type( $type ) {
108 $this->doc_type = $type;
109 }
110
111 /**
112 * Get document type
113 */
114 public function get_current_type() {
115 return $this->doc_type;
116 }
117
118
119 /**
120 * Preview query switch
121 */
122 public function ec_preview_query_switch() {
123
124 $post_id = get_the_ID();
125 $document = Elementor\Plugin::instance()->documents->get_doc_or_auto_save( $post_id );
126
127 if ( ! is_object( $document ) ) {
128 return null;
129 }
130
131 $new_query = $this->ec_get_args_preview_query();
132
133 if ( empty( $new_query ) ) {
134 return null;
135 }
136
137 Elementor\Plugin::instance()->db->switch_to_query( $new_query );
138 }
139
140 /**
141 * Restore default query
142 */
143 public function ec_current_query_restore() {
144 Elementor\Plugin::instance()->db->restore_current_query();
145 }
146
147 public function preview_post_setting( $parent_post_id = '' ){
148 $preview = [];
149 if( empty( $parent_post_id )){
150 $post_id = get_the_ID();
151 }else{
152 $post_id = $parent_post_id;
153 }
154
155 if ( get_post_type() == ECAFE_POST ) {
156 $template_type = get_post_meta( $post_id, 'ecafe_build_template_type', true );
157 if( $template_type == 'singular' ){
158 $singular_prev_type = get_post_meta( $post_id, 'ecafe_build_display_singular', true );
159 $singular_prev_id = get_post_meta( $post_id, 'ecafe_build_display_prev', true );
160 if( !empty($singular_prev_type) && !empty($singular_prev_id)){
161 $preview['type'] = 'singular';
162 $preview['preview_type'] = $singular_prev_type;
163 $preview['preview_id'] = $singular_prev_id;
164 $preview['preview_url'] = get_permalink( $singular_prev_id );
165 }
166 }else if( $template_type == 'archives' ){
167 $archive_prev_type = get_post_meta( $post_id, 'ecafe_build_display_archives', true );
168 $archive_prev_id = get_post_meta( $post_id, 'ecafe_build_display_prev', true );
169 if( !empty($archive_prev_type) && !empty($archive_prev_id)){
170 $preview['type'] = 'archives';
171 $preview['preview_type'] = $archive_prev_type;
172 $preview['preview_id'] = $archive_prev_id;
173 $preview['preview_url'] = get_category_link( $archive_prev_id );
174 }
175 }
176 }
177
178 return $preview;
179 }
180
181 public function ec_get_args_preview_query() {
182 $prev_data = $this->preview_post_setting();
183 $preview_id = '';
184 if( !empty( $prev_data ) && !empty( $prev_data['preview_id'] ) ){
185 $preview_id = $prev_data['preview_id'];
186 }
187
188 $args = [];
189 if( isset( $prev_data['type'] ) && !empty( $prev_data['type'] ) ){
190 switch ( $prev_data['type'] ) {
191 case 'singular':
192 $post = get_post( $preview_id );
193 if ( ! $post ) {
194 break;
195 }
196
197 $args = [
198 'p' => $post->ID,
199 'post_type' => $post->post_type,
200 ];
201 break;
202 case 'archives':
203 switch ( $prev_data['preview_type'] ) {
204 default:
205 $get_term = get_term( $preview_id );
206
207 if ( $get_term && ! is_wp_error( $get_term ) ) {
208 $args = [
209 'tax_query' => [
210 [
211 'taxonomy' => $get_term->taxonomy,
212 'terms' => [ $preview_id ],
213 'field' => 'id',
214 ],
215 ],
216 ];
217 }
218 break;
219 }
220 break;
221 }
222 }
223
224 if ( empty( $args ) ) {
225 $args = [
226 'p' => get_the_ID(),
227 'post_type' => get_post_type(),
228 ];
229 }
230
231 return $args;
232 }
233 }
234 }