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
ShopPressWidgets.php
280 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Widgets Base. |
| 4 | * |
| 5 | * @package ShopPress |
| 6 | */ |
| 7 | |
| 8 | namespace ShopPress\Elementor; |
| 9 | |
| 10 | use Elementor\Controls_Manager; |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | abstract class ShopPressWidgets extends ShopPressStyler { |
| 15 | /** |
| 16 | * Enqueue the widget's declared style/script dependencies at render time. |
| 17 | * |
| 18 | * Elementor normally enqueues a widget's get_style_depends()/get_script_depends() |
| 19 | * automatically, but in some frontend render contexts ( e.g. widgets rendered |
| 20 | * inside header/footer or other templates built outside the main loop, and |
| 21 | * under the asset-loading behaviour of newer Elementor versions ) those |
| 22 | * dependencies are not printed - leaving the widget unstyled on the frontend |
| 23 | * while it still looks correct in the editor, where all widget assets load. |
| 24 | * |
| 25 | * Enqueuing the already-registered handles here is idempotent ( a no-op when |
| 26 | * Elementor has already enqueued them ) and guarantees the assets load |
| 27 | * wherever the widget actually renders. |
| 28 | * |
| 29 | * @since 1.5.1 |
| 30 | */ |
| 31 | public function before_render() { |
| 32 | foreach ( (array) $this->get_style_depends() as $style_handle ) { |
| 33 | wp_enqueue_style( $style_handle ); |
| 34 | } |
| 35 | |
| 36 | foreach ( (array) $this->get_script_depends() as $script_handle ) { |
| 37 | wp_enqueue_script( $script_handle ); |
| 38 | } |
| 39 | |
| 40 | parent::before_render(); |
| 41 | } |
| 42 | |
| 43 | public function carousel_options() { |
| 44 | |
| 45 | $this->start_controls_section( |
| 46 | 'carousel_options', |
| 47 | array( |
| 48 | 'label' => __( 'Carousel', 'shop-press' ), |
| 49 | 'tab' => Controls_Manager::TAB_CONTENT, |
| 50 | ) |
| 51 | ); |
| 52 | |
| 53 | $this->add_control( |
| 54 | 'carousel', |
| 55 | array( |
| 56 | 'label' => __( 'Carousel', 'shop-press' ), |
| 57 | 'type' => Controls_Manager::SWITCHER, |
| 58 | 'return_value' => 'true', |
| 59 | 'default' => 'false', |
| 60 | ) |
| 61 | ); |
| 62 | |
| 63 | $this->add_control( |
| 64 | 'carousel_columns', |
| 65 | array( |
| 66 | 'label' => __( 'Carousel Items', 'shop-press' ), |
| 67 | 'type' => Controls_Manager::NUMBER, |
| 68 | 'min' => 1, |
| 69 | 'max' => 12, |
| 70 | 'step' => 1, |
| 71 | 'default' => 4, |
| 72 | 'tablet_default' => 3, |
| 73 | 'mobile_default' => 2, |
| 74 | 'condition' => array( |
| 75 | 'carousel' => 'true', |
| 76 | ), |
| 77 | ) |
| 78 | ); |
| 79 | |
| 80 | $this->add_control( |
| 81 | 'slide_speed', |
| 82 | array( |
| 83 | 'label' => __( 'Slide Speed (ms)', 'shop-press' ), |
| 84 | 'type' => Controls_Manager::NUMBER, |
| 85 | 'default' => 500, |
| 86 | 'min' => 100, |
| 87 | 'max' => 10000, |
| 88 | 'step' => 100, |
| 89 | 'condition' => array( |
| 90 | 'carousel' => 'true', |
| 91 | ), |
| 92 | ) |
| 93 | ); |
| 94 | |
| 95 | $this->add_control( |
| 96 | 'show_controls', |
| 97 | array( |
| 98 | 'label' => __( 'Arrows', 'shop-press' ), |
| 99 | 'type' => Controls_Manager::SWITCHER, |
| 100 | 'label_on' => __( 'Show', 'shop-press' ), |
| 101 | 'label_off' => __( 'Hide', 'shop-press' ), |
| 102 | 'return_value' => 'true', |
| 103 | 'default' => 'true', |
| 104 | 'condition' => array( |
| 105 | 'carousel' => 'true', |
| 106 | ), |
| 107 | ) |
| 108 | ); |
| 109 | |
| 110 | $this->add_control( |
| 111 | 'autoplay', |
| 112 | array( |
| 113 | 'label' => __( 'Autoplay', 'shop-press' ), |
| 114 | 'type' => Controls_Manager::SWITCHER, |
| 115 | 'label_on' => __( 'Yes', 'shop-press' ), |
| 116 | 'label_off' => __( 'No', 'shop-press' ), |
| 117 | 'return_value' => 'true', |
| 118 | 'default' => 'false', |
| 119 | 'condition' => array( |
| 120 | 'carousel' => 'true', |
| 121 | ), |
| 122 | ) |
| 123 | ); |
| 124 | |
| 125 | $this->add_control( |
| 126 | 'autoplay_speed', |
| 127 | array( |
| 128 | 'label' => __( 'Autoplay Speed (ms)', 'shop-press' ), |
| 129 | 'type' => Controls_Manager::NUMBER, |
| 130 | 'default' => 3000, |
| 131 | 'min' => 1000, |
| 132 | 'max' => 10000, |
| 133 | 'step' => 100, |
| 134 | 'condition' => array( |
| 135 | 'carousel' => 'true', |
| 136 | 'autoplay' => 'true', |
| 137 | ), |
| 138 | ) |
| 139 | ); |
| 140 | |
| 141 | $this->add_control( |
| 142 | 'carousel_loop', |
| 143 | array( |
| 144 | 'label' => __( 'Loop', 'shop-press' ), |
| 145 | 'type' => Controls_Manager::SWITCHER, |
| 146 | 'return_value' => 'true', |
| 147 | 'default' => 'true', |
| 148 | 'condition' => array( |
| 149 | 'carousel' => 'true', |
| 150 | ), |
| 151 | ) |
| 152 | ); |
| 153 | |
| 154 | $this->add_control( |
| 155 | 'slider_rows', |
| 156 | array( |
| 157 | 'label' => __( 'Rows', 'shop-press' ), |
| 158 | 'type' => Controls_Manager::NUMBER, |
| 159 | 'default' => 1, |
| 160 | 'min' => 1, |
| 161 | 'max' => 6, |
| 162 | 'step' => 1, |
| 163 | 'condition' => array( |
| 164 | 'carousel' => 'true', |
| 165 | ), |
| 166 | ) |
| 167 | ); |
| 168 | |
| 169 | $this->end_controls_section(); |
| 170 | } |
| 171 | |
| 172 | public function carousel_stylers() { |
| 173 | $this->register_group_styler( |
| 174 | 'owl_arrow', |
| 175 | __( 'Carousel Arrows', 'shop-press' ), |
| 176 | array( |
| 177 | 'prev_arrow' => array( |
| 178 | 'label' => esc_html__( 'Prev Arrow', 'shop-press' ), |
| 179 | 'type' => 'styler', |
| 180 | 'selector' => 'button.slick-prev', |
| 181 | 'wrapper' => '{{WRAPPER}} .sp-slider-style', |
| 182 | ), |
| 183 | 'next_arrow' => array( |
| 184 | 'label' => esc_html__( 'Next Arrow', 'shop-press' ), |
| 185 | 'type' => 'styler', |
| 186 | 'selector' => 'button.slick-next', |
| 187 | 'wrapper' => '{{WRAPPER}} .sp-slider-style', |
| 188 | ), |
| 189 | ), |
| 190 | array( |
| 191 | 'carousel' => 'true' ?? array(), |
| 192 | ) |
| 193 | ); |
| 194 | } |
| 195 | |
| 196 | public function custom_heading_stylers() { |
| 197 | $this->register_group_styler( |
| 198 | 'reviews_custom_heading', |
| 199 | __( 'Heading', 'shop-press' ), |
| 200 | array( |
| 201 | 'reviews_custom_heading' => array( |
| 202 | 'label' => esc_html__( 'Custom Heading', 'shop-press' ), |
| 203 | 'type' => 'styler', |
| 204 | 'selector' => '.sp-products-heading', |
| 205 | 'wrapper' => '{{WRAPPER}}', |
| 206 | ), |
| 207 | ), |
| 208 | ); |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * Returns Woo categories. |
| 213 | * |
| 214 | * @since 1.4.7 |
| 215 | * |
| 216 | * @return array |
| 217 | */ |
| 218 | public function get_categories_for_select_option() { |
| 219 | $categories = get_terms( array( 'taxonomy' => 'product_cat' ) ); |
| 220 | |
| 221 | $cats = array(); |
| 222 | $cat_slug = array(); |
| 223 | $cat_name = array(); |
| 224 | if ( $categories ) { |
| 225 | foreach ( $categories as $cat ) { |
| 226 | $cat_slug[] = $cat->slug; |
| 227 | $cat_name[] = $cat->name; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | if ( $cat_slug && $cat_name ) { |
| 232 | $cats = array_combine( $cat_name, $cat_slug ); |
| 233 | } |
| 234 | |
| 235 | return $cats; |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * Returns all image sizes. |
| 240 | * |
| 241 | * @since 1.3.5 |
| 242 | * |
| 243 | * @return array |
| 244 | */ |
| 245 | public static function get_all_image_sizes() { |
| 246 | global $_wp_additional_image_sizes; |
| 247 | |
| 248 | $default_image_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' ); |
| 249 | |
| 250 | $image_sizes = array(); |
| 251 | |
| 252 | foreach ( $default_image_sizes as $size ) { |
| 253 | $width = (int) get_option( $size . '_size_w' ); |
| 254 | $height = (int) get_option( $size . '_size_h' ); |
| 255 | $crop = (bool) get_option( $size . '_crop' ); |
| 256 | $image_sizes[ $size ] = array( |
| 257 | 'width' => $width, |
| 258 | 'height' => $height, |
| 259 | 'crop' => $crop, |
| 260 | ); |
| 261 | } |
| 262 | |
| 263 | if ( $_wp_additional_image_sizes ) { |
| 264 | $image_sizes = array_merge( $image_sizes, $_wp_additional_image_sizes ); |
| 265 | } |
| 266 | |
| 267 | foreach ( $image_sizes as $size => $image_size ) { |
| 268 | $size_text = "{$image_size['width']}x{$image_size['height']}"; |
| 269 | $title = ucfirst( str_replace( '_', ' ', $size ) ); |
| 270 | if ( $size_text !== $title ) { |
| 271 | $title .= ' ' . $size_text; |
| 272 | } |
| 273 | |
| 274 | $image_sizes[ $size ]['title'] = $title; |
| 275 | } |
| 276 | |
| 277 | return $image_sizes; |
| 278 | } |
| 279 | } |
| 280 |