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

346 lines 10.6 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 $this->end_controls_section();
61
62
63 $this->start_controls_section(
64 'form_content_label',
65 [
66 'label' => __( 'Label', 'easy-elements' ),
67 'tab' => Controls_Manager::TAB_CONTENT,
68 ]
69 );
70
71 $this->add_control(
72 'input_label_color',
73 [
74 'label' => __( 'Color', 'easy-elements' ),
75 'type' => Controls_Manager::COLOR,
76 'selectors' => [
77 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form label' => 'color: {{VALUE}};',
78 ],
79 ]
80 );
81
82 $this->add_responsive_control(
83 'input_label_margin',[
84 'label' => __( 'Margin', 'easy-elements' ),
85 'type' => Controls_Manager::DIMENSIONS,
86 'size_units' => [ 'px', '%', 'em' ],
87 'selectors' => [
88 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form label' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
89 ],
90 ]
91 );
92
93 // Input Color Picker
94 $this->add_group_control(
95 \Elementor\Group_Control_Typography::get_type(),
96 [
97 'name' => 'input_label_typography',
98 'label' => __( 'Typography', 'easy-elements' ),
99 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form label',
100 'description' => __( 'Customize the typography for form field labels', 'easy-elements' ),
101 ]
102 );
103 $this->end_controls_section();
104
105 // form style
106 $this->start_controls_section(
107 'form_content',
108 [
109 'label' => __( 'Input', 'easy-elements' ),
110 'tab' => Controls_Manager::TAB_CONTENT,
111 ]
112 );
113
114 // Input Color Picker
115 $this->add_control(
116 'input_color',
117 [
118 'label' => __( 'Color', 'easy-elements' ),
119 'type' => Controls_Manager::COLOR,
120 'selectors' => [
121 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea' => 'color: {{VALUE}};',
122 ],
123 ]
124 );
125
126 $this->add_group_control(
127 \Elementor\Group_Control_Background::get_type(),
128 [
129 'name' => 'input_background',
130 'label' => __( 'Background', 'easy-elements' ),
131 'types' => ['classic', 'gradient'],
132 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea',
133 'description' => __( 'Customize the background for form input fields', 'easy-elements' ),
134 ]
135 );
136
137 $this->add_control(
138 'input_focus_color',
139 [
140 'label' => __( 'Focus Color', 'easy-elements' ),
141 'type' => Controls_Manager::COLOR,
142 'selectors' => [
143 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:focus, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea:focus' => 'color: {{VALUE}};',
144 ],
145 'description' => __( 'Select the text color for form fields when focused', 'easy-elements' ),
146 ]
147 );
148
149 $this->add_group_control(
150 \Elementor\Group_Control_Typography::get_type(),
151 [
152 'name' => 'input_form_typography',
153 'label' => __( 'Input Typography', 'easy-elements' ),
154 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea',
155 'description' => __( 'Customize the typography for form field inputs', 'easy-elements' ),
156 ]
157 );
158
159 $this->add_control(
160 'placeholder_color',
161 [
162 'label' => __( 'Placeholder Color', 'easy-elements' ),
163 'type' => Controls_Manager::COLOR,
164 'selectors' => [
165 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input::placeholder, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea::placeholder' => 'color: {{VALUE}};',
166 ],
167 'description' => __( 'Select the color for placeholder text in form fields', 'easy-elements' ),
168 ]
169 );
170
171 $this->add_control(
172 'input_focus_border_color',
173 [
174 'label' => __( 'Focus Border Color', 'easy-elements' ),
175 'type' => Controls_Manager::COLOR,
176 'selectors' => [
177 // Use :focus-visible for better accessibility
178 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:focus-visible, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea:focus-visible' => 'outline-color: {{VALUE}} !important;',
179 ],
180 'description' => __( 'Select the border color for form fields when focused via keyboard navigation', 'easy-elements' ),
181 ]
182 );
183
184 $this->add_responsive_control(
185 'input_form_padding',[
186 'label' => __( 'Padding', 'easy-elements' ),
187 'type' => Controls_Manager::DIMENSIONS,
188 'size_units' => [ 'px', '%', 'em' ],
189 'selectors' => [
190 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
191 ],
192 ]
193 );
194
195 $this->add_responsive_control(
196 'input_border_radius',
197 [
198 'label' => __( 'Border Radius', 'easy-elements' ),
199 'type' => Controls_Manager::DIMENSIONS,
200 'size_units' => [ 'px', '%', 'em' ],
201 'selectors' => [
202 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
203 ],
204 ]
205 );
206
207 $this->add_group_control(
208 \Elementor\Group_Control_Border::get_type(),
209 [
210 'name' => 'input_border',
211 'label' => __( 'Border', 'easy-elements' ),
212 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea',
213 ]
214 );
215
216 $this->end_controls_section();
217
218 $this->start_controls_section(
219 'comments_content_button_style',
220 [
221 'label' => __( 'Button', 'easy-elements' ),
222 'tab' => Controls_Manager::TAB_CONTENT,
223 ]
224 );
225
226 $this->add_control(
227 'button_color',
228 [
229 'label' => esc_html__( 'Color', 'easy-elements' ),
230 'type' => Controls_Manager::COLOR,
231 'selectors' => [
232 '{{WRAPPER}} .comment-respond .form-submit #submit' => 'color: {{VALUE}};',
233 ],
234 ]
235 );
236 $this->add_control(
237 'button_hover_color',
238 [
239 'label' => esc_html__( 'Color (Hover)', 'easy-elements' ),
240 'type' => Controls_Manager::COLOR,
241 'selectors' => [
242 '{{WRAPPER}} .comment-respond .form-submit #submit:hover' => 'color: {{VALUE}};',
243 ],
244 ]
245 );
246 $this->add_control(
247 'button_bg_color',
248 [
249 'label' => esc_html__( 'Background', 'easy-elements' ),
250 'type' => Controls_Manager::COLOR,
251 'selectors' => [
252 '{{WRAPPER}} .comment-respond .form-submit #submit' => 'background: {{VALUE}};',
253 ],
254 ]
255 );
256 $this->add_control(
257 'button_bg_hover_color',
258 [
259 'label' => esc_html__( 'Background (Hover)', 'easy-elements' ),
260 'type' => Controls_Manager::COLOR,
261 'selectors' => [
262 '{{WRAPPER}} .comment-respond .form-submit #submit:hover' => 'background: {{VALUE}};',
263 ],
264 ]
265 );
266 $this->add_group_control(
267 \Elementor\Group_Control_Typography::get_type(),
268 [
269 'name' => 'button_typography',
270 'selector' => '{{WRAPPER}} .comment-respond .form-submit #submit',
271 ]
272 );
273 $this->add_responsive_control(
274 'button_padding',
275 [
276 'label' => esc_html__('Padding', 'easy-elements'),
277 'type' => \Elementor\Controls_Manager::DIMENSIONS,
278 'size_units' => ['px', 'em', '%'],
279 'selectors' => [
280 '{{WRAPPER}} .comment-respond .form-submit #submit' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
281 ],
282 ]
283 );
284
285 $this->end_controls_section();
286 }
287
288
289 protected function render() {
290 $settings = $this->get_settings_for_display();
291
292 global $post;
293 $original_post = $post;
294
295 // Get post object: editor mode uses prepared post, frontend uses current post
296 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
297 if ( ($settings['show_comments'] ?? 'no') !== 'yes' ) {
298 // Editor mode: show nothing if 'show_comments' is not 'yes'
299 echo '<p>' . esc_html__( 'Comments are disabled in editor preview.', 'easy-elements' ) . '</p>';
300 return;
301 }
302
303 $post_id = function_exists('easyel_get_prepared_post_id')
304 ? easyel_get_prepared_post_id()
305 : get_the_ID();
306 $post_obj = get_post( $post_id );
307
308 } else {
309 if ( ($settings['show_comments'] ?? 'no') !== 'yes' ) {
310 // Frontend: comments disabled in settings
311 return;
312 }
313
314 $post_obj = $post;
315 if ( ! $post_obj instanceof \WP_Post ) {
316 echo '<p>' . esc_html__( 'Invalid post object.', 'easy-elements' ) . '</p>';
317 return;
318 }
319 }
320
321 $post = $post_obj;
322 setup_postdata( $post );
323
324 echo '<div class="eel-post-comments-widget">';
325
326 if ( post_type_supports( $post->post_type, 'comments' ) ) {
327 if ( post_password_required() ) {
328 echo '<p>' . esc_html__( 'This post is password protected. Enter the password to view comments.', 'easy-elements' ) . '</p>';
329 } else {
330 comments_template();
331 }
332 } else {
333 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
334 echo '<p>' . esc_html__( 'Comments are not enabled for this post type.', 'easy-elements' ) . '</p>';
335 }
336 }
337
338 echo '</div>';
339
340 wp_reset_postdata();
341 $post = $original_post;
342
343 }
344
345 }
346