PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.86
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.86
51.1.86 51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 All 40 releases
king-addons / includes / widgets / Woo_Archive_Title / Woo_Archive_Title.php

Woo_Archive_Title.php in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.86, at includes/widgets/Woo_Archive_Title/Woo_Archive_Title.php

194 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Woo Archive Title widget.
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Group_Control_Typography;
12
13 if (!defined('ABSPATH')) {
14 exit;
15 }
16
17 /**
18 * Displays archive title.
19 */
20 class Woo_Archive_Title extends Abstract_Archive_Widget
21 {
22 public function get_name(): string
23 {
24 return 'woo_archive_title';
25 }
26
27 public function get_title(): string
28 {
29 return esc_html__('Archive Title', 'king-addons');
30 }
31
32 public function get_icon(): string
33 {
34 return 'king-addons-icon king-addons-woo-archive-title';
35 }
36
37 public function get_categories(): array
38 {
39 return ['king-addons-woo-builder'];
40 }
41
42 public function get_style_depends(): array
43 {
44 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-woo-archive-title-style'];
45 }
46
47 protected function register_controls(): void
48 {
49 $this->start_controls_section(
50 'section_content',
51 [
52 'label' => esc_html__('Content', 'king-addons'),
53 'tab' => Controls_Manager::TAB_CONTENT,
54 ]
55 );
56
57 $this->add_control(
58 'html_tag',
59 [
60 'label' => esc_html__('HTML Tag', 'king-addons'),
61 'type' => Controls_Manager::SELECT,
62 'options' => [
63 'h1' => 'H1',
64 'h2' => 'H2',
65 'h3' => 'H3',
66 'div' => 'div',
67 ],
68 'default' => 'h1',
69 ]
70 );
71
72 $this->add_control(
73 'prefix',
74 [
75 'label' => sprintf(__('Prefix (Pro) %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
76 'type' => Controls_Manager::TEXT,
77 'dynamic' => ['active' => true],
78 'default' => '',
79 ]
80 );
81
82 $this->add_control(
83 'custom_format',
84 [
85 'label' => sprintf(__('Custom format %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
86 'type' => Controls_Manager::TEXT,
87 'description' => esc_html__('Use {title} and {count} placeholders.', 'king-addons'),
88 'default' => '',
89 ]
90 );
91
92 $this->end_controls_section();
93
94 $this->start_controls_section(
95 'section_style',
96 [
97 'label' => esc_html__('Style', 'king-addons'),
98 'tab' => Controls_Manager::TAB_STYLE,
99 ]
100 );
101
102 $this->add_group_control(
103 Group_Control_Typography::get_type(),
104 [
105 'name' => 'typography',
106 'selector' => '{{WRAPPER}} .ka-woo-archive-title',
107 ]
108 );
109
110 $this->add_control(
111 'color',
112 [
113 'label' => esc_html__('Color', 'king-addons'),
114 'type' => Controls_Manager::COLOR,
115 'selectors' => [
116 '{{WRAPPER}} .ka-woo-archive-title' => 'color: {{VALUE}};',
117 ],
118 ]
119 );
120
121 $this->add_responsive_control(
122 'margin',
123 [
124 'label' => esc_html__('Margin', 'king-addons'),
125 'type' => Controls_Manager::DIMENSIONS,
126 'size_units' => ['px', 'em', '%'],
127 'selectors' => [
128 '{{WRAPPER}} .ka-woo-archive-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
129 ],
130 ]
131 );
132
133 $this->end_controls_section();
134 }
135
136 protected function render(): void
137 {
138 if (!class_exists('WooCommerce') || !function_exists('is_shop') || !function_exists('is_product_taxonomy')) {
139 return;
140 }
141
142 if (!$this->should_render()) {
143 $this->render_missing_archive_notice();
144 return;
145 }
146
147 $settings = $this->get_settings_for_display();
148
149 // The value is written straight into the markup as an element name, so
150 // anything off the list has to fall back rather than produce a tag the
151 // browser has never heard of.
152 $tag = strtolower((string) ($settings['html_tag'] ?? 'h1'));
153 if (!in_array($tag, ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'span', 'p'], true)) {
154 $tag = 'h1';
155 }
156
157 $title = (string) woocommerce_page_title(false);
158 $can_pro = king_addons_can_use_pro();
159 if (!empty($settings['prefix']) && $can_pro) {
160 $title = $settings['prefix'] . ' ' . $title;
161 }
162
163 if (!empty($settings['custom_format']) && $can_pro) {
164 global $wp_query;
165 $count = isset($wp_query->found_posts) ? (int) $wp_query->found_posts : 0;
166 $formatted = str_replace(
167 ['{title}', '{count}'],
168 [$title, number_format_i18n($count)],
169 $settings['custom_format']
170 );
171 $title = $formatted;
172 }
173
174 if ('' === trim($title)) {
175 // Outside a real archive there is no page title to print, and a
176 // blank widget in the editor reads as a fault.
177 if (\Elementor\Plugin::$instance->editor->is_edit_mode()) {
178 echo '<div class="king-addons-woo-builder-notice">'
179 . esc_html__('The archive title comes from the shop or category being viewed.', 'king-addons')
180 . '</div>';
181 }
182 return;
183 }
184
185 echo '<' . $tag . ' class="ka-woo-archive-title">' . esc_html($title) . '</' . $tag . '>';
186 }
187 }
188
189
190
191
192
193
194