PluginProbe ʕ •ᴥ•ʔ
ShopPress – Shop Builder for Elementor and WooCommerce / trunk
ShopPress – Shop Builder for Elementor and WooCommerce vtrunk
shop-press / Elementor / ShopPressStyler.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
ShopPressStyler.php
147 lines
1 <?php
2 /**
3 * Styler.
4 *
5 * @package ShopPress
6 */
7
8 namespace ShopPress\Elementor;
9
10 defined( 'ABSPATH' ) || exit;
11
12 use Elementor\Plugin;
13 use Elementor\Widget_Base;
14 use Elementor\Controls_Manager;
15
16 abstract class ShopPressStyler extends Widget_Base {
17 /**
18 * Is Elementor Editor.
19 *
20 * @return boolean
21 */
22 public function is_editor() {
23 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Preview flag for editor detection, no form processing.
24 return Plugin::$instance->editor->is_edit_mode()
25 ||
26 ( in_array( get_post_type(), array( 'shoppress_pages', 'shoppress_loop' ), true ) && isset( $_GET['preview'] ) );
27 }
28
29 /**
30 * Preview in editor
31 *
32 * @since 1.0.0
33 *
34 * @return bool
35 */
36 public function editor_preview() {
37
38 if ( ! $this->is_editor() && 'product' !== get_post_type() ) {
39 return false;
40 }
41
42 return true;
43 }
44
45 /**
46 * Preview in checkout editor
47 *
48 * @since 1.0.0
49 *
50 * @return bool
51 */
52 public function checkout_editor_preview() {
53
54 if ( ! $this->is_editor() && ! is_checkout() ) {
55 return false;
56 }
57
58 if ( $this->is_editor() ) {
59 if ( empty( WC()->cart ) ) {
60 return false;
61 }
62 }
63
64 return true;
65 }
66
67 /**
68 * Register Grouped styler controls
69 *
70 * @since 1.0.0
71 *
72 * @param string $id
73 * @param string $sec_label
74 * @param array $fields = array( 'icon_box_title' => array( 'label' => '', 'selector' => '', 'wrapper' => '', 'condition' => array() ), );
75 * @param array $condition
76 *
77 * @return void
78 */
79 public function register_group_styler( $sec_id, $sec_label, $fields, $condition = array() ) {
80
81 $this->start_controls_section(
82 $sec_id . '_styler_section',
83 array(
84 'label' => $sec_label,
85 'tab' => Controls_Manager::TAB_STYLE,
86 'condition' => $condition,
87 )
88 );
89
90 foreach ( $fields as $id => $item ) {
91 $base_name = ( $sec_id === $id && 1 === count( $fields ) ) ? 'styler_' . $id : 'styler_' . $sec_id . '_' . $id;
92 $control_name = $base_name;
93 $controls = $this->get_controls();
94 $counter = 1;
95 while ( isset( $controls[ $control_name ] ) ) {
96 $control_name = $base_name . '_' . $counter;
97 ++$counter;
98 }
99
100 $this->add_control(
101 $control_name,
102 array(
103 'label' => esc_html( $item['label'] ),
104 'type' => 'styler',
105 'selector' => isset( $item['selector'] ) ? $item['selector'] : '{{WRAPPER}}', // example '.styler-test-text',
106 'wrapper' => isset( $item['wrapper'] ) ? $item['wrapper'] : '{{WRAPPER}}', // example '{{WRAPPER}}',
107 'condition' => isset( $item['condition'] ) ? $item['condition'] : array(), // array()
108 'separator' => isset( $item['separator'] ) ? $item['separator'] : '', // array()
109 'isSVG' => true,
110 )
111 );
112 }
113
114 $this->end_controls_section();
115 }
116
117 /**
118 * Register a styler controls
119 *
120 * @since 1.0.0
121 *
122 * @param string $id
123 * @param string $label
124 * @param string $selector
125 * @param string $wrapper
126 * @param array $condition
127 * @param string $hover
128 *
129 * @return void
130 */
131 public function register_styler( $id, $label, $selector, $wrapper, $condition = array(), $hover = '' ) {
132
133 $this->add_control(
134 'styler_' . $id,
135 array(
136 'label' => esc_html( $label ),
137 'type' => 'styler',
138 'selector' => $selector, // example '.styler-test-text',
139 'hover' => isset( $hover ) ? $hover : $selector, // example '.styler-test-text',
140 'wrapper' => $wrapper, // example '{{WRAPPER}}',
141 'condition' => $condition, // array()
142 'isSVG' => true,
143 )
144 );
145 }
146 }
147