PluginProbe
Elementor Website Builder – more than just a page builder / 3.17.2
Elementor Website Builder – more than just a page builder v3.17.2
4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 All 454 releases
← All changes | includes/widgets/star-rating.php +33 -108 4.3.13.17.2 View file →
@@ -72,27 +72,9 @@
72 72 public function get_keywords() {
73 73 return [ 'star', 'rating', 'rate', 'review' ];
74 74 }
75 75
76 - protected function is_dynamic_content(): bool {
77 - return false;
78 - }
79 -
80 76 /**
81 - * Get style dependencies.
82 - *
83 - * Retrieve the list of style dependencies the widget requires.
84 - *
85 - * @since 3.24.0
86 - * @access public
87 - *
88 - * @return array Widget style dependencies.
89 - */
90 - public function get_style_depends(): array {
91 - return [ 'widget-star-rating' ];
92 - }
93 -
94 - /**
95 77 * Hide widget from panel.
96 78 *
97 79 * Hide the star rating widget from the panel.
98 80 *
@@ -102,12 +84,8 @@
102 84 public function show_in_panel(): bool {
103 85 return false;
104 86 }
105 87
106 - public function has_widget_inner_wrapper(): bool {
107 - return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
108 - }
109 -
110 88 /**
111 89 * Register star rating widget controls.
112 90 *
113 91 * Adds different input fields to allow the user to change and customize the widget settings.
@@ -118,9 +96,9 @@
118 96 protected function register_controls() {
119 97 $this->start_controls_section(
120 98 'section_rating',
121 99 [
122 - 'label' => esc_html__( 'Star Rating', 'elementor' ),
100 + 'label' => esc_html__( 'Rating', 'elementor' ),
123 101 ]
124 102 );
125 103
126 104 if ( Plugin::$instance->widgets_manager->get_widget_types( 'rating' ) ) {
@@ -214,10 +192,10 @@
214 192 [
215 193 'label' => esc_html__( 'Alignment', 'elementor' ),
216 194 'type' => Controls_Manager::CHOOSE,
217 195 'options' => [
218 - 'start' => [
219 - 'title' => esc_html__( 'Start', 'elementor' ),
196 + 'left' => [
197 + 'title' => esc_html__( 'Left', 'elementor' ),
220 198 'icon' => 'eicon-text-align-left',
221 199 ],
222 200 'center' => [
223 201 'title' => esc_html__( 'Center', 'elementor' ),
@@ -222,10 +200,10 @@
222 200 'center' => [
223 201 'title' => esc_html__( 'Center', 'elementor' ),
224 202 'icon' => 'eicon-text-align-center',
225 203 ],
226 - 'end' => [
227 - 'title' => esc_html__( 'End', 'elementor' ),
204 + 'right' => [
205 + 'title' => esc_html__( 'Right', 'elementor' ),
228 206 'icon' => 'eicon-text-align-right',
229 207 ],
230 208 'justify' => [
231 209 'title' => esc_html__( 'Justified', 'elementor' ),
@@ -231,17 +209,8 @@
231 209 'title' => esc_html__( 'Justified', 'elementor' ),
232 210 'icon' => 'eicon-text-align-justify',
233 211 ],
234 212 ],
235 - 'classes' => 'elementor-control-start-end',
236 - 'classes_dictionary' => [
237 - 'left' => is_rtl() ? 'end' : 'start',
238 - 'right' => is_rtl() ? 'start' : 'end',
239 - ],
240 - 'selectors_dictionary' => [
241 - 'left' => is_rtl() ? 'end' : 'start',
242 - 'right' => is_rtl() ? 'start' : 'end',
243 - ],
244 213 'prefix_class' => 'elementor-star-rating%s--align-',
245 214 'selectors' => [
246 215 '{{WRAPPER}}' => 'text-align: {{VALUE}}',
247 216 ],
@@ -298,24 +267,17 @@
298 267 'title_gap',
299 268 [
300 269 'label' => esc_html__( 'Gap', 'elementor' ),
301 270 'type' => Controls_Manager::SLIDER,
302 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
303 271 'range' => [
304 272 'px' => [
273 + 'min' => 0,
305 274 'max' => 50,
306 275 ],
307 - 'em' => [
308 - 'min' => 0,
309 - 'max' => 5,
310 - ],
311 - 'rem' => [
312 - 'min' => 0,
313 - 'max' => 5,
314 - ],
315 276 ],
316 277 'selectors' => [
317 - '{{WRAPPER}}:not(.elementor-star-rating--align-justify) .elementor-star-rating__title' => 'margin-inline-end: {{SIZE}}{{UNIT}}',
278 + 'body:not(.rtl) {{WRAPPER}}:not(.elementor-star-rating--align-justify) .elementor-star-rating__title' => 'margin-right: {{SIZE}}{{UNIT}}',
279 + 'body.rtl {{WRAPPER}}:not(.elementor-star-rating--align-justify) .elementor-star-rating__title' => 'margin-left: {{SIZE}}{{UNIT}}',
318 280 ],
319 281 ]
320 282 );
321 283
@@ -333,21 +295,13 @@
333 295 'icon_size',
334 296 [
335 297 'label' => esc_html__( 'Size', 'elementor' ),
336 298 'type' => Controls_Manager::SLIDER,
337 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
338 299 'range' => [
339 300 'px' => [
301 + 'min' => 0,
340 302 'max' => 100,
341 303 ],
342 - 'em' => [
343 - 'min' => 0,
344 - 'max' => 10,
345 - ],
346 - 'rem' => [
347 - 'min' => 0,
348 - 'max' => 10,
349 - ],
350 304 ],
351 305 'selectors' => [
352 306 '{{WRAPPER}} .elementor-star-rating' => 'font-size: {{SIZE}}{{UNIT}}',
353 307 ],
@@ -358,24 +312,17 @@
358 312 'icon_space',
359 313 [
360 314 'label' => esc_html__( 'Spacing', 'elementor' ),
361 315 'type' => Controls_Manager::SLIDER,
362 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
363 316 'range' => [
364 317 'px' => [
318 + 'min' => 0,
365 319 'max' => 50,
366 320 ],
367 - 'em' => [
368 - 'min' => 0,
369 - 'max' => 5,
370 - ],
371 - 'rem' => [
372 - 'min' => 0,
373 - 'max' => 5,
374 - ],
375 321 ],
376 322 'selectors' => [
377 - '{{WRAPPER}} .elementor-star-rating i:not(:last-of-type)' => 'margin-inline-end: {{SIZE}}{{UNIT}}',
323 + 'body:not(.rtl) {{WRAPPER}} .elementor-star-rating i:not(:last-of-type)' => 'margin-right: {{SIZE}}{{UNIT}}',
324 + 'body.rtl {{WRAPPER}} .elementor-star-rating i:not(:last-of-type)' => 'margin-left: {{SIZE}}{{UNIT}}',
378 325 ],
379 326 ]
380 327 );
381 328
@@ -411,9 +358,9 @@
411 358 */
412 359 protected function get_rating() {
413 360 $settings = $this->get_settings_for_display();
414 361 $rating_scale = (int) $settings['rating_scale'];
415 - $rating = min( (float) $settings['rating'], $rating_scale );
362 + $rating = (float) $settings['rating'] > $rating_scale ? $rating_scale : $settings['rating'];
416 363
417 364 return [ $rating, $rating_scale ];
418 365 }
419 366
@@ -434,17 +381,17 @@
434 381 $stars_html = '';
435 382
436 383 for ( $stars = 1.0; $stars <= $rating_data[1]; $stars++ ) {
437 384 if ( $stars <= $floored_rating ) {
438 - $stars_html .= '<i class="elementor-star-full" aria-hidden="true">' . $icon . '</i>';
385 + $stars_html .= '<i class="elementor-star-full">' . $icon . '</i>';
439 386 } elseif ( $floored_rating + 1 === $stars && $rating !== $floored_rating ) {
440 - $stars_html .= '<i class="elementor-star-' . ( $rating - $floored_rating ) * 10 . '" aria-hidden="true">' . $icon . '</i>';
387 + $stars_html .= '<i class="elementor-star-' . ( $rating - $floored_rating ) * 10 . '">' . $icon . '</i>';
441 388 } else {
442 - $stars_html .= '<i class="elementor-star-empty" aria-hidden="true">' . $icon . '</i>';
389 + $stars_html .= '<i class="elementor-star-empty">' . $icon . '</i>';
443 390 }
444 391 }
445 392
446 - Utils::print_unescaped_internal_string( $stars_html );
393 + return $stars_html;
447 394 }
448 395
449 396 /**
450 397 * @since 2.3.0
@@ -452,14 +399,9 @@
452 399 */
453 400 protected function render() {
454 401 $settings = $this->get_settings_for_display();
455 402 $rating_data = $this->get_rating();
456 - $textual_rating = sprintf(
457 - /* translators: 1: Rating value. 2: Rating scale. */
458 - esc_html__( 'Rated %1$s out of %2$s', 'elementor' ),
459 - $rating_data[0],
460 - $rating_data[1]
461 - );
403 + $textual_rating = $rating_data[0] . '/' . $rating_data[1];
462 404 $icon = '&#xE934;';
463 405
464 406 if ( 'star_fontawesome' === $settings['star_style'] ) {
465 407 if ( 'outline' === $settings['unmarked_star_style'] ) {
@@ -474,48 +416,28 @@
474 416 }
475 417
476 418 $this->add_render_attribute( 'icon_wrapper', [
477 419 'class' => 'elementor-star-rating',
420 + 'title' => $textual_rating,
478 421 'itemtype' => 'http://schema.org/Rating',
479 422 'itemscope' => '',
480 423 'itemprop' => 'reviewRating',
481 424 ] );
425 +
426 + $schema_rating = '<span itemprop="ratingValue" class="elementor-screen-only">' . $textual_rating . '</span>';
427 + $stars_element = '<div ' . $this->get_render_attribute_string( 'icon_wrapper' ) . '>' . $this->render_stars( $icon ) . ' ' . $schema_rating . '</div>';
482 428 ?>
429 +
483 430 <div class="elementor-star-rating__wrapper">
484 431 <?php if ( ! Utils::is_empty( $settings['title'] ) ) : ?>
485 432 <div class="elementor-star-rating__title"><?php echo esc_html( $settings['title'] ); ?></div>
486 - <?php endif; ?>
487 - <div <?php $this->print_render_attribute_string( 'icon_wrapper' ); ?>>
488 - <?php $this->render_stars( $icon ); ?>
489 - <span itemprop="ratingValue" class="elementor-screen-only"><?php echo esc_html( $textual_rating ); ?></span>
490 - </div>
433 + <?php endif;
434 + // PHPCS - $stars_element contains an HTML string that cannot be escaped. ?>
435 + <?php echo $stars_element; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
491 436 </div>
492 437 <?php
493 438 }
494 439
495 - public function render_markdown(): string {
496 - $settings = $this->get_settings_for_display();
497 - $title = Utils::html_to_plain_text( $settings['title'] ?? '' );
498 - $rating = floatval( $settings['rating'] ?? 0 );
499 - $scale = intval( $settings['rating_scale'] ?? 5 );
500 -
501 - if ( empty( $rating ) ) {
502 - return '';
503 - }
504 -
505 - $full_stars = intval( floor( $rating ) );
506 - $empty_stars = $scale - $full_stars;
507 - $stars = str_repeat( '★', $full_stars ) . str_repeat( '☆', max( 0, $empty_stars ) );
508 -
509 - $md = $stars . ' ' . $rating . '/' . $scale;
510 -
511 - if ( ! empty( $title ) ) {
512 - $md .= "\n\n" . $title;
513 - }
514 -
515 - return $md;
516 - }
517 -
518 440 /**
519 441 * @since 2.9.0
520 442 * @access protected
521 443 */
@@ -529,9 +451,9 @@
529 451 return [ rating, ratingScale ];
530 452 },
531 453 ratingData = getRating(),
532 454 rating = ratingData[0],
533 - textualRating = 'Rated ' + ratingData[0] + ' out of ' + ratingData[1],
455 + textualRating = ratingData[0] + '/' + ratingData[1],
534 456 renderStars = function( icon ) {
535 457 var starsHtml = '',
536 458 flooredRating = Math.floor( rating );
537 459
@@ -536,13 +458,13 @@
536 458 flooredRating = Math.floor( rating );
537 459
538 460 for ( var stars = 1; stars <= ratingData[1]; stars++ ) {
539 461 if ( stars <= flooredRating ) {
540 - starsHtml += '<i class="elementor-star-full" aria-hidden="true">' + icon + '</i>';
462 + starsHtml += '<i class="elementor-star-full">' + icon + '</i>';
541 463 } else if ( flooredRating + 1 === stars && rating !== flooredRating ) {
542 - starsHtml += '<i class="elementor-star-' + ( rating - flooredRating ).toFixed( 1 ) * 10 + '" aria-hidden="true">' + icon + '</i>';
464 + starsHtml += '<i class="elementor-star-' + ( rating - flooredRating ).toFixed( 1 ) * 10 + '">' + icon + '</i>';
543 465 } else {
544 - starsHtml += '<i class="elementor-star-empty" aria-hidden="true">' + icon + '</i>';
466 + starsHtml += '<i class="elementor-star-empty">' + icon + '</i>';
545 467 }
546 468 }
547 469
548 470 return starsHtml;
@@ -562,13 +484,15 @@
562 484 }
563 485
564 486 view.addRenderAttribute( 'iconWrapper', 'class', 'elementor-star-rating' );
565 487 view.addRenderAttribute( 'iconWrapper', 'itemtype', 'http://schema.org/Rating' );
488 + view.addRenderAttribute( 'iconWrapper', 'title', textualRating );
566 489 view.addRenderAttribute( 'iconWrapper', 'itemscope', '' );
567 490 view.addRenderAttribute( 'iconWrapper', 'itemprop', 'reviewRating' );
568 491
569 492 var stars = renderStars( icon );
570 493 #>
494 +
571 495 <div class="elementor-star-rating__wrapper">
572 496 <# if ( ! _.isEmpty( settings.title ) ) { #>
573 497 <div class="elementor-star-rating__title">{{ settings.title }}</div>
574 498 <# } #>
@@ -576,7 +500,8 @@
576 500 {{{ stars }}}
577 501 <span itemprop="ratingValue" class="elementor-screen-only">{{ textualRating }}</span>
578 502 </div>
579 503 </div>
504 +
580 505 <?php
581 506 }
582 507 }