PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.83
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.83
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 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / widgets / TB_Post_Comments / TB_Post_Comments.php

TB_Post_Comments.php in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.83, at includes/widgets/TB_Post_Comments/TB_Post_Comments.php

346 lines 9.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Theme Builder Post Comments widget (Free).
4 *
5 * @package King_Addons
6 */
7
8 namespace King_Addons;
9
10 use Elementor\Controls_Manager;
11 use Elementor\Group_Control_Typography;
12 use Elementor\Widget_Base;
13
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 /**
19 * Renders comments list and form for the current post.
20 */
21 class TB_Post_Comments extends Widget_Base
22 {
23 /**
24 * Widget slug.
25 *
26 * @return string
27 */
28 public function get_name(): string
29 {
30 return 'king-addons-tb-post-comments';
31 }
32
33 /**
34 * Widget title.
35 *
36 * @return string
37 */
38 public function get_title(): string
39 {
40 return esc_html__('TB - Post Comments', 'king-addons');
41 }
42
43 /**
44 * Widget icon.
45 *
46 * @return string
47 */
48 public function get_icon(): string
49 {
50 return 'king-addons-icon king-addons-tb-post-comments';
51 }
52
53 /**
54 * Style dependencies.
55 *
56 * @return array<int, string>
57 */
58 public function get_style_depends(): array
59 {
60 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-tb-post-comments-style'];
61 }
62
63 /**
64 * Script dependencies.
65 *
66 * @return array<int, string>
67 */
68 public function get_script_depends(): array
69 {
70 return [KING_ADDONS_ASSETS_UNIQUE_KEY . '-tb-post-comments-script'];
71 }
72
73 /**
74 * Categories.
75 *
76 * @return array<int, string>
77 */
78 public function get_categories(): array
79 {
80 return ['king-addons-theme-builder'];
81 }
82
83 /**
84 * Keywords.
85 *
86 * @return array<int, string>
87 */
88 public function get_keywords(): array
89 {
90 return ['comments', 'discussion', 'form', 'theme builder', 'king-addons'];
91 }
92
93 public function get_custom_help_url()
94 {
95 return 'mailto:bug@kingaddons.com?subject=Bug Report - King Addons&body=Please describe the issue';
96 }
97
98 /**
99 * Register controls.
100 *
101 * @return void
102 */
103 public function register_controls(): void
104 {
105 $this->register_content_controls(false);
106 $this->register_style_controls(false);
107 $this->register_pro_notice_controls();
108 }
109
110 /**
111 * Render output.
112 *
113 * @return void
114 */
115 public function render(): void
116 {
117 $settings = $this->get_settings_for_display();
118 $this->render_output($settings, false);
119 }
120
121 /**
122 * Content controls.
123 *
124 * @param bool $is_pro Whether Pro controls are enabled.
125 *
126 * @return void
127 */
128 protected function register_content_controls(bool $is_pro): void
129 {
130 $this->start_controls_section(
131 'kng_content_section',
132 [
133 'label' => KING_ADDONS_ELEMENTOR_ICON . esc_html__('Content', 'king-addons'),
134 'tab' => Controls_Manager::TAB_CONTENT,
135 ]
136 );
137
138 $this->add_control(
139 'kng_show',
140 [
141 'label' => esc_html__('Show', 'king-addons'),
142 'type' => Controls_Manager::SELECT,
143 'default' => 'both',
144 'options' => [
145 'list' => esc_html__('Comments List', 'king-addons'),
146 'form' => esc_html__('Comment Form', 'king-addons'),
147 'both' => esc_html__('Both', 'king-addons'),
148 ],
149 ]
150 );
151
152 $this->add_control(
153 'kng_hide_when_closed',
154 [
155 'label' => esc_html__('Hide When Closed', 'king-addons'),
156 'type' => Controls_Manager::SWITCHER,
157 'return_value' => 'yes',
158 'default' => '',
159 ]
160 );
161
162 $this->add_control(
163 'kng_no_comments_text',
164 [
165 'label' => $is_pro ?
166 esc_html__('No Comments Text', 'king-addons') :
167 sprintf(__('No Comments Text %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
168 'type' => Controls_Manager::TEXT,
169 'dynamic' => ['active' => true],
170 'default' => esc_html__('No comments yet.', 'king-addons'),
171 'classes' => $is_pro ? '' : 'king-addons-pro-control',
172 ]
173 );
174
175 $this->add_control(
176 'kng_order',
177 [
178 'label' => $is_pro ?
179 esc_html__('Order', 'king-addons') :
180 sprintf(__('Order %s', 'king-addons'), '<i class="eicon-pro-icon"></i>'),
181 'type' => Controls_Manager::SELECT,
182 'default' => 'ASC',
183 'options' => [
184 'ASC' => esc_html__('Oldest First', 'king-addons'),
185 'DESC' => esc_html__('Newest First', 'king-addons'),
186 ],
187 'classes' => $is_pro ? '' : 'king-addons-pro-control',
188 ]
189 );
190
191 $this->end_controls_section();
192 }
193
194 /**
195 * Style controls.
196 *
197 * @param bool $is_pro Whether Pro controls are enabled.
198 *
199 * @return void
200 */
201 protected function register_style_controls(bool $is_pro): void
202 {
203 $this->start_controls_section(
204 'kng_style_section',
205 [
206 'label' => esc_html__('Style', 'king-addons'),
207 'tab' => Controls_Manager::TAB_STYLE,
208 ]
209 );
210
211 $this->add_group_control(
212 Group_Control_Typography::get_type(),
213 [
214 'name' => 'kng_heading_typography',
215 'label' => esc_html__('Heading Typography', 'king-addons'),
216 'selector' => '{{WRAPPER}} .king-addons-tb-post-comments__heading',
217 ]
218 );
219
220 $this->add_group_control(
221 Group_Control_Typography::get_type(),
222 [
223 'name' => 'kng_body_typography',
224 'label' => esc_html__('Text Typography', 'king-addons'),
225 'selector' => '{{WRAPPER}} .king-addons-tb-post-comments, {{WRAPPER}} .king-addons-tb-post-comments a',
226 ]
227 );
228
229 $this->add_control(
230 'kng_text_color',
231 [
232 'label' => esc_html__('Text Color', 'king-addons'),
233 'type' => Controls_Manager::COLOR,
234 'selectors' => [
235 '{{WRAPPER}} .king-addons-tb-post-comments' => 'color: {{VALUE}};',
236 '{{WRAPPER}} .king-addons-tb-post-comments a' => 'color: {{VALUE}};',
237 ],
238 ]
239 );
240
241 $this->add_control(
242 'kng_link_hover_color',
243 [
244 'label' => esc_html__('Link Hover Color', 'king-addons'),
245 'type' => Controls_Manager::COLOR,
246 'selectors' => [
247 '{{WRAPPER}} .king-addons-tb-post-comments a:hover' => 'color: {{VALUE}};',
248 ],
249 ]
250 );
251
252 $this->end_controls_section();
253 }
254
255 /**
256 * Pro upsell.
257 *
258 * @return void
259 */
260 protected function register_pro_notice_controls(): void
261 {
262 if (king_addons_freemius()->can_use_premium_code__premium_only()) {
263 return;
264 }
265
266 Core::renderProFeaturesSection(
267 $this,
268 '',
269 Controls_Manager::RAW_HTML,
270 'tb-post-comments',
271 [
272 'Custom empty text and ordering',
273 'Extended styling for lists and form',
274 ]
275 );
276 }
277
278 /**
279 * Render output helper.
280 *
281 * @param array<string, mixed> $settings Settings.
282 * @param bool $is_pro Whether Pro features are enabled.
283 *
284 * @return void
285 */
286 protected function render_output(array $settings, bool $is_pro): void
287 {
288 $post = get_post();
289 if (!$post instanceof \WP_Post) {
290 return;
291 }
292
293 if (!comments_open($post) && ('yes' === ($settings['kng_hide_when_closed'] ?? ''))) {
294 return;
295 }
296
297 $show = $settings['kng_show'] ?? 'both';
298 $show_list = in_array($show, ['list', 'both'], true);
299 $show_form = in_array($show, ['form', 'both'], true);
300
301 echo '<div class="king-addons-tb-post-comments">';
302
303 if ($show_list) {
304 $comments = get_comments(
305 [
306 'post_id' => $post->ID,
307 'status' => 'approve',
308 'order' => $is_pro ? ($settings['kng_order'] ?? 'ASC') : 'ASC',
309 ]
310 );
311
312 if (!empty($comments)) {
313 echo '<div class="king-addons-tb-post-comments__heading">' . esc_html__('Comments', 'king-addons') . '</div>';
314 echo '<ol class="king-addons-tb-post-comments__list">';
315 foreach ($comments as $comment) {
316 echo '<li class="king-addons-tb-post-comments__item">';
317 echo '<div class="king-addons-tb-post-comments__meta">' . esc_html(get_comment_author($comment)) . ' · ' . esc_html(get_comment_date('', $comment)) . '</div>';
318 echo '<div class="king-addons-tb-post-comments__content">' . wp_kses_post(get_comment_text($comment)) . '</div>';
319 echo '</li>';
320 }
321 echo '</ol>';
322 } else {
323 $empty_text = $is_pro ? ($settings['kng_no_comments_text'] ?? '') : '';
324 if ($empty_text) {
325 echo '<div class="king-addons-tb-post-comments__empty">' . esc_html($empty_text) . '</div>';
326 }
327 }
328 }
329
330 if ($show_form && comments_open($post)) {
331 echo '<div class="king-addons-tb-post-comments__form">';
332 comment_form(
333 [
334 'title_reply' => esc_html__('Leave a comment', 'king-addons'),
335 'label_submit' => esc_html__('Post Comment', 'king-addons'),
336 'comment_notes_after' => '',
337 ],
338 $post->ID
339 );
340 echo '</div>';
341 }
342
343 echo '</div>';
344 }
345 }
346