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

341 lines 10.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 use Elementor\Widget_Base;
3 use Elementor\Controls_Manager;
4 use Elementor\Group_Control_Typography;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 if( class_exists("Easyel_Free_Post_Comments_Widget")) {
11 return;
12 }
13
14 class Easyel_Free_Post_Comments_Widget extends \Elementor\Widget_Base {
15
16 public function get_style_depends() {
17 $handle = 'eel-post-comments';
18 $css_path = plugin_dir_path( __FILE__ ) . 'css/post-comments.min.css';
19
20 if ( ! wp_style_is( $handle, 'registered' ) && file_exists( $css_path ) ) {
21 wp_register_style( $handle, plugins_url( 'css/post-comments.min.css', __FILE__ ), [], defined( 'WP_DEBUG' ) && WP_DEBUG ? filemtime( $css_path ) : EASYELEMENTS_VER );
22 }
23
24 return [ $handle ];
25 }
26
27 public function get_name() {
28 return 'eel-post-comments';
29 }
30
31 public function get_title() {
32 return __( 'Post Comments', 'easy-elements' );
33 }
34
35 public function get_icon() {
36 return 'easyicon easyelIcon-comments';
37 }
38
39 public function get_categories() {
40 return [ 'easyelements_category_pro' ];
41 }
42
43 public function get_keywords() {
44 return [ 'comments', 'posts', 'next', 'prev', 'page', 'blog' ];
45 }
46
47 protected function register_controls() {
48 // button style
49 $this->start_controls_section(
50 'comments_content',
51 [
52 'label' => __( 'Comments', 'easy-elements' ),
53 'tab' => Controls_Manager::TAB_CONTENT,
54 ]
55 );
56
57 $this->add_control(
58 'show_comments',
59 [
60 'label' => __( 'Show Comments', 'easy-elements' ),
61 'type' => Controls_Manager::SWITCHER,
62 'label_on' => __( 'Yes', 'easy-elements' ),
63 'label_off' => __( 'No', 'easy-elements' ),
64 'default' => '',
65 ]
66 );
67 $this->end_controls_section();
68
69
70 $this->start_controls_section(
71 'form_content_label',
72 [
73 'label' => __( 'Label', 'easy-elements' ),
74 'tab' => Controls_Manager::TAB_CONTENT,
75 ]
76 );
77
78 $this->add_control(
79 'input_label_color',
80 [
81 'label' => __( 'Color', 'easy-elements' ),
82 'type' => Controls_Manager::COLOR,
83 'selectors' => [
84 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form label' => 'color: {{VALUE}};',
85 ],
86 ]
87 );
88
89 $this->add_responsive_control(
90 'input_label_margin',[
91 'label' => __( 'Margin', 'easy-elements' ),
92 'type' => Controls_Manager::DIMENSIONS,
93 'size_units' => [ 'px', '%', 'em' ],
94 'selectors' => [
95 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form label' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
96 ],
97 ]
98 );
99
100 // Input Color Picker
101 $this->add_group_control(
102 \Elementor\Group_Control_Typography::get_type(),
103 [
104 'name' => 'input_label_typography',
105 'label' => __( 'Typography', 'easy-elements' ),
106 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form label',
107 'description' => __( 'Customize the typography for form field labels', 'easy-elements' ),
108 ]
109 );
110 $this->end_controls_section();
111
112 // form style
113 $this->start_controls_section(
114 'form_content',
115 [
116 'label' => __( 'Input', 'easy-elements' ),
117 'tab' => Controls_Manager::TAB_CONTENT,
118 ]
119 );
120
121 // Input Color Picker
122 $this->add_control(
123 'input_color',
124 [
125 'label' => __( 'Color', 'easy-elements' ),
126 'type' => Controls_Manager::COLOR,
127 'selectors' => [
128 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea' => 'color: {{VALUE}};',
129 ],
130 ]
131 );
132
133 $this->add_group_control(
134 \Elementor\Group_Control_Background::get_type(),
135 [
136 'name' => 'input_background',
137 'label' => __( 'Background', 'easy-elements' ),
138 'types' => ['classic', 'gradient'],
139 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea',
140 'description' => __( 'Customize the background for form input fields', 'easy-elements' ),
141 ]
142 );
143
144 $this->add_control(
145 'input_focus_color',
146 [
147 'label' => __( 'Focus Color', 'easy-elements' ),
148 'type' => Controls_Manager::COLOR,
149 'selectors' => [
150 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input:focus, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea:focus' => 'color: {{VALUE}};',
151 ],
152 'description' => __( 'Select the text color for form fields when focused', 'easy-elements' ),
153 ]
154 );
155
156 $this->add_group_control(
157 \Elementor\Group_Control_Typography::get_type(),
158 [
159 'name' => 'input_form_typography',
160 'label' => __( 'Input Typography', 'easy-elements' ),
161 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea',
162 'description' => __( 'Customize the typography for form field inputs', 'easy-elements' ),
163 ]
164 );
165
166 $this->add_control(
167 'placeholder_color',
168 [
169 'label' => __( 'Placeholder Color', 'easy-elements' ),
170 'type' => Controls_Manager::COLOR,
171 'selectors' => [
172 '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input::placeholder, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea::placeholder' => 'color: {{VALUE}};',
173 ],
174 'description' => __( 'Select the color for placeholder text in form fields', 'easy-elements' ),
175 ]
176 );
177
178 $this->add_control(
179 'input_focus_border_color',
180 [
181 'label' => __( 'Focus Border Color', 'easy-elements' ),
182 'type' => Controls_Manager::COLOR,
183 'selectors' => [
184 // Use :focus-visible for better accessibility
185 '{{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;',
186 ],
187 'description' => __( 'Select the border color for form fields when focused via keyboard navigation', 'easy-elements' ),
188 ]
189 );
190
191 $this->add_responsive_control(
192 'input_form_padding',[
193 'label' => __( 'Padding', 'easy-elements' ),
194 'type' => Controls_Manager::DIMENSIONS,
195 'size_units' => [ 'px', '%', 'em' ],
196 'selectors' => [
197 '{{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}};',
198 ],
199 ]
200 );
201
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, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
210 ],
211 ]
212 );
213
214 $this->add_group_control(
215 \Elementor\Group_Control_Border::get_type(),
216 [
217 'name' => 'input_border',
218 'label' => __( 'Border', 'easy-elements' ),
219 'selector' => '{{WRAPPER}} .eel-post-comments-widget #comments .comment-form input, {{WRAPPER}} .eel-post-comments-widget #comments .comment-form textarea',
220 ]
221 );
222
223 $this->end_controls_section();
224
225 $this->start_controls_section(
226 'comments_content_button_style',
227 [
228 'label' => __( 'Button', 'easy-elements' ),
229 'tab' => Controls_Manager::TAB_CONTENT,
230 ]
231 );
232
233 $this->add_control(
234 'button_color',
235 [
236 'label' => esc_html__( 'Color', 'easy-elements' ),
237 'type' => Controls_Manager::COLOR,
238 'selectors' => [
239 '{{WRAPPER}} .comment-respond .form-submit #submit' => 'color: {{VALUE}};',
240 ],
241 ]
242 );
243 $this->add_control(
244 'button_hover_color',
245 [
246 'label' => esc_html__( 'Color (Hover)', 'easy-elements' ),
247 'type' => Controls_Manager::COLOR,
248 'selectors' => [
249 '{{WRAPPER}} .comment-respond .form-submit #submit:hover' => 'color: {{VALUE}};',
250 ],
251 ]
252 );
253 $this->add_control(
254 'button_bg_color',
255 [
256 'label' => esc_html__( 'Background', 'easy-elements' ),
257 'type' => Controls_Manager::COLOR,
258 'selectors' => [
259 '{{WRAPPER}} .comment-respond .form-submit #submit' => 'background: {{VALUE}};',
260 ],
261 ]
262 );
263 $this->add_control(
264 'button_bg_hover_color',
265 [
266 'label' => esc_html__( 'Background (Hover)', 'easy-elements' ),
267 'type' => Controls_Manager::COLOR,
268 'selectors' => [
269 '{{WRAPPER}} .comment-respond .form-submit #submit:hover' => 'background: {{VALUE}};',
270 ],
271 ]
272 );
273 $this->add_group_control(
274 \Elementor\Group_Control_Typography::get_type(),
275 [
276 'name' => 'button_typography',
277 'selector' => '{{WRAPPER}} .comment-respond .form-submit #submit',
278 ]
279 );
280 $this->add_responsive_control(
281 'button_padding',
282 [
283 'label' => esc_html__('Padding', 'easy-elements'),
284 'type' => \Elementor\Controls_Manager::DIMENSIONS,
285 'size_units' => ['px', 'em', '%'],
286 'selectors' => [
287 '{{WRAPPER}} .comment-respond .form-submit #submit' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
288 ],
289 ]
290 );
291
292 $this->end_controls_section();
293 }
294
295
296 protected function render() {
297 $settings = $this->get_settings_for_display();
298
299 // Always show the comment form in Elementor editor mode
300 if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
301 echo '<div class="eel-post-comments-widget">';
302
303 global $post;
304 $has_comments_form = false;
305
306 if ( $post && post_type_supports( $post->post_type, 'comments' ) ) {
307 ob_start();
308 comments_template();
309 $output = ob_get_clean();
310 if ( trim( wp_strip_all_tags( $output ) ) ) {
311 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
312 echo $output;
313 $has_comments_form = true;
314 }
315 }
316
317 if ( ! $has_comments_form ) {
318 // Show only a message for preview
319 echo '<p>' . esc_html__( 'Comments form will appear here on the frontend.', 'easy-elements' ) . '</p>';
320 }
321
322 echo '</div>';
323 return;
324 }
325
326 if ( 'yes' === $settings['show_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 return;
330 }
331
332 // Output the comments template
333 echo '<div class="eel-post-comments-widget">';
334 comments_template();
335 echo '</div>';
336 } else {
337
338 }
339 }
340 }
341