PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.5.3
Easy Elements for Elementor – Addons & Website Templates v1.5.3
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / widgets / post-comments / post-comments.php

post-comments.php in Easy Elements for Elementor – Addons & Website Templates 1.5.3, at widgets/post-comments/post-comments.php

429 lines 12.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Easyel\EasyElements\Widgets;
3 use Elementor\Widget_Base;
4 use Elementor\Controls_Manager;
5 use Elementor\Group_Control_Typography;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 class Easyel_Free_Post_Comments_Widget extends \Elementor\Widget_Base {
12
13 public function get_name() {
14 return 'eel-post-comments';
15 }
16
17 public function get_title() {
18 return __( 'Comments Box', 'easy-elements' );
19 }
20
21 public function get_icon() {
22 return 'easyicon easyelIcon-comments';
23 }
24
25 public function get_categories() {
26 return [ 'easyelements_category' ];
27 }
28
29 public function get_keywords() {
30 return [ 'comments', 'posts', 'next', 'prev', 'page', 'blog' ];
31 }
32
33 public function get_style_depends() {
34 return [
35 'eel-post-comments',
36 ];
37 }
38
39
40 protected function register_controls() {
41 // button style
42 $this->start_controls_section(
43 'comments_content',
44 [
45 'label' => __( 'Comments', 'easy-elements' ),
46 'tab' => Controls_Manager::TAB_CONTENT,
47 ]
48 );
49
50 $this->add_control(
51 'show_comments',
52 [
53 'label' => __( 'Show Comments', 'easy-elements' ),
54 'type' => Controls_Manager::SWITCHER,
55 'label_on' => __( 'Yes', 'easy-elements' ),
56 'label_off' => __( 'No', 'easy-elements' ),
57 'default' => '',
58 ]
59 );
60
61 $this->add_control(
62 'input__color',
63 [
64 'label' => __( 'Color', 'easy-elements' ),
65 'type' => Controls_Manager::COLOR,
66 'selectors' => [
67 '{{WRAPPER}} .eel-post-comments-widget .comment-respond, {{WRAPPER}} .eel-post-comments-widget .title-comments, {{WRAPPER}} .eel-post-comments-widget .comment-list *' => 'color: {{VALUE}};',
68 ],
69 ]
70 );
71 $this->add_control(
72 'input__color_link',
73 [
74 'label' => __( 'Link Color', 'easy-elements' ),
75 'type' => Controls_Manager::COLOR,
76 'selectors' => [
77 '{{WRAPPER}} .eel-post-comments-widget .comment-respond a' => 'color: {{VALUE}};',
78 ],
79 ]
80 );
81
82 $this->end_controls_section();
83
84 $this->start_controls_section(
85 'form_content_label',
86 [
87 'label' => __( 'Label', 'easy-elements' ),
88 'tab' => Controls_Manager::TAB_CONTENT,
89 ]
90 );
91
92 $this->add_control(
93 'show_label',
94 [
95 'label' => __( 'Show Label', 'easy-elements' ),
96 'type' => Controls_Manager::SWITCHER,
97 'label_on' => __( 'Yes', 'easy-elements' ),
98 'label_off' => __( 'No', 'easy-elements' ),
99 'default' => 'yes',
100 ]
101 );
102
103 $this->add_control(
104 'input_label_color',
105 [
106 'label' => __( 'Color', 'easy-elements' ),
107 'type' => Controls_Manager::COLOR,
108 'selectors' => [
109 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form label' => 'color: {{VALUE}};',
110 ],
111 'condition' => [ 'show_label' => 'yes' ],
112 ]
113 );
114
115 $this->add_responsive_control(
116 'input_label_margin',[
117 'label' => __( 'Margin', 'easy-elements' ),
118 'type' => Controls_Manager::DIMENSIONS,
119 'size_units' => [ 'px', '%', 'em' ],
120 'selectors' => [
121 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form label' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
122 ],
123 'condition' => [ 'show_label' => 'yes' ],
124 ]
125 );
126
127 // Input Color Picker
128 $this->add_group_control(
129 \Elementor\Group_Control_Typography::get_type(),
130 [
131 'name' => 'input_label_typography',
132 'label' => __( 'Typography', 'easy-elements' ),
133 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form label',
134 'description' => __( 'Customize the typography for form field labels', 'easy-elements' ),
135 'condition' => [ 'show_label' => 'yes' ],
136 ]
137 );
138 $this->end_controls_section();
139
140 // form style
141 $this->start_controls_section(
142 'form_content',
143 [
144 'label' => __( 'Input', 'easy-elements' ),
145 'tab' => Controls_Manager::TAB_CONTENT,
146 ]
147 );
148
149 $this->add_control(
150 'input_color',
151 [
152 'label' => __( 'Color', 'easy-elements' ),
153 'type' => Controls_Manager::COLOR,
154 'selectors' => [
155 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:not([type="submit"]),
156 {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea'
157 => 'color: {{VALUE}};',
158 ],
159 ]
160 );
161
162 $this->add_group_control(
163 \Elementor\Group_Control_Background::get_type(),
164 [
165 'name' => 'input_background',
166 'label' => __( 'Background', 'easy-elements' ),
167 'types' => [ 'classic', 'gradient' ],
168 'selector' =>
169 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:not([type="submit"]),
170 {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea',
171 ]
172 );
173
174 $this->add_control(
175 'input_focus_border_color',
176 [
177 'label' => __( 'Focus Border Color', 'easy-elements' ),
178 'type' => Controls_Manager::COLOR,
179 'selectors' => [
180 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:not([type="submit"]):focus,
181 {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea:focus'
182 => 'border-color: {{VALUE}};',
183 ],
184 ]
185 );
186
187 $this->add_responsive_control(
188 'input_form_padding',
189 [
190 'label' => __( 'Padding', 'easy-elements' ),
191 'type' => Controls_Manager::DIMENSIONS,
192 'size_units' => [ 'px', '%', 'em' ],
193 'selectors' => [
194 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:not([type="submit"]),
195 {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea'
196 => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
197 ],
198 ]
199 );
200
201 /* ================= Border Radius ================= */
202 $this->add_responsive_control(
203 'input_border_radius',
204 [
205 'label' => __( 'Border Radius', 'easy-elements' ),
206 'type' => Controls_Manager::DIMENSIONS,
207 'size_units' => [ 'px', '%', 'em' ],
208 'selectors' => [
209 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:not([type="submit"]),
210 {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea'
211 => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
212 ],
213 ]
214 );
215
216 /* ================= Border ================= */
217 $this->add_group_control(
218 \Elementor\Group_Control_Border::get_type(),
219 [
220 'name' => 'input_border',
221 'selector' =>
222 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:not([type="submit"]),
223 {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea',
224 ]
225 );
226
227 $this->end_controls_section();
228
229
230 $this->start_controls_section(
231 'comments_content_button_style',
232 [
233 'label' => __( 'Button', 'easy-elements' ),
234 'tab' => Controls_Manager::TAB_CONTENT,
235 ]
236 );
237
238 /* Tabs start */
239 $this->start_controls_tabs( 'button_style_tabs' );
240
241 /* ================= NORMAL TAB ================= */
242 $this->start_controls_tab(
243 'button_normal_tab',
244 [
245 'label' => __( 'Normal', 'easy-elements' ),
246 ]
247 );
248
249 $this->add_control(
250 'button_color',
251 [
252 'label' => esc_html__( 'Color', 'easy-elements' ),
253 'type' => Controls_Manager::COLOR,
254 'selectors' => [
255 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-respond .form-submit #submit' => 'color: {{VALUE}};',
256 ],
257 ]
258 );
259
260 $this->add_group_control(
261 \Elementor\Group_Control_Background::get_type(),
262 [
263 'name' => 'button_bg_color',
264 'label' => esc_html__( 'Background', 'easy-elements' ),
265 'types' => [ 'classic', 'gradient' ],
266 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-respond .form-submit #submit',
267 ]
268 );
269
270 /* Typography */
271 $this->add_group_control(
272 \Elementor\Group_Control_Typography::get_type(),
273 [
274 'name' => 'button_typography',
275 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-respond .form-submit #submit',
276 ]
277 );
278
279 /* Padding */
280 $this->add_responsive_control(
281 'button_padding',
282 [
283 'label' => esc_html__( 'Padding', 'easy-elements' ),
284 'type' => Controls_Manager::DIMENSIONS,
285 'size_units' => [ 'px', 'em', '%' ],
286 'selectors' => [
287 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-respond .form-submit #submit' =>
288 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
289 ],
290 ]
291 );
292
293 $this->add_group_control(
294 \Elementor\Group_Control_Border::get_type(),
295 [
296 'name' => 'button_border',
297 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-respond .form-submit #submit',
298 ]
299 );
300
301 $this->add_responsive_control(
302 'button_border_radius',
303 [
304 'label' => esc_html__( 'Border Radius', 'easy-elements' ),
305 'type' => Controls_Manager::DIMENSIONS,
306 'size_units' => [ 'px', '%', 'em' ],
307 'selectors' => [
308 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-respond .form-submit #submit' =>
309 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
310 ],
311 ]
312 );
313
314 $this->end_controls_tab();
315
316 /* ================= HOVER TAB ================= */
317 $this->start_controls_tab(
318 'button_hover_tab',
319 [
320 'label' => __( 'Hover', 'easy-elements' ),
321 ]
322 );
323
324 $this->add_control(
325 'button_hover_color',
326 [
327 'label' => esc_html__( 'Color', 'easy-elements' ),
328 'type' => Controls_Manager::COLOR,
329 'selectors' => [
330 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-respond .form-submit #submit:hover' => 'color: {{VALUE}};',
331 ],
332 ]
333 );
334
335 $this->add_group_control(
336 \Elementor\Group_Control_Background::get_type(),
337 [
338 'name' => 'button_bg_hover_color',
339 'label' => esc_html__( 'Background', 'easy-elements' ),
340 'types' => [ 'classic', 'gradient' ],
341 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-respond .form-submit #submit:hover',
342 ]
343 );
344
345 $this->add_group_control(
346 \Elementor\Group_Control_Border::get_type(),
347 [
348 'name' => 'button_border_hover',
349 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-respond .form-submit #submit:hover',
350 ]
351 );
352
353 $this->add_responsive_control(
354 'button_border_radius_hover',
355 [
356 'label' => esc_html__( 'Border Radius', 'easy-elements' ),
357 'type' => Controls_Manager::DIMENSIONS,
358 'size_units' => [ 'px', '%', 'em' ],
359 'selectors' => [
360 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-respond .form-submit #submit:hover' =>
361 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
362 ],
363 ]
364 );
365 $this->end_controls_tab();
366 $this->end_controls_tabs();
367 $this->end_controls_section();
368
369 }
370
371
372 protected function render() {
373 $settings = $this->get_settings_for_display();
374
375 global $post;
376 $original_post = $post;
377
378 // Get post object: editor mode uses prepared post, frontend uses current post
379 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
380 if ( ($settings['show_comments'] ?? 'no') !== 'yes' ) {
381 // Editor mode: show nothing if 'show_comments' is not 'yes'
382 echo '<p>' . esc_html__( 'Comments are disabled in editor preview.', 'easy-elements' ) . '</p>';
383 return;
384 }
385
386 $post_id = function_exists('easyel_get_prepared_post_id')
387 ? easyel_get_prepared_post_id()
388 : get_the_ID();
389 $post_obj = get_post( $post_id );
390
391 } else {
392 if ( ($settings['show_comments'] ?? 'no') !== 'yes' ) {
393 // Frontend: comments disabled in settings
394 return;
395 }
396
397 $post_obj = $post;
398 if ( ! $post_obj instanceof \WP_Post ) {
399 echo '<p>' . esc_html__( 'Invalid post object.', 'easy-elements' ) . '</p>';
400 return;
401 }
402 }
403
404 $post = $post_obj;
405 setup_postdata( $post );
406 $label_class = ! empty( $settings['show_label'] ) ? $settings['show_label'] : '';
407 echo '<div class="eel-post-comments-widget label--' . esc_attr( $label_class ) . ' ">';
408
409 if ( post_type_supports( $post->post_type, 'comments' ) ) {
410 if ( post_password_required() ) {
411 echo '<p>' . esc_html__( 'This post is password protected. Enter the password to view comments.', 'easy-elements' ) . '</p>';
412 } else {
413 comments_template();
414 }
415 } else {
416 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
417 echo '<p>' . esc_html__( 'Comments are not enabled for this post type.', 'easy-elements' ) . '</p>';
418 }
419 }
420
421 echo '</div>';
422
423 wp_reset_postdata();
424 $post = $original_post;
425
426 }
427
428 }
429