| 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 |
} |
| 405 |
|