PluginProbe ʕ •ᴥ•ʔ
ShopPress – Shop Builder for Elementor and WooCommerce / trunk
ShopPress – Shop Builder for Elementor and WooCommerce vtrunk
shop-press / Elementor / EditorCondition.php
shop-press / Elementor Last commit date
control 2 weeks ago template-library 2 weeks ago widgets 2 weeks ago ControlsWidgets.php 2 weeks ago EditorCondition.php 2 weeks ago EditorScripts.php 1 year ago Integration.php 1 year ago RegisterWidgets.php 1 year ago ShopPressStyler.php 2 weeks ago ShopPressWidgets.php 2 weeks ago
EditorCondition.php
386 lines
1 <?php
2 /**
3 * Editor Condition.
4 *
5 * @package ShopPress
6 */
7
8 namespace ShopPress\Elementor;
9
10 defined( 'ABSPATH' ) || exit;
11
12 use Elementor\Plugin;
13
14 class EditorCondition {
15 /**
16 * Post type
17 *
18 * @var string
19 */
20 private static $post_type = '';
21
22 /**
23 * Custom type meta
24 *
25 * @var mixed
26 */
27 private static $custom_type_meta = '';
28
29 /**
30 * Page ID
31 *
32 * @var string
33 */
34 private static $page_id = '';
35
36 /**
37 * Retrieves the post type of the current post.
38 *
39 * @since 1.2.0
40 *
41 * @return string The post type of the current post.
42 */
43 private static function get_post_type() {
44
45 if ( empty( self::$post_type ) ) {
46 self::$post_type = get_post_type();
47 }
48
49 return self::$post_type;
50 }
51
52 /**
53 * Retrieves the custom type meta for the current page.
54 *
55 * @since 1.2.0
56 *
57 * @return string The custom type meta for the current page.
58 */
59 private static function get_custom_type_meta() {
60
61 if ( empty( self::$page_id ) ) {
62 self::$page_id = get_the_ID();
63 }
64
65 if ( empty( self::$custom_type_meta ) ) {
66 self::$custom_type_meta = get_post_meta( self::$page_id, 'custom_type', true );
67 }
68
69 return self::$custom_type_meta;
70 }
71
72 /**
73 * Check the custom type of the given editor.
74 *
75 * @since 1.2.0
76 *
77 * @param string $editor The editor to check.
78 *
79 * @return bool
80 */
81 private static function check_custom_type( $editor ) {
82 return ( in_array( $editor, (array) self::get_custom_type_meta(), true ) );
83 }
84
85 /**
86 * Check if is elementor edit mode.
87 *
88 * @since 1.2.0
89 *
90 * @return bool
91 */
92 private static function is_edit_mode() {
93 return Plugin::$instance->editor->is_edit_mode();
94 }
95
96 /**
97 * Determine if the current page is a products page.
98 *
99 * @since 1.2.0
100 *
101 * @return bool
102 */
103 private static function is_products() {
104 $type = self::get_custom_type_meta();
105 return (
106 is_shop()
107 ||
108 in_array( $type, array( 'shop', 'archive', 'single' ) )
109 ||
110 (
111 in_array( self::get_post_type(), array( 'page', 'post', 'product' ) )
112 &&
113 ! in_array( $type, array( 'cart', 'checkout' ) )
114 )
115 );
116 }
117
118 /**
119 * Returns true for all types of editors.
120 *
121 * @since 1.2.0
122 *
123 * @return bool
124 */
125 private static function is_general() {
126 return true;
127 }
128
129 /**
130 * Determine if is a page or post.
131 *
132 * @since 1.2.0
133 *
134 * @return bool
135 */
136 private static function is_page_or_post() {
137 return in_array( self::get_post_type(), array( 'page', 'post' ) );
138 }
139
140 /**
141 * Determine if the current page is a shop page.
142 *
143 * @since 1.2.0
144 *
145 * @return bool
146 */
147 private static function is_shop() {
148 return (
149 in_array( self::get_custom_type_meta(), array( 'shop', 'archive' ) ) ||
150 is_shop() ||
151 is_product_category() ||
152 is_product_tag() ||
153 is_tax()
154 );
155 }
156
157 /**
158 * Determine if the current page is a archive page.
159 *
160 * @since 1.4.3
161 *
162 * @return bool
163 */
164 private static function is_archive() {
165 return (
166 in_array( self::get_custom_type_meta(), array( 'archive' ) ) ||
167 is_product_category() ||
168 is_product_tag()
169 );
170 }
171
172 /**
173 * Determine if the current page is a loop page.
174 *
175 * @since 1.2.0
176 *
177 * @return bool
178 */
179 private static function is_loop() {
180
181 if ( self::get_post_type() === 'shoppress_loop' ) {
182 return true;
183 }
184
185 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Elementor verifies nonce in its AJAX handler.
186 return (
187 ( false === self::is_edit_mode() || ( isset( $_POST['action'] ) && 'elementor_ajax' === sanitize_text_field( wp_unslash( $_POST['action'] ) ) ) ) &&
188 ( self::is_general() || self::is_single() || self::is_shop()
189 ) );
190 }
191
192 /**
193 * Determine if the current page is a single page.
194 *
195 * @since 1.2.0
196 *
197 * @return bool
198 */
199 private static function is_wishlist() {
200 return self::check_custom_type( 'wishlist' ) || self::check_custom_type( 'my_account_wishlist' ) || is_sp_wishlist_page() || is_page();
201 }
202
203 /**
204 * Determine if the current page is a compare page.
205 *
206 * @since 1.2.0
207 *
208 * @return bool
209 */
210 private static function is_compare() {
211 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Action used for conditional check only; Compare AJAX verifies nonce separately.
212 $action = isset( $_REQUEST['action'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['action'] ) ) : false;
213 return self::check_custom_type( 'compare' ) || is_sp_compare_page() || in_array( $action, array( 'AddCompare', 'RemoveCompare' ), true );
214 }
215
216 /**
217 * Determine if the current page is a cart page.
218 *
219 * @since 1.2.0
220 *
221 * @return bool
222 */
223 private static function is_cart() {
224 return self::check_custom_type( 'cart' ) || is_cart();
225 }
226
227 /**
228 * Determine if the current page is a empty cart page.
229 *
230 * @since 1.2.0
231 *
232 * @return bool
233 */
234 private static function is_empty_cart() {
235 return self::check_custom_type( 'empty_cart' ) || is_cart();
236 }
237
238 /**
239 * Determine if the current page is a single page.
240 *
241 * @since 1.2.0
242 *
243 * @return bool
244 */
245 private static function is_checkout() {
246 return self::check_custom_type( 'checkout' ) || is_checkout();
247 }
248
249 /**
250 * Determine if the current page is a thank you page.
251 *
252 * @since 1.2.0
253 *
254 * @return bool
255 */
256 private static function is_thank_you() {
257 return self::check_custom_type( 'thank_you' ) || is_checkout();
258 }
259
260 /**
261 * Determine if the current page is a single page.
262 *
263 * @since 1.2.0
264 *
265 * @return bool
266 */
267 private static function is_my_account() {
268 return self::check_custom_type( 'my_account' ) || is_account_page();
269 }
270
271 /**
272 * Determine if the current page is a dashboard page.
273 *
274 * @since 1.2.0
275 *
276 * @return bool
277 */
278 private static function is_dashboard() {
279 return self::check_custom_type( 'dashboard' ) || is_account_page();
280 }
281
282 /**
283 * Determine if the current page is a account details page.
284 *
285 * @since 1.2.0
286 *
287 * @return bool
288 */
289 private static function is_account_details() {
290 return self::check_custom_type( 'account_details' ) || is_account_page();
291 }
292
293 /**
294 * Determine if the current page is a orders page.
295 *
296 * @since 1.2.0
297 *
298 * @return bool
299 */
300 private static function is_orders() {
301 return self::check_custom_type( 'orders' ) || is_account_page();
302 }
303
304 /**
305 * Determine if the current page is a login page.
306 *
307 * @since 1.4.0
308 *
309 * @return bool
310 */
311 private static function is_login_register_form() {
312 return self::check_custom_type( 'login_register_form' ) || is_account_page();
313 }
314
315 /**
316 * Determine if the current page is a downloads page.
317 *
318 * @since 1.2.0
319 *
320 * @return bool
321 */
322 private static function is_downloads() {
323 return self::check_custom_type( 'downloads' ) || is_account_page();
324 }
325
326 /**
327 * Determine if the current page is a addresses page.
328 *
329 * @since 1.2.0
330 *
331 * @return bool
332 */
333 private static function is_addresses() {
334 return self::check_custom_type( 'addresses' ) || is_account_page();
335 }
336
337 /**
338 * Determine if the current page is a user notifications page.
339 *
340 * @since 1.2.0
341 *
342 * @return bool
343 */
344 private static function is_notifications() {
345 return self::check_custom_type( 'my_account_notifications' ) || is_account_page();
346 }
347
348 /**
349 * Determine if the current page is a single or quick view page.
350 *
351 * @since 1.2.0
352 *
353 * @return bool
354 */
355 private static function is_single() {
356 return (
357 ( self::check_custom_type( 'single' ) || is_product() ) ||
358 ( self::check_custom_type( 'quick_view' ) || is_sp_quick_view_ajax() )
359 );
360 }
361
362 /**
363 * Checks the current editor page.
364 *
365 * @since 1.2.0
366 *
367 * @param string $editor The editor page to check.
368 *
369 * @return bool
370 */
371 public static function is_editor_page( $editor ) {
372
373 if ( self::get_post_type() === 'elementor_library' ) {
374 return true;
375 }
376
377 $method = "is_{$editor}";
378
379 if ( method_exists( __CLASS__, $method ) ) {
380 return self::$method();
381 }
382
383 return false;
384 }
385 }
386