| 1 |
<?php |
| 2 |
|
| 3 |
namespace UltimateStoreKit\Modules\BrandGrid\Widgets; |
| 4 |
|
| 5 |
use UltimateStoreKit\Base\Module_Base; |
| 6 |
use Elementor\Group_Control_Css_Filter; |
| 7 |
use Elementor\Repeater; |
| 8 |
use Elementor\Controls_Manager; |
| 9 |
use Elementor\Group_Control_Box_Shadow; |
| 10 |
use Elementor\Group_Control_Image_Size; |
| 11 |
use Elementor\Group_Control_Background; |
| 12 |
use Elementor\Group_Control_Border; |
| 13 |
use Elementor\Utils; |
| 14 |
|
| 15 |
if (!defined('ABSPATH')) { |
| 16 |
exit; |
| 17 |
} // Exit if accessed directly |
| 18 |
|
| 19 |
class Brand_Grid extends Module_Base { |
| 20 |
|
| 21 |
public function get_name() { |
| 22 |
return 'usk-brand-grid'; |
| 23 |
} |
| 24 |
|
| 25 |
public function get_title() { |
| 26 |
return esc_html__('Brand Grid', 'ultimate-store-kit'); |
| 27 |
} |
| 28 |
|
| 29 |
public function get_icon() { |
| 30 |
return 'usk-widget-icon usk-icon-brand-grid'; |
| 31 |
} |
| 32 |
|
| 33 |
public function get_categories() { |
| 34 |
return ['ultimate-store-kit']; |
| 35 |
} |
| 36 |
|
| 37 |
public function get_keywords() { |
| 38 |
return ['brand', 'grid', 'client', 'logo', 'showcase']; |
| 39 |
} |
| 40 |
|
| 41 |
public function get_style_depends() { |
| 42 |
if ($this->usk_is_edit_mode()) { |
| 43 |
return ['usk-styles']; |
| 44 |
} else { |
| 45 |
return ['usk-brand-grid']; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
// public function get_custom_help_url() { |
| 50 |
// return 'https://youtu.be/a_wJL950Kz4'; |
| 51 |
// } |
| 52 |
|
| 53 |
protected function register_controls() { |
| 54 |
|
| 55 |
$this->start_controls_section( |
| 56 |
'section_layout', |
| 57 |
[ |
| 58 |
'label' => __('Layout', 'ultimate-store-kit'), |
| 59 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 60 |
] |
| 61 |
); |
| 62 |
|
| 63 |
$this->add_responsive_control( |
| 64 |
'columns', |
| 65 |
[ |
| 66 |
'label' => __('Columns', 'ultimate-store-kit'), |
| 67 |
'type' => Controls_Manager::SELECT, |
| 68 |
'default' => 4, |
| 69 |
'tablet_default' => 2, |
| 70 |
'mobile_default' => 1, |
| 71 |
'options' => [ |
| 72 |
1 => '1', |
| 73 |
2 => '2', |
| 74 |
3 => '3', |
| 75 |
4 => '4', |
| 76 |
5 => '5', |
| 77 |
6 => '6', |
| 78 |
], |
| 79 |
'selectors' => [ |
| 80 |
'{{WRAPPER}} .usk-brand-grid' => 'grid-template-columns: repeat({{SIZE}}, 1fr);', |
| 81 |
], |
| 82 |
] |
| 83 |
); |
| 84 |
|
| 85 |
$this->add_responsive_control( |
| 86 |
'column_gap', |
| 87 |
[ |
| 88 |
'label' => esc_html__('Column Gap', 'ultimate-store-kit'), |
| 89 |
'type' => Controls_Manager::SLIDER, |
| 90 |
'default' => [ |
| 91 |
'size' => 20, |
| 92 |
], |
| 93 |
'selectors' => [ |
| 94 |
'{{WRAPPER}} .usk-brand-grid' => 'grid-column-gap: {{SIZE}}{{UNIT}};', |
| 95 |
], |
| 96 |
] |
| 97 |
); |
| 98 |
|
| 99 |
$this->add_responsive_control( |
| 100 |
'row_gap', |
| 101 |
[ |
| 102 |
'label' => esc_html__('Row Gap', 'ultimate-store-kit'), |
| 103 |
'type' => Controls_Manager::SLIDER, |
| 104 |
'default' => [ |
| 105 |
'size' => 20, |
| 106 |
], |
| 107 |
'selectors' => [ |
| 108 |
'{{WRAPPER}} .usk-brand-grid' => 'grid-row-gap: {{SIZE}}{{UNIT}};', |
| 109 |
], |
| 110 |
] |
| 111 |
); |
| 112 |
|
| 113 |
$this->end_controls_section(); |
| 114 |
|
| 115 |
$this->start_controls_section( |
| 116 |
'usk_section_brands', |
| 117 |
[ |
| 118 |
'label' => __('Brand Items', 'ultimate-store-kit'), |
| 119 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 120 |
] |
| 121 |
); |
| 122 |
|
| 123 |
$repeater = new Repeater(); |
| 124 |
|
| 125 |
$repeater->add_control( |
| 126 |
'image', |
| 127 |
[ |
| 128 |
'label' => __('Brand Image', 'ultimate-store-kit'), |
| 129 |
'type' => Controls_Manager::MEDIA, |
| 130 |
'default' => [ |
| 131 |
'url' => Utils::get_placeholder_image_src(), |
| 132 |
], |
| 133 |
] |
| 134 |
); |
| 135 |
|
| 136 |
$repeater->add_control( |
| 137 |
'brand_name', |
| 138 |
[ |
| 139 |
'label' => __('Brand Name', 'ultimate-store-kit'), |
| 140 |
'type' => Controls_Manager::TEXT, |
| 141 |
'default' => __('Brand Name', 'ultimate-store-kit'), |
| 142 |
'label_block' => true, |
| 143 |
'dynamic' => ['active' => true], |
| 144 |
] |
| 145 |
); |
| 146 |
|
| 147 |
$repeater->add_control( |
| 148 |
'link', |
| 149 |
[ |
| 150 |
'label' => __('Url', 'ultimate-store-kit'), |
| 151 |
'type' => Controls_Manager::URL, |
| 152 |
'placeholder' => __('https://your-link.com', 'plugin-domain'), |
| 153 |
'show_external' => true, |
| 154 |
'default' => [ |
| 155 |
'url' => '#', |
| 156 |
'is_external' => true, |
| 157 |
'nofollow' => true, |
| 158 |
], |
| 159 |
'label_block' => true, |
| 160 |
'dynamic' => ['active' => true], |
| 161 |
] |
| 162 |
); |
| 163 |
|
| 164 |
$this->add_control( |
| 165 |
'brand_items', |
| 166 |
[ |
| 167 |
'show_label' => false, |
| 168 |
'type' => Controls_Manager::REPEATER, |
| 169 |
'fields' => $repeater->get_controls(), |
| 170 |
'title_field' => '{{{ name }}}', |
| 171 |
'default' => [ |
| 172 |
['image' => ['url' => Utils::get_placeholder_image_src()]], |
| 173 |
['image' => ['url' => Utils::get_placeholder_image_src()]], |
| 174 |
['image' => ['url' => Utils::get_placeholder_image_src()]], |
| 175 |
['image' => ['url' => Utils::get_placeholder_image_src()]], |
| 176 |
['image' => ['url' => Utils::get_placeholder_image_src()]], |
| 177 |
['image' => ['url' => Utils::get_placeholder_image_src()]], |
| 178 |
['image' => ['url' => Utils::get_placeholder_image_src()]], |
| 179 |
['image' => ['url' => Utils::get_placeholder_image_src()]], |
| 180 |
] |
| 181 |
] |
| 182 |
); |
| 183 |
|
| 184 |
$this->add_group_control( |
| 185 |
Group_Control_Image_Size::get_type(), |
| 186 |
[ |
| 187 |
'name' => 'thumbnail', |
| 188 |
'default' => 'medium', |
| 189 |
'separator' => 'before', |
| 190 |
'exclude' => ['custom'] |
| 191 |
] |
| 192 |
); |
| 193 |
|
| 194 |
$this->end_controls_section(); |
| 195 |
|
| 196 |
//Style |
| 197 |
$this->start_controls_section( |
| 198 |
'section_style_items', |
| 199 |
[ |
| 200 |
'label' => __('Items', 'ultimate-store-kit'), |
| 201 |
'tab' => Controls_Manager::TAB_STYLE, |
| 202 |
] |
| 203 |
); |
| 204 |
|
| 205 |
$this->start_controls_tabs('tabs_item_style'); |
| 206 |
|
| 207 |
$this->start_controls_tab( |
| 208 |
'tab_item_normal', |
| 209 |
[ |
| 210 |
'label' => esc_html__('Normal', 'ultimate-store-kit'), |
| 211 |
] |
| 212 |
); |
| 213 |
|
| 214 |
$this->add_group_control( |
| 215 |
Group_Control_Background::get_type(), |
| 216 |
[ |
| 217 |
'name' => 'item_background', |
| 218 |
'selector' => '{{WRAPPER}} .usk-brand-grid-item', |
| 219 |
] |
| 220 |
); |
| 221 |
|
| 222 |
$this->add_group_control( |
| 223 |
Group_Control_Border::get_type(), |
| 224 |
[ |
| 225 |
'name' => 'item_border', |
| 226 |
'label' => esc_html__('Border', 'bdthemes-element-pack'), |
| 227 |
'fields_options' => [ |
| 228 |
'border' => [ |
| 229 |
'default' => 'solid', |
| 230 |
], |
| 231 |
'width' => [ |
| 232 |
'default' => [ |
| 233 |
'top' => '1', |
| 234 |
'right' => '1', |
| 235 |
'bottom' => '1', |
| 236 |
'left' => '1', |
| 237 |
'isLinked' => false, |
| 238 |
], |
| 239 |
], |
| 240 |
'color' => [ |
| 241 |
'default' => '#dbdbdb', |
| 242 |
], |
| 243 |
], |
| 244 |
'selector' => '{{WRAPPER}} .usk-brand-grid-item', |
| 245 |
'separator' => 'before', |
| 246 |
] |
| 247 |
); |
| 248 |
|
| 249 |
$this->add_responsive_control( |
| 250 |
'item_border_radius', |
| 251 |
[ |
| 252 |
'label' => esc_html__('Border Radius', 'ultimate-store-kit'), |
| 253 |
'type' => Controls_Manager::DIMENSIONS, |
| 254 |
'size_units' => ['px', 'em', '%'], |
| 255 |
'selectors' => [ |
| 256 |
'{{WRAPPER}} .usk-brand-grid-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 257 |
], |
| 258 |
] |
| 259 |
); |
| 260 |
|
| 261 |
$this->add_responsive_control( |
| 262 |
'item_padding', |
| 263 |
[ |
| 264 |
'label' => esc_html__('Padding', 'ultimate-store-kit'), |
| 265 |
'type' => Controls_Manager::DIMENSIONS, |
| 266 |
'size_units' => ['px', 'em', '%'], |
| 267 |
'selectors' => [ |
| 268 |
'{{WRAPPER}} .usk-brand-grid-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 269 |
], |
| 270 |
] |
| 271 |
); |
| 272 |
|
| 273 |
$this->add_group_control( |
| 274 |
Group_Control_Box_Shadow::get_type(), |
| 275 |
[ |
| 276 |
'name' => 'item_box_shadow', |
| 277 |
'selector' => '{{WRAPPER}} .usk-brand-grid-item', |
| 278 |
] |
| 279 |
); |
| 280 |
|
| 281 |
|
| 282 |
$this->add_control( |
| 283 |
'image_heading', |
| 284 |
[ |
| 285 |
'label' => __('IMAGE', 'ultimate-store-kit'), |
| 286 |
'type' => Controls_Manager::HEADING, |
| 287 |
'separator' => 'before' |
| 288 |
] |
| 289 |
); |
| 290 |
|
| 291 |
$this->add_responsive_control( |
| 292 |
'brand_image_height', |
| 293 |
[ |
| 294 |
'label' => __('Height', 'ultimate-store-kit'), |
| 295 |
'type' => Controls_Manager::SLIDER, |
| 296 |
'range' => [ |
| 297 |
'px' => [ |
| 298 |
'min' => 10, |
| 299 |
'max' => 500, |
| 300 |
], |
| 301 |
], |
| 302 |
'selectors' => [ |
| 303 |
'{{WRAPPER}} .usk-brand-grid-img' => 'height: {{SIZE}}{{UNIT}};', |
| 304 |
], |
| 305 |
] |
| 306 |
); |
| 307 |
|
| 308 |
$this->add_responsive_control( |
| 309 |
'brand_image_width', |
| 310 |
[ |
| 311 |
'label' => __('Width', 'ultimate-store-kit'), |
| 312 |
'type' => Controls_Manager::SLIDER, |
| 313 |
'range' => [ |
| 314 |
'px' => [ |
| 315 |
'min' => 10, |
| 316 |
'max' => 500, |
| 317 |
], |
| 318 |
], |
| 319 |
'selectors' => [ |
| 320 |
'{{WRAPPER}} .usk-brand-grid-img' => 'width: {{SIZE}}{{UNIT}};', |
| 321 |
], |
| 322 |
] |
| 323 |
); |
| 324 |
|
| 325 |
$this->add_control( |
| 326 |
'brand_image_opaciry', |
| 327 |
[ |
| 328 |
'label' => __('Opaciry', 'ultimate-store-kit'), |
| 329 |
'type' => Controls_Manager::SLIDER, |
| 330 |
'default' => [ |
| 331 |
'size' => 0.3, |
| 332 |
], |
| 333 |
'range' => [ |
| 334 |
'px' => [ |
| 335 |
'min' => 0, |
| 336 |
'max' => 1, |
| 337 |
'step' => 0.1, |
| 338 |
], |
| 339 |
], |
| 340 |
'selectors' => [ |
| 341 |
'{{WRAPPER}} .usk-brand-grid-img' => 'opacity: {{SIZE}};', |
| 342 |
], |
| 343 |
] |
| 344 |
); |
| 345 |
|
| 346 |
$this->add_group_control( |
| 347 |
Group_Control_Css_Filter::get_type(), |
| 348 |
[ |
| 349 |
'name' => 'css_filters', |
| 350 |
'selector' => '{{WRAPPER}} .usk-brand-grid-img', |
| 351 |
] |
| 352 |
); |
| 353 |
|
| 354 |
$this->end_controls_tab(); |
| 355 |
|
| 356 |
$this->start_controls_tab( |
| 357 |
'tab_item_hover', |
| 358 |
[ |
| 359 |
'label' => esc_html__('Hover', 'ultimate-store-kit'), |
| 360 |
] |
| 361 |
); |
| 362 |
|
| 363 |
$this->add_group_control( |
| 364 |
Group_Control_Background::get_type(), |
| 365 |
[ |
| 366 |
'name' => 'item_hover_background', |
| 367 |
'selector' => '{{WRAPPER}} .usk-brand-grid-item:hover', |
| 368 |
] |
| 369 |
); |
| 370 |
|
| 371 |
$this->add_control( |
| 372 |
'item_hover_border_color', |
| 373 |
[ |
| 374 |
'label' => esc_html__('Border Color', 'ultimate-store-kit'), |
| 375 |
'type' => Controls_Manager::COLOR, |
| 376 |
'default' => '#2B2D42', |
| 377 |
'condition' => [ |
| 378 |
'item_border_border!' => '', |
| 379 |
], |
| 380 |
'selectors' => [ |
| 381 |
'{{WRAPPER}} .usk-brand-grid-item:hover' => 'border-color: {{VALUE}};', |
| 382 |
], |
| 383 |
'separator' => 'before' |
| 384 |
] |
| 385 |
); |
| 386 |
|
| 387 |
$this->add_group_control( |
| 388 |
Group_Control_Box_Shadow::get_type(), |
| 389 |
[ |
| 390 |
'name' => 'item_hover_box_shadow', |
| 391 |
'selector' => '{{WRAPPER}} .usk-brand-grid-item:hover', |
| 392 |
] |
| 393 |
); |
| 394 |
|
| 395 |
$this->add_control( |
| 396 |
'image_heading_hover', |
| 397 |
[ |
| 398 |
'label' => __('IMAGE', 'ultimate-store-kit'), |
| 399 |
'type' => Controls_Manager::HEADING, |
| 400 |
'separator' => 'before' |
| 401 |
] |
| 402 |
); |
| 403 |
|
| 404 |
$this->add_control( |
| 405 |
'brand_image_opaciry_hover', |
| 406 |
[ |
| 407 |
'label' => __('Opaciry', 'ultimate-store-kit'), |
| 408 |
'type' => Controls_Manager::SLIDER, |
| 409 |
'default' => [ |
| 410 |
'size' => 1, |
| 411 |
], |
| 412 |
'range' => [ |
| 413 |
'px' => [ |
| 414 |
'min' => 0, |
| 415 |
'max' => 1, |
| 416 |
'step' => 0.1, |
| 417 |
], |
| 418 |
], |
| 419 |
'selectors' => [ |
| 420 |
'{{WRAPPER}} .usk-brand-grid-item:hover .usk-brand-grid-img' => 'opacity: {{SIZE}};', |
| 421 |
], |
| 422 |
] |
| 423 |
); |
| 424 |
|
| 425 |
$this->add_group_control( |
| 426 |
Group_Control_Css_Filter::get_type(), |
| 427 |
[ |
| 428 |
'name' => 'css_filters_hover', |
| 429 |
'selector' => '{{WRAPPER}} .usk-brand-grid-item:hover .usk-brand-grid-img', |
| 430 |
] |
| 431 |
); |
| 432 |
|
| 433 |
$this->end_controls_tab(); |
| 434 |
|
| 435 |
$this->end_controls_tabs(); |
| 436 |
|
| 437 |
$this->end_controls_section(); |
| 438 |
} |
| 439 |
|
| 440 |
protected function render() { |
| 441 |
$settings = $this->get_settings_for_display(); |
| 442 |
|
| 443 |
if (empty($settings['brand_items'])) { |
| 444 |
return; |
| 445 |
} |
| 446 |
|
| 447 |
$this->add_render_attribute('brand-grid', 'class', 'usk-brand-grid'); |
| 448 |
|
| 449 |
?> |
| 450 |
<div <?php $this->print_render_attribute_string('brand-grid'); ?>> |
| 451 |
<?php foreach ($settings['brand_items'] as $item) : |
| 452 |
$thumb_url = Group_Control_Image_Size::get_attachment_image_src($item['image']['id'], 'thumbnail', $settings); |
| 453 |
if (!$thumb_url) { |
| 454 |
$thumb_url = $item['image']['url']; |
| 455 |
} |
| 456 |
|
| 457 |
$this->add_render_attribute( |
| 458 |
[ |
| 459 |
'link' => [ |
| 460 |
'href' => isset($item['link']['url']) && !empty($item['link']['url']) ? esc_url($item['link']['url']) : 'javascript:void(0);', |
| 461 |
'target' => $item['link']['is_external'] ? '_blank' : '_self' |
| 462 |
] |
| 463 |
], |
| 464 |
'', |
| 465 |
'', |
| 466 |
true |
| 467 |
); |
| 468 |
|
| 469 |
$this->add_render_attribute('item-wrap', 'class', 'usk-brand-grid-item', true); |
| 470 |
|
| 471 |
?> |
| 472 |
<div <?php echo $this->get_render_attribute_string('item-wrap'); ?>> |
| 473 |
<img class="usk-brand-grid-img" src="<?php echo esc_url($thumb_url); ?>" alt="<?php echo esc_html($item['brand_name']); ?>"> |
| 474 |
<?php |
| 475 |
if (!empty($item['link']['url'])) { |
| 476 |
printf('<a %1$s title="%2$s"></a>', $this->get_render_attribute_string('link'), wp_kses_post($item['brand_name'])); |
| 477 |
} ?> |
| 478 |
</div> |
| 479 |
|
| 480 |
<?php endforeach; ?> |
| 481 |
</div> |
| 482 |
<?php |
| 483 |
} |
| 484 |
} |
| 485 |
|