| @@ -1,404 +1,340 @@ | ||
| 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 | - '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}} .comment-respond .form-submit #submit' => 'color: {{VALUE}};', | |
| 256 | - ], | |
| 257 | - ] | |
| 258 | - ); | |
| 259 | - | |
| 260 | - $this->add_control( | |
| 261 | - 'button_bg_color', | |
| 262 | - [ | |
| 263 | - 'label' => esc_html__( 'Background Color', 'easy-elements' ), | |
| 264 | - 'type' => Controls_Manager::COLOR, | |
| 265 | - 'selectors' => [ | |
| 266 | - '{{WRAPPER}} .comment-respond .form-submit #submit' => 'background-color: {{VALUE}};', | |
| 267 | - ], | |
| 268 | - ] | |
| 269 | - ); | |
| 270 | - | |
| 271 | - /* Typography */ | |
| 272 | - $this->add_group_control( | |
| 273 | - \Elementor\Group_Control_Typography::get_type(), | |
| 274 | - [ | |
| 275 | - 'name' => 'button_typography', | |
| 276 | - 'selector' => '{{WRAPPER}} .comment-respond .form-submit #submit', | |
| 277 | - ] | |
| 278 | - ); | |
| 279 | - | |
| 280 | - /* Padding */ | |
| 281 | - $this->add_responsive_control( | |
| 282 | - 'button_padding', | |
| 283 | - [ | |
| 284 | - 'label' => esc_html__( 'Padding', 'easy-elements' ), | |
| 285 | - 'type' => Controls_Manager::DIMENSIONS, | |
| 286 | - 'size_units' => [ 'px', 'em', '%' ], | |
| 287 | - 'selectors' => [ | |
| 288 | - '{{WRAPPER}} .comment-respond .form-submit #submit' => | |
| 289 | - 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', | |
| 290 | - ], | |
| 291 | - ] | |
| 292 | - ); | |
| 293 | - | |
| 294 | - $this->add_group_control( | |
| 295 | - \Elementor\Group_Control_Border::get_type(), | |
| 296 | - [ | |
| 297 | - 'name' => 'button_border', | |
| 298 | - 'selector' => '{{WRAPPER}} .comment-respond .form-submit #submit', | |
| 299 | - ] | |
| 300 | - ); | |
| 301 | - | |
| 302 | - $this->end_controls_tab(); | |
| 303 | - | |
| 304 | - /* ================= HOVER TAB ================= */ | |
| 305 | - $this->start_controls_tab( | |
| 306 | - 'button_hover_tab', | |
| 307 | - [ | |
| 308 | - 'label' => __( 'Hover', 'easy-elements' ), | |
| 309 | - ] | |
| 310 | - ); | |
| 311 | - | |
| 312 | - $this->add_control( | |
| 313 | - 'button_hover_color', | |
| 314 | - [ | |
| 315 | - 'label' => esc_html__( 'Color', 'easy-elements' ), | |
| 316 | - 'type' => Controls_Manager::COLOR, | |
| 317 | - 'selectors' => [ | |
| 318 | - '{{WRAPPER}} .comment-respond .form-submit #submit:hover' => 'color: {{VALUE}};', | |
| 319 | - ], | |
| 320 | - ] | |
| 321 | - ); | |
| 322 | - | |
| 323 | - $this->add_control( | |
| 324 | - 'button_bg_hover_color', | |
| 325 | - [ | |
| 326 | - 'label' => esc_html__( 'Background Color', 'easy-elements' ), | |
| 327 | - 'type' => Controls_Manager::COLOR, | |
| 328 | - 'selectors' => [ | |
| 329 | - '{{WRAPPER}} .comment-respond .form-submit #submit:hover' => 'background-color: {{VALUE}};', | |
| 330 | - ], | |
| 331 | - ] | |
| 332 | - ); | |
| 333 | - | |
| 334 | - $this->add_group_control( | |
| 335 | - \Elementor\Group_Control_Border::get_type(), | |
| 336 | - [ | |
| 337 | - 'name' => 'button_border_hover', | |
| 338 | - 'selector' => '{{WRAPPER}} .comment-respond .form-submit #submit:hover', | |
| 339 | - ] | |
| 340 | - ); | |
| 341 | - $this->end_controls_tab(); | |
| 342 | - $this->end_controls_tabs(); | |
| 343 | - $this->end_controls_section(); | |
| 344 | - | |
| 345 | - } | |
| 346 | - | |
| 347 | - | |
| 348 | - protected function render() { | |
| 349 | - $settings = $this->get_settings_for_display(); | |
| 350 | - | |
| 351 | - global $post; | |
| 352 | - $original_post = $post; | |
| 353 | - | |
| 354 | - // Get post object: editor mode uses prepared post, frontend uses current post | |
| 355 | - if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { | |
| 356 | - if ( ($settings['show_comments'] ?? 'no') !== 'yes' ) { | |
| 357 | - // Editor mode: show nothing if 'show_comments' is not 'yes' | |
| 358 | - echo '<p>' . esc_html__( 'Comments are disabled in editor preview.', 'easy-elements' ) . '</p>'; | |
| 359 | - return; | |
| 360 | - } | |
| 361 | - | |
| 362 | - $post_id = function_exists('easyel_get_prepared_post_id') | |
| 363 | - ? easyel_get_prepared_post_id() | |
| 364 | - : get_the_ID(); | |
| 365 | - $post_obj = get_post( $post_id ); | |
| 366 | - | |
| 367 | - } else { | |
| 368 | - if ( ($settings['show_comments'] ?? 'no') !== 'yes' ) { | |
| 369 | - // Frontend: comments disabled in settings | |
| 370 | - return; | |
| 371 | - } | |
| 372 | - | |
| 373 | - $post_obj = $post; | |
| 374 | - if ( ! $post_obj instanceof \WP_Post ) { | |
| 375 | - echo '<p>' . esc_html__( 'Invalid post object.', 'easy-elements' ) . '</p>'; | |
| 376 | - return; | |
| 377 | - } | |
| 378 | - } | |
| 379 | - | |
| 380 | - $post = $post_obj; | |
| 381 | - setup_postdata( $post ); | |
| 382 | - $label_class = ! empty( $settings['show_label'] ) ? $settings['show_label'] : ''; | |
| 383 | - echo '<div class="eel-post-comments-widget label--' . esc_attr( $label_class ) . ' ">'; | |
| 384 | - | |
| 385 | - if ( post_type_supports( $post->post_type, 'comments' ) ) { | |
| 386 | - if ( post_password_required() ) { | |
| 387 | - echo '<p>' . esc_html__( 'This post is password protected. Enter the password to view comments.', 'easy-elements' ) . '</p>'; | |
| 388 | - } else { | |
| 389 | - comments_template(); | |
| 390 | - } | |
| 391 | - } else { | |
| 392 | - if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { | |
| 393 | - echo '<p>' . esc_html__( 'Comments are not enabled for this post type.', 'easy-elements' ) . '</p>'; | |
| 394 | - } | |
| 395 | - } | |
| 396 | - | |
| 397 | - echo '</div>'; | |
| 398 | - | |
| 399 | - wp_reset_postdata(); | |
| 400 | - $post = $original_post; | |
| 401 | - | |
| 402 | - } | |
| 403 | - | |
| 404 | -} | |
| 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 | +} | |