PluginProbe
Easy Elements for Elementor – Addons & Website Templates / 1.3.1
Easy Elements for Elementor – Addons & Website Templates v1.3.1
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.3.1, at widgets/post-comments/post-comments.php

391 lines 10.7 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 __( 'Post Comments', '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 'input_label_color',
94 [
95 'label' => __( 'Color', 'easy-elements' ),
96 'type' => Controls_Manager::COLOR,
97 'selectors' => [
98 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form label' => 'color: {{VALUE}};',
99 ],
100 ]
101 );
102
103 $this->add_responsive_control(
104 'input_label_margin',[
105 'label' => __( 'Margin', 'easy-elements' ),
106 'type' => Controls_Manager::DIMENSIONS,
107 'size_units' => [ 'px', '%', 'em' ],
108 'selectors' => [
109 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form label' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
110 ],
111 ]
112 );
113
114 // Input Color Picker
115 $this->add_group_control(
116 \Elementor\Group_Control_Typography::get_type(),
117 [
118 'name' => 'input_label_typography',
119 'label' => __( 'Typography', 'easy-elements' ),
120 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form label',
121 'description' => __( 'Customize the typography for form field labels', 'easy-elements' ),
122 ]
123 );
124 $this->end_controls_section();
125
126 // form style
127 $this->start_controls_section(
128 'form_content',
129 [
130 'label' => __( 'Input', 'easy-elements' ),
131 'tab' => Controls_Manager::TAB_CONTENT,
132 ]
133 );
134
135 $this->add_control(
136 'input_color',
137 [
138 'label' => __( 'Color', 'easy-elements' ),
139 'type' => Controls_Manager::COLOR,
140 'selectors' => [
141 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:not([type="submit"]),
142 {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea'
143 => 'color: {{VALUE}};',
144 ],
145 ]
146 );
147
148 $this->add_group_control(
149 \Elementor\Group_Control_Background::get_type(),
150 [
151 'name' => 'input_background',
152 'label' => __( 'Background', 'easy-elements' ),
153 'types' => [ 'classic', 'gradient' ],
154 'selector' =>
155 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:not([type="submit"]),
156 {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea',
157 ]
158 );
159
160 $this->add_control(
161 'input_focus_border_color',
162 [
163 'label' => __( 'Focus Border Color', 'easy-elements' ),
164 'type' => Controls_Manager::COLOR,
165 'selectors' => [
166 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:not([type="submit"]):focus,
167 {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea:focus'
168 => 'border-color: {{VALUE}};',
169 ],
170 ]
171 );
172
173 $this->add_responsive_control(
174 'input_form_padding',
175 [
176 'label' => __( 'Padding', 'easy-elements' ),
177 'type' => Controls_Manager::DIMENSIONS,
178 'size_units' => [ 'px', '%', 'em' ],
179 'selectors' => [
180 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:not([type="submit"]),
181 {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea'
182 => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
183 ],
184 ]
185 );
186
187 /* ================= Border Radius ================= */
188 $this->add_responsive_control(
189 'input_border_radius',
190 [
191 'label' => __( 'Border Radius', 'easy-elements' ),
192 'type' => Controls_Manager::DIMENSIONS,
193 'size_units' => [ 'px', '%', 'em' ],
194 'selectors' => [
195 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:not([type="submit"]),
196 {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea'
197 => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
198 ],
199 ]
200 );
201
202 /* ================= Border ================= */
203 $this->add_group_control(
204 \Elementor\Group_Control_Border::get_type(),
205 [
206 'name' => 'input_border',
207 'selector' =>
208 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:not([type="submit"]),
209 {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea',
210 ]
211 );
212
213 $this->end_controls_section();
214
215
216 $this->start_controls_section(
217 'comments_content_button_style',
218 [
219 'label' => __( 'Button', 'easy-elements' ),
220 'tab' => Controls_Manager::TAB_CONTENT,
221 ]
222 );
223
224 /* Tabs start */
225 $this->start_controls_tabs( 'button_style_tabs' );
226
227 /* ================= NORMAL TAB ================= */
228 $this->start_controls_tab(
229 'button_normal_tab',
230 [
231 'label' => __( 'Normal', 'easy-elements' ),
232 ]
233 );
234
235 $this->add_control(
236 'button_color',
237 [
238 'label' => esc_html__( 'Color', 'easy-elements' ),
239 'type' => Controls_Manager::COLOR,
240 'selectors' => [
241 '{{WRAPPER}} .comment-respond .form-submit #submit' => 'color: {{VALUE}};',
242 ],
243 ]
244 );
245
246 $this->add_control(
247 'button_bg_color',
248 [
249 'label' => esc_html__( 'Background Color', 'easy-elements' ),
250 'type' => Controls_Manager::COLOR,
251 'selectors' => [
252 '{{WRAPPER}} .comment-respond .form-submit #submit' => 'background-color: {{VALUE}};',
253 ],
254 ]
255 );
256
257 /* Typography */
258 $this->add_group_control(
259 \Elementor\Group_Control_Typography::get_type(),
260 [
261 'name' => 'button_typography',
262 'selector' => '{{WRAPPER}} .comment-respond .form-submit #submit',
263 ]
264 );
265
266 /* Padding */
267 $this->add_responsive_control(
268 'button_padding',
269 [
270 'label' => esc_html__( 'Padding', 'easy-elements' ),
271 'type' => Controls_Manager::DIMENSIONS,
272 'size_units' => [ 'px', 'em', '%' ],
273 'selectors' => [
274 '{{WRAPPER}} .comment-respond .form-submit #submit' =>
275 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
276 ],
277 ]
278 );
279
280 $this->add_group_control(
281 \Elementor\Group_Control_Border::get_type(),
282 [
283 'name' => 'button_border',
284 'selector' => '{{WRAPPER}} .comment-respond .form-submit #submit',
285 ]
286 );
287
288 $this->end_controls_tab();
289
290 /* ================= HOVER TAB ================= */
291 $this->start_controls_tab(
292 'button_hover_tab',
293 [
294 'label' => __( 'Hover', 'easy-elements' ),
295 ]
296 );
297
298 $this->add_control(
299 'button_hover_color',
300 [
301 'label' => esc_html__( 'Color', 'easy-elements' ),
302 'type' => Controls_Manager::COLOR,
303 'selectors' => [
304 '{{WRAPPER}} .comment-respond .form-submit #submit:hover' => 'color: {{VALUE}};',
305 ],
306 ]
307 );
308
309 $this->add_control(
310 'button_bg_hover_color',
311 [
312 'label' => esc_html__( 'Background Color', 'easy-elements' ),
313 'type' => Controls_Manager::COLOR,
314 'selectors' => [
315 '{{WRAPPER}} .comment-respond .form-submit #submit:hover' => 'background-color: {{VALUE}};',
316 ],
317 ]
318 );
319
320 $this->add_group_control(
321 \Elementor\Group_Control_Border::get_type(),
322 [
323 'name' => 'button_border_hover',
324 'selector' => '{{WRAPPER}} .comment-respond .form-submit #submit:hover',
325 ]
326 );
327 $this->end_controls_tab();
328 $this->end_controls_tabs();
329 $this->end_controls_section();
330
331 }
332
333
334 protected function render() {
335 $settings = $this->get_settings_for_display();
336
337 global $post;
338 $original_post = $post;
339
340 // Get post object: editor mode uses prepared post, frontend uses current post
341 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
342 if ( ($settings['show_comments'] ?? 'no') !== 'yes' ) {
343 // Editor mode: show nothing if 'show_comments' is not 'yes'
344 echo '<p>' . esc_html__( 'Comments are disabled in editor preview.', 'easy-elements' ) . '</p>';
345 return;
346 }
347
348 $post_id = function_exists('easyel_get_prepared_post_id')
349 ? easyel_get_prepared_post_id()
350 : get_the_ID();
351 $post_obj = get_post( $post_id );
352
353 } else {
354 if ( ($settings['show_comments'] ?? 'no') !== 'yes' ) {
355 // Frontend: comments disabled in settings
356 return;
357 }
358
359 $post_obj = $post;
360 if ( ! $post_obj instanceof \WP_Post ) {
361 echo '<p>' . esc_html__( 'Invalid post object.', 'easy-elements' ) . '</p>';
362 return;
363 }
364 }
365
366 $post = $post_obj;
367 setup_postdata( $post );
368
369 echo '<div class="eel-post-comments-widget">';
370
371 if ( post_type_supports( $post->post_type, 'comments' ) ) {
372 if ( post_password_required() ) {
373 echo '<p>' . esc_html__( 'This post is password protected. Enter the password to view comments.', 'easy-elements' ) . '</p>';
374 } else {
375 comments_template();
376 }
377 } else {
378 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
379 echo '<p>' . esc_html__( 'Comments are not enabled for this post type.', 'easy-elements' ) . '</p>';
380 }
381 }
382
383 echo '</div>';
384
385 wp_reset_postdata();
386 $post = $original_post;
387
388 }
389
390 }
391