| 1 |
<?php |
| 2 |
|
| 3 |
namespace King_Addons; |
| 4 |
|
| 5 |
use Elementor\Icons_Manager; |
| 6 |
use Elementor\Widget_Base; |
| 7 |
use Elementor\Controls_Manager; |
| 8 |
use Elementor\Group_Control_Typography; |
| 9 |
|
| 10 |
if (!defined('ABSPATH')) { |
| 11 |
exit; // Exit if accessed directly. |
| 12 |
} |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
class Taxonomy_List extends Widget_Base |
| 17 |
{ |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public function get_name(): string |
| 22 |
{ |
| 23 |
return 'king-addons-taxonomy-list'; |
| 24 |
} |
| 25 |
|
| 26 |
public function get_title(): string |
| 27 |
{ |
| 28 |
return esc_html__('Taxonomy List', 'king-addons'); |
| 29 |
} |
| 30 |
|
| 31 |
public function get_icon(): string |
| 32 |
{ |
| 33 |
return 'king-addons-icon king-addons-taxonomy-list'; |
| 34 |
} |
| 35 |
|
| 36 |
public function get_style_depends(): array |
| 37 |
{ |
| 38 |
return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-taxonomy-list-style']; |
| 39 |
} |
| 40 |
|
| 41 |
public function get_categories(): array |
| 42 |
{ |
| 43 |
return ['king-addons']; |
| 44 |
} |
| 45 |
|
| 46 |
public function get_keywords(): array |
| 47 |
{ |
| 48 |
return ['click', 'target', 'point', 'builder', 'link', 'point', 'points', 'king', 'addons', 'kingaddons', |
| 49 |
'king-addons', 'heading', 'header', 'paragraph', 'section', 'heading', 'title', 'subtitle', |
| 50 |
'taxonomy-list', 'taxonomy', 'category', 'categories', 'tag', 'list', 'tax', 'custom', 'post', 'types', |
| 51 |
'custom post types', 'taxonomies', 'sub', 'sub child']; |
| 52 |
} |
| 53 |
|
| 54 |
public function get_custom_help_url() |
| 55 |
{ |
| 56 |
return 'mailto:bug@kingaddons.com?subject=Bug Report - King Addons&body=Please describe the issue'; |
| 57 |
} |
| 58 |
|
| 59 |
public function add_section_style_toggle_icon() |
| 60 |
{ |
| 61 |
} |
| 62 |
|
| 63 |
public function get_post_taxonomies(): array |
| 64 |
{ |
| 65 |
$post_taxonomies = [ |
| 66 |
'category' => esc_html__('Categories', 'king-addons'), |
| 67 |
'post_tag' => esc_html__('Tags', 'king-addons'), |
| 68 |
'product_cat' => esc_html__('Product Categories', 'king-addons'), |
| 69 |
'product_tag' => esc_html__('Product Tags', 'king-addons'), |
| 70 |
]; |
| 71 |
|
| 72 |
foreach (Core::getCustomTypes('tax') as $slug => $title) { |
| 73 |
if (!in_array($slug, ['product_tag', 'product_cat'])) { |
| 74 |
$post_taxonomies['pro-' . substr($slug, 0, 2)] = esc_html($title) . ' (Pro)'; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
return $post_taxonomies; |
| 79 |
} |
| 80 |
|
| 81 |
public function add_controls_group_sub_category_filters() |
| 82 |
{ |
| 83 |
$this->add_control( |
| 84 |
'show_sub_categories', |
| 85 |
[ |
| 86 |
'label' => sprintf(__('Show Sub Categories %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'), |
| 87 |
'type' => Controls_Manager::SWITCHER, |
| 88 |
'classes' => 'king-addons-pro-control', |
| 89 |
] |
| 90 |
); |
| 91 |
|
| 92 |
$this->add_control( |
| 93 |
'show_sub_children', |
| 94 |
[ |
| 95 |
'label' => sprintf(__('Show Sub Child %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'), |
| 96 |
'type' => Controls_Manager::SWITCHER, |
| 97 |
'classes' => 'king-addons-pro-control', |
| 98 |
] |
| 99 |
); |
| 100 |
|
| 101 |
$this->add_control( |
| 102 |
'show_sub_categories_on_click', |
| 103 |
[ |
| 104 |
'label' => sprintf(__('Show Child on Click %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'), |
| 105 |
'type' => Controls_Manager::SWITCHER, |
| 106 |
'label_block' => false, |
| 107 |
'classes' => 'king-addons-pro-control', |
| 108 |
] |
| 109 |
); |
| 110 |
} |
| 111 |
|
| 112 |
protected function register_controls() |
| 113 |
{ |
| 114 |
$this->start_controls_section( |
| 115 |
'section_taxonomy_list_general', |
| 116 |
[ |
| 117 |
'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('General', 'king-addons'), |
| 118 |
'tab' => Controls_Manager::TAB_CONTENT, |
| 119 |
] |
| 120 |
); |
| 121 |
|
| 122 |
$this->add_control( |
| 123 |
'query_heading', |
| 124 |
[ |
| 125 |
'label' => esc_html__('Query', 'king-addons'), |
| 126 |
'type' => Controls_Manager::HEADING, |
| 127 |
] |
| 128 |
); |
| 129 |
|
| 130 |
$this->add_control( |
| 131 |
'query_tax_selection', |
| 132 |
[ |
| 133 |
'label' => esc_html__('Select Taxonomy', 'king-addons'), |
| 134 |
'type' => Controls_Manager::SELECT, |
| 135 |
'default' => 'category', |
| 136 |
'options' => $this->get_post_taxonomies(), |
| 137 |
] |
| 138 |
); |
| 139 |
|
| 140 |
if (!king_addons_freemius()->can_use_premium_code__premium_only()) { |
| 141 |
$this->add_control( |
| 142 |
'query_tax_selection_pro_notice', |
| 143 |
[ |
| 144 |
'raw' => 'This option is available<br> in the <strong><a href="https://kingaddons.com/pricing/?utm_source=kng-module-taxonomy-list-settings-upgrade-pro&utm_medium=plugin&utm_campaign=kng" target="_blank">Pro version</a></strong>', |
| 145 |
'type' => Controls_Manager::RAW_HTML, |
| 146 |
'content_classes' => 'king-addons-pro-notice', |
| 147 |
'condition' => [ |
| 148 |
'query_tax_selection!' => ['category', 'post_tag', 'product_cat', 'product_tag'], |
| 149 |
] |
| 150 |
] |
| 151 |
); |
| 152 |
} |
| 153 |
|
| 154 |
$this->add_control( |
| 155 |
'query_hide_empty', |
| 156 |
[ |
| 157 |
'label' => esc_html__('Hide Empty', 'king-addons'), |
| 158 |
'type' => Controls_Manager::SWITCHER, |
| 159 |
'return_value' => 'yes', |
| 160 |
'default' => 'yes' |
| 161 |
] |
| 162 |
); |
| 163 |
|
| 164 |
$this->add_controls_group_sub_category_filters(); |
| 165 |
|
| 166 |
$this->add_control( |
| 167 |
'layout_heading', |
| 168 |
[ |
| 169 |
'label' => esc_html__('Layout', 'king-addons'), |
| 170 |
'type' => Controls_Manager::HEADING, |
| 171 |
'separator' => 'before', |
| 172 |
] |
| 173 |
); |
| 174 |
|
| 175 |
$this->add_control( |
| 176 |
'taxonomy_list_layout', |
| 177 |
[ |
| 178 |
'label' => esc_html__('Select Layout', 'king-addons'), |
| 179 |
'type' => Controls_Manager::CHOOSE, |
| 180 |
'default' => 'vertical', |
| 181 |
'render_type' => 'template', |
| 182 |
'options' => [ |
| 183 |
'vertical' => [ |
| 184 |
'title' => esc_html__('Vertical', 'king-addons'), |
| 185 |
'icon' => 'eicon-editor-list-ul', |
| 186 |
], |
| 187 |
'horizontal' => [ |
| 188 |
'title' => esc_html__('Horizontal', 'king-addons'), |
| 189 |
'icon' => 'eicon-ellipsis-h', |
| 190 |
], |
| 191 |
], |
| 192 |
'prefix_class' => 'king-addons-tax-list-taxonomy-list-', |
| 193 |
'label_block' => false, |
| 194 |
] |
| 195 |
); |
| 196 |
|
| 197 |
$this->add_control( |
| 198 |
'show_tax_list_icon', |
| 199 |
[ |
| 200 |
'label' => esc_html__('Show Icon', 'king-addons'), |
| 201 |
'type' => Controls_Manager::SWITCHER, |
| 202 |
'return_value' => 'yes', |
| 203 |
'label_block' => false, |
| 204 |
'default' => 'yes' |
| 205 |
] |
| 206 |
); |
| 207 |
|
| 208 |
$this->add_control( |
| 209 |
'tax_list_icon', |
| 210 |
[ |
| 211 |
'label' => esc_html__('Icon', 'king-addons'), |
| 212 |
'type' => Controls_Manager::ICONS, |
| 213 |
'skin' => 'inline', |
| 214 |
'label_block' => false, |
| 215 |
'exclude_inline_options' => 'svg', |
| 216 |
'condition' => [ |
| 217 |
'show_tax_list_icon' => 'yes' |
| 218 |
] |
| 219 |
] |
| 220 |
); |
| 221 |
|
| 222 |
$this->add_control( |
| 223 |
'show_tax_count', |
| 224 |
[ |
| 225 |
'label' => esc_html__('Show Count', 'king-addons'), |
| 226 |
'type' => Controls_Manager::SWITCHER, |
| 227 |
'return_value' => 'yes', |
| 228 |
'label_block' => false, |
| 229 |
'default' => 'yes' |
| 230 |
] |
| 231 |
); |
| 232 |
|
| 233 |
$this->add_control( |
| 234 |
'show_count_brackets', |
| 235 |
[ |
| 236 |
'label' => esc_html__('Count Brackets', 'king-addons'), |
| 237 |
'type' => Controls_Manager::SWITCHER, |
| 238 |
'return_value' => 'yes', |
| 239 |
'label_block' => false, |
| 240 |
'default' => 'yes', |
| 241 |
'condition' => [ |
| 242 |
'show_tax_count' => 'yes' |
| 243 |
] |
| 244 |
] |
| 245 |
); |
| 246 |
|
| 247 |
$this->add_control( |
| 248 |
'disable_links', |
| 249 |
[ |
| 250 |
'label' => esc_html__('Disable Links', 'king-addons'), |
| 251 |
'type' => Controls_Manager::SWITCHER, |
| 252 |
'return_value' => 'yes', |
| 253 |
'label_block' => false, |
| 254 |
'default' => '', |
| 255 |
'separator' => 'before' |
| 256 |
] |
| 257 |
); |
| 258 |
|
| 259 |
$this->add_control( |
| 260 |
'open_in_new_page', |
| 261 |
[ |
| 262 |
'label' => esc_html__('Open in New Page', 'king-addons'), |
| 263 |
'type' => Controls_Manager::SWITCHER, |
| 264 |
'return_value' => 'yes', |
| 265 |
'label_block' => false, |
| 266 |
'default' => 'yes', |
| 267 |
'condition' => [ |
| 268 |
'disable_links!' => 'yes' |
| 269 |
] |
| 270 |
] |
| 271 |
); |
| 272 |
|
| 273 |
$this->add_control( |
| 274 |
'highlight_active', |
| 275 |
[ |
| 276 |
'label' => esc_html__('Highlight Active', 'king-addons'), |
| 277 |
'type' => Controls_Manager::SWITCHER, |
| 278 |
'return_value' => 'yes', |
| 279 |
'label_block' => false, |
| 280 |
'default' => '' |
| 281 |
] |
| 282 |
); |
| 283 |
|
| 284 |
$this->end_controls_section(); |
| 285 |
|
| 286 |
Core::renderProFeaturesSection($this, '', Controls_Manager::RAW_HTML, 'taxonomy-list', [ |
| 287 |
'Custom Post Type Taxonomies & Categories', |
| 288 |
'Show Sub Categories', |
| 289 |
'Show Sub Child', |
| 290 |
'Show Child On Click', |
| 291 |
]); |
| 292 |
|
| 293 |
$this->start_controls_section( |
| 294 |
'section_style_tax', |
| 295 |
[ |
| 296 |
'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Taxonomy Style', 'king-addons'), |
| 297 |
'tab' => Controls_Manager::TAB_STYLE, |
| 298 |
'show_label' => false, |
| 299 |
] |
| 300 |
); |
| 301 |
|
| 302 |
$this->start_controls_tabs('tax_style'); |
| 303 |
|
| 304 |
$this->start_controls_tab( |
| 305 |
'tax_normal', |
| 306 |
[ |
| 307 |
'label' => esc_html__('Normal', 'king-addons'), |
| 308 |
] |
| 309 |
); |
| 310 |
|
| 311 |
$this->add_control( |
| 312 |
'tax_color', |
| 313 |
[ |
| 314 |
'label' => esc_html__('Color', 'king-addons'), |
| 315 |
'type' => Controls_Manager::COLOR, |
| 316 |
'default' => '#5B03FF', |
| 317 |
'selectors' => [ |
| 318 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li a' => 'color: {{VALUE}}', |
| 319 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li>span' => 'color: {{VALUE}}' |
| 320 |
], |
| 321 |
] |
| 322 |
); |
| 323 |
|
| 324 |
$this->add_control( |
| 325 |
'tax_bg_color', |
| 326 |
[ |
| 327 |
'label' => esc_html__('Background Color', 'king-addons'), |
| 328 |
'type' => Controls_Manager::COLOR, |
| 329 |
'default' => '', |
| 330 |
'selectors' => [ |
| 331 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li a' => 'background-color: {{VALUE}}', |
| 332 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li>span' => 'background-color: {{VALUE}}' |
| 333 |
] |
| 334 |
] |
| 335 |
); |
| 336 |
|
| 337 |
$this->add_control( |
| 338 |
'tax_border_color', |
| 339 |
[ |
| 340 |
'label' => esc_html__('Border Color', 'king-addons'), |
| 341 |
'type' => Controls_Manager::COLOR, |
| 342 |
'default' => '#E8E8E8', |
| 343 |
'selectors' => [ |
| 344 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li a' => 'border-color: {{VALUE}}', |
| 345 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li>span' => 'border-color: {{VALUE}}' |
| 346 |
], |
| 347 |
] |
| 348 |
); |
| 349 |
|
| 350 |
$this->add_control( |
| 351 |
'tax_transition_duration', |
| 352 |
[ |
| 353 |
'label' => esc_html__('Transition Duration (ms)', 'king-addons'), |
| 354 |
'type' => Controls_Manager::NUMBER, |
| 355 |
'default' => 300, |
| 356 |
'min' => 0, |
| 357 |
'step' => 10, |
| 358 |
'selectors' => [ |
| 359 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li a' => 'transition-duration: {{VALUE}}ms', |
| 360 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li>span' => 'transition-duration: {{VALUE}}ms' |
| 361 |
], |
| 362 |
] |
| 363 |
); |
| 364 |
|
| 365 |
$this->add_group_control( |
| 366 |
Group_Control_Typography::get_type(), |
| 367 |
[ |
| 368 |
'name' => 'tax_typography', |
| 369 |
'selector' => '{{WRAPPER}} .king-addons-tax-list-taxonomy-list li a, {{WRAPPER}} .king-addons-tax-list-taxonomy-list li>span', |
| 370 |
'fields_options' => [ |
| 371 |
'typography' => [ |
| 372 |
'default' => 'custom', |
| 373 |
], |
| 374 |
'font_size' => [ |
| 375 |
'default' => [ |
| 376 |
'size' => '14', |
| 377 |
'unit' => 'px', |
| 378 |
], |
| 379 |
] |
| 380 |
] |
| 381 |
] |
| 382 |
); |
| 383 |
|
| 384 |
$this->end_controls_tab(); |
| 385 |
|
| 386 |
$this->start_controls_tab( |
| 387 |
'tax_hover', |
| 388 |
[ |
| 389 |
'label' => esc_html__('Hover', 'king-addons'), |
| 390 |
] |
| 391 |
); |
| 392 |
|
| 393 |
$this->add_control( |
| 394 |
'tax_color_hr', |
| 395 |
[ |
| 396 |
'label' => esc_html__('Color', 'king-addons'), |
| 397 |
'type' => Controls_Manager::COLOR, |
| 398 |
'selectors' => [ |
| 399 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li a:hover' => 'color: {{VALUE}} !important', |
| 400 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li>span:hover' => 'color: {{VALUE}} !important', |
| 401 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li.king-addons-tax-list-taxonomy-active a' => 'color: {{VALUE}}', |
| 402 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li.king-addons-tax-list-taxonomy-active>span' => 'color: {{VALUE}}' |
| 403 |
], |
| 404 |
] |
| 405 |
); |
| 406 |
|
| 407 |
$this->add_control( |
| 408 |
'tax1_bg_color_hr', |
| 409 |
[ |
| 410 |
'label' => esc_html__('Background Color', 'king-addons'), |
| 411 |
'type' => Controls_Manager::COLOR, |
| 412 |
'selectors' => [ |
| 413 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li a:hover' => 'background-color: {{VALUE}} !important', |
| 414 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li>span:hover' => 'background-color: {{VALUE}} !important', |
| 415 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li.king-addons-tax-list-taxonomy-active a' => 'background-color: {{VALUE}}', |
| 416 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li.king-addons-tax-list-taxonomy-active>span' => 'background-color: {{VALUE}}' |
| 417 |
] |
| 418 |
] |
| 419 |
); |
| 420 |
|
| 421 |
$this->add_control( |
| 422 |
'tax1_border_color_hr', |
| 423 |
[ |
| 424 |
'label' => esc_html__('Border Color', 'king-addons'), |
| 425 |
'type' => Controls_Manager::COLOR, |
| 426 |
'selectors' => [ |
| 427 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li a:hover' => 'border-color: {{VALUE}} !important', |
| 428 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li>span:hover' => 'border-color: {{VALUE}} !important', |
| 429 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li.king-addons-tax-list-taxonomy-active a' => 'border-color: {{VALUE}}', |
| 430 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li.king-addons-tax-list-taxonomy-active>span' => 'border-color: {{VALUE}}' |
| 431 |
], |
| 432 |
] |
| 433 |
); |
| 434 |
|
| 435 |
$this->end_controls_tab(); |
| 436 |
|
| 437 |
$this->end_controls_tabs(); |
| 438 |
|
| 439 |
$this->add_responsive_control( |
| 440 |
'tax_padding', |
| 441 |
[ |
| 442 |
'label' => esc_html__('Padding', 'king-addons'), |
| 443 |
'type' => Controls_Manager::DIMENSIONS, |
| 444 |
'size_units' => ['px', '%'], |
| 445 |
'default' => [ |
| 446 |
'top' => 5, |
| 447 |
'right' => 0, |
| 448 |
'bottom' => 5, |
| 449 |
'left' => 0, |
| 450 |
], |
| 451 |
'selectors' => [ |
| 452 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li a' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 453 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li>span' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' |
| 454 |
], |
| 455 |
'separator' => 'before', |
| 456 |
] |
| 457 |
); |
| 458 |
|
| 459 |
$this->add_responsive_control( |
| 460 |
'tax_margin', |
| 461 |
[ |
| 462 |
'label' => esc_html__('Margin', 'king-addons'), |
| 463 |
'type' => Controls_Manager::DIMENSIONS, |
| 464 |
'size_units' => ['px', '%'], |
| 465 |
'default' => [ |
| 466 |
'top' => 5, |
| 467 |
'right' => 8, |
| 468 |
'bottom' => 0, |
| 469 |
'left' => 0, |
| 470 |
], |
| 471 |
'selectors' => [ |
| 472 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 473 |
], |
| 474 |
] |
| 475 |
); |
| 476 |
|
| 477 |
$this->add_control( |
| 478 |
'tax_border_type', |
| 479 |
[ |
| 480 |
'label' => esc_html__('Border Type', 'king-addons'), |
| 481 |
'type' => Controls_Manager::SELECT, |
| 482 |
'options' => [ |
| 483 |
'none' => esc_html__('None', 'king-addons'), |
| 484 |
'solid' => esc_html__('Solid', 'king-addons'), |
| 485 |
'double' => esc_html__('Double', 'king-addons'), |
| 486 |
'dotted' => esc_html__('Dotted', 'king-addons'), |
| 487 |
'dashed' => esc_html__('Dashed', 'king-addons'), |
| 488 |
'groove' => esc_html__('Groove', 'king-addons'), |
| 489 |
], |
| 490 |
'default' => 'solid', |
| 491 |
'selectors' => [ |
| 492 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li a' => 'border-style: {{VALUE}};', |
| 493 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li>span' => 'border-style: {{VALUE}};' |
| 494 |
], |
| 495 |
'separator' => 'before', |
| 496 |
] |
| 497 |
); |
| 498 |
|
| 499 |
$this->add_control( |
| 500 |
'tax_border_width', |
| 501 |
[ |
| 502 |
'label' => esc_html__('Border Width', 'king-addons'), |
| 503 |
'type' => Controls_Manager::DIMENSIONS, |
| 504 |
'size_units' => ['px'], |
| 505 |
'default' => [ |
| 506 |
'top' => 0, |
| 507 |
'right' => 0, |
| 508 |
'bottom' => 1, |
| 509 |
'left' => 0, |
| 510 |
], |
| 511 |
'selectors' => [ |
| 512 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li a' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 513 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li>span' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' |
| 514 |
], |
| 515 |
'condition' => [ |
| 516 |
'tax_border_type!' => 'none', |
| 517 |
], |
| 518 |
] |
| 519 |
); |
| 520 |
|
| 521 |
$this->add_control( |
| 522 |
'tax_radius', |
| 523 |
[ |
| 524 |
'label' => esc_html__('Border Radius', 'king-addons'), |
| 525 |
'type' => Controls_Manager::DIMENSIONS, |
| 526 |
'size_units' => ['px', '%'], |
| 527 |
'default' => [ |
| 528 |
'top' => 0, |
| 529 |
'right' => 0, |
| 530 |
'bottom' => 0, |
| 531 |
'left' => 0, |
| 532 |
], |
| 533 |
'selectors' => [ |
| 534 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li a' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', |
| 535 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li>span' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' |
| 536 |
] |
| 537 |
] |
| 538 |
); |
| 539 |
|
| 540 |
$this->end_controls_section(); |
| 541 |
|
| 542 |
$this->start_controls_section( |
| 543 |
'section_style_icon', |
| 544 |
[ |
| 545 |
'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Icon', 'king-addons'), |
| 546 |
'tab' => Controls_Manager::TAB_STYLE, |
| 547 |
'condition' => [ |
| 548 |
'show_tax_list_icon' => 'yes' |
| 549 |
] |
| 550 |
] |
| 551 |
); |
| 552 |
|
| 553 |
$this->add_control( |
| 554 |
'icon_color', |
| 555 |
[ |
| 556 |
'label' => esc_html__('Color', 'king-addons'), |
| 557 |
'type' => Controls_Manager::COLOR, |
| 558 |
'default' => '#5B03FF', |
| 559 |
'selectors' => [ |
| 560 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li i' => 'color: {{VALUE}}', |
| 561 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li svg' => 'fill: {{VALUE}}', |
| 562 |
], |
| 563 |
] |
| 564 |
); |
| 565 |
|
| 566 |
$this->add_responsive_control( |
| 567 |
'icon_size', |
| 568 |
[ |
| 569 |
'label' => esc_html__('Size', 'king-addons'), |
| 570 |
'type' => Controls_Manager::SLIDER, |
| 571 |
'size_units' => ['px'], |
| 572 |
'range' => [ |
| 573 |
'px' => [ |
| 574 |
'min' => 0, |
| 575 |
'max' => 50, |
| 576 |
], |
| 577 |
], |
| 578 |
'default' => [ |
| 579 |
'unit' => 'px', |
| 580 |
'size' => 15, |
| 581 |
], |
| 582 |
'selectors' => [ |
| 583 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li i' => 'font-size: {{SIZE}}{{UNIT}};', |
| 584 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li svg' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};', |
| 585 |
], |
| 586 |
'separator' => 'before' |
| 587 |
] |
| 588 |
); |
| 589 |
|
| 590 |
$this->add_responsive_control( |
| 591 |
'icon_distance', |
| 592 |
[ |
| 593 |
'label' => esc_html__('Space', 'king-addons'), |
| 594 |
'type' => Controls_Manager::SLIDER, |
| 595 |
'size_units' => ['px'], |
| 596 |
'range' => [ |
| 597 |
'px' => [ |
| 598 |
'min' => 0, |
| 599 |
'max' => 50, |
| 600 |
], |
| 601 |
], |
| 602 |
'default' => [ |
| 603 |
'unit' => 'px', |
| 604 |
'size' => 5, |
| 605 |
], |
| 606 |
'selectors' => [ |
| 607 |
'{{WRAPPER}} .king-addons-tax-list-taxonomy-list li i:not(.king-addons-tax-list-tax-dropdown)' => 'margin-right: {{SIZE}}{{UNIT}};', |
| 608 |
], |
| 609 |
] |
| 610 |
); |
| 611 |
|
| 612 |
$this->end_controls_section(); |
| 613 |
|
| 614 |
$this->add_section_style_toggle_icon(); |
| 615 |
} |
| 616 |
|
| 617 |
public function get_tax_wrapper_open_tag($settings, $term_id, $open_in_new_page) |
| 618 |
{ |
| 619 |
if ('yes' == $settings['disable_links']) { |
| 620 |
echo '<span>'; |
| 621 |
} else { |
| 622 |
echo '<a target="' . $open_in_new_page . '" href="' . esc_url(get_term_link($term_id)) . '">'; |
| 623 |
} |
| 624 |
} |
| 625 |
|
| 626 |
public function get_tax_wrapper_close_tag($settings) |
| 627 |
{ |
| 628 |
if ('yes' == $settings['disable_links']) { |
| 629 |
echo '</span>'; |
| 630 |
} else { |
| 631 |
echo '</a>'; |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
protected function render() |
| 636 |
{ |
| 637 |
$settings = $this->get_settings_for_display(); |
| 638 |
$open_in_new_page = $settings['open_in_new_page'] ? '_blank' : '_self'; |
| 639 |
|
| 640 |
ob_start(); |
| 641 |
Icons_Manager::render_icon($settings['tax_list_icon'], ['aria-hidden' => 'true']); |
| 642 |
$icon = ob_get_clean(); |
| 643 |
$icon_wrapper = !empty($settings['tax_list_icon']) ? '<span>' . $icon . '</span>' : ''; |
| 644 |
$brackets = $settings['show_count_brackets'] ?? ''; |
| 645 |
|
| 646 |
$settings['query_tax_selection'] = str_contains($settings['query_tax_selection'], 'pro-') ? 'category' : $settings['query_tax_selection']; |
| 647 |
|
| 648 |
$terms = $this->get_terms_hierarchy($settings, $settings['query_tax_selection']); |
| 649 |
|
| 650 |
echo '<ul class="king-addons-tax-list-taxonomy-list" data-show-on-click="' . esc_attr($settings['show_sub_categories_on_click']) . '">'; |
| 651 |
$this->render_terms($terms, $settings, $icon_wrapper, $brackets, $open_in_new_page); |
| 652 |
echo '</ul>'; |
| 653 |
} |
| 654 |
|
| 655 |
private function get_terms_hierarchy($settings, $taxonomy, $parent = 0) |
| 656 |
{ |
| 657 |
return get_terms($taxonomy, [ |
| 658 |
'hide_empty' => 'yes' === $settings['query_hide_empty'], |
| 659 |
'parent' => $parent, |
| 660 |
'fields' => 'all' |
| 661 |
]); |
| 662 |
} |
| 663 |
|
| 664 |
private function render_terms($terms, $settings, $icon_wrapper, $brackets, $open_in_new_page, $level = 0) |
| 665 |
{ |
| 666 |
foreach ($terms as $term) { |
| 667 |
$class = $this->get_term_class($settings, $term, $level); |
| 668 |
$children = ('yes' === $settings['show_sub_categories']) ? $this->get_terms_hierarchy($settings, $settings['query_tax_selection'], $term->term_id) : []; |
| 669 |
|
| 670 |
echo '<li' . $class . ' data-term-id="' . esc_attr($term->term_id) . '">'; |
| 671 |
$this->get_tax_wrapper_open_tag($settings, $term->term_id, $open_in_new_page); |
| 672 |
|
| 673 |
echo '<span class="king-addons-tax-list-tax-wrap">' |
| 674 |
. (!empty($children) && $settings['show_sub_categories_on_click'] === 'yes' ? '<i class="fas fa-caret-right king-addons-tax-list-tax-dropdown" aria-hidden="true"></i>' : '') |
| 675 |
. $icon_wrapper |
| 676 |
. '<span>' . esc_html($term->name) . '</span>' |
| 677 |
. '</span>' |
| 678 |
. ($settings['show_tax_count'] ? $this->render_term_count($term, $brackets) : ''); |
| 679 |
|
| 680 |
$this->get_tax_wrapper_close_tag($settings); |
| 681 |
|
| 682 |
if (!empty($children)) { |
| 683 |
$this->render_terms($children, $settings, $icon_wrapper, $brackets, $open_in_new_page, $level + 1); |
| 684 |
} |
| 685 |
|
| 686 |
echo '</li>'; |
| 687 |
} |
| 688 |
} |
| 689 |
|
| 690 |
private function get_term_class($settings, $term, $level): string |
| 691 |
{ |
| 692 |
$is_active = isset(get_queried_object()->term_taxonomy_id) && $term->term_id == get_queried_object()->term_taxonomy_id && 'yes' === $settings['highlight_active']; |
| 693 |
$hidden_class = ($level > 0 && ($settings['show_sub_categories_on_click'] ?? '') === 'yes') |
| 694 |
? ' king-addons-tax-list-sub-hidden' |
| 695 |
: ''; |
| 696 |
|
| 697 |
$base_class = $level === 0 ? 'king-addons-tax-list-taxonomy' : "king-addons-tax-list-sub-taxonomy-$level"; |
| 698 |
return ' class="' . $base_class . ($is_active ? ' king-addons-tax-list-taxonomy-active' : '') . $hidden_class . '"'; |
| 699 |
} |
| 700 |
|
| 701 |
private function render_term_count($term, $brackets): string |
| 702 |
{ |
| 703 |
$count = esc_html($term->count); |
| 704 |
return $brackets ? "<span><span class=\"king-addons-tax-list-term-count\"> ($count)</span></span>" : "<span><span class=\"king-addons-tax-list-term-count\"> $count</span></span>"; |
| 705 |
} |
| 706 |
} |