PluginProbe
Elementor Website Builder – more than just a page builder / 3.23.0-dev3
Elementor Website Builder – more than just a page builder v3.23.0-dev3
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 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | includes/widgets/star-rating.php +29 -76 4.1.0-dev23.23.0-dev3 View file →
@@ -77,22 +77,8 @@
77 77 return false;
78 78 }
79 79
80 80 /**
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 81 * Hide widget from panel.
96 82 *
97 83 * Hide the star rating widget from the panel.
98 84 *
@@ -102,12 +88,8 @@
102 88 public function show_in_panel(): bool {
103 89 return false;
104 90 }
105 91
106 - public function has_widget_inner_wrapper(): bool {
107 - return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
108 - }
109 -
110 92 /**
111 93 * Register star rating widget controls.
112 94 *
113 95 * Adds different input fields to allow the user to change and customize the widget settings.
@@ -214,10 +196,10 @@
214 196 [
215 197 'label' => esc_html__( 'Alignment', 'elementor' ),
216 198 'type' => Controls_Manager::CHOOSE,
217 199 'options' => [
218 - 'start' => [
219 - 'title' => esc_html__( 'Start', 'elementor' ),
200 + 'left' => [
201 + 'title' => esc_html__( 'Left', 'elementor' ),
220 202 'icon' => 'eicon-text-align-left',
221 203 ],
222 204 'center' => [
223 205 'title' => esc_html__( 'Center', 'elementor' ),
@@ -222,10 +204,10 @@
222 204 'center' => [
223 205 'title' => esc_html__( 'Center', 'elementor' ),
224 206 'icon' => 'eicon-text-align-center',
225 207 ],
226 - 'end' => [
227 - 'title' => esc_html__( 'End', 'elementor' ),
208 + 'right' => [
209 + 'title' => esc_html__( 'Right', 'elementor' ),
228 210 'icon' => 'eicon-text-align-right',
229 211 ],
230 212 'justify' => [
231 213 'title' => esc_html__( 'Justified', 'elementor' ),
@@ -231,17 +213,8 @@
231 213 'title' => esc_html__( 'Justified', 'elementor' ),
232 214 'icon' => 'eicon-text-align-justify',
233 215 ],
234 216 ],
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 217 'prefix_class' => 'elementor-star-rating%s--align-',
245 218 'selectors' => [
246 219 '{{WRAPPER}}' => 'text-align: {{VALUE}}',
247 220 ],
@@ -313,9 +286,10 @@
313 286 'max' => 5,
314 287 ],
315 288 ],
316 289 'selectors' => [
317 - '{{WRAPPER}}:not(.elementor-star-rating--align-justify) .elementor-star-rating__title' => 'margin-inline-end: {{SIZE}}{{UNIT}}',
290 + 'body:not(.rtl) {{WRAPPER}}:not(.elementor-star-rating--align-justify) .elementor-star-rating__title' => 'margin-right: {{SIZE}}{{UNIT}}',
291 + 'body.rtl {{WRAPPER}}:not(.elementor-star-rating--align-justify) .elementor-star-rating__title' => 'margin-left: {{SIZE}}{{UNIT}}',
318 292 ],
319 293 ]
320 294 );
321 295
@@ -373,9 +347,10 @@
373 347 'max' => 5,
374 348 ],
375 349 ],
376 350 'selectors' => [
377 - '{{WRAPPER}} .elementor-star-rating i:not(:last-of-type)' => 'margin-inline-end: {{SIZE}}{{UNIT}}',
351 + 'body:not(.rtl) {{WRAPPER}} .elementor-star-rating i:not(:last-of-type)' => 'margin-right: {{SIZE}}{{UNIT}}',
352 + 'body.rtl {{WRAPPER}} .elementor-star-rating i:not(:last-of-type)' => 'margin-left: {{SIZE}}{{UNIT}}',
378 353 ],
379 354 ]
380 355 );
381 356
@@ -411,9 +386,9 @@
411 386 */
412 387 protected function get_rating() {
413 388 $settings = $this->get_settings_for_display();
414 389 $rating_scale = (int) $settings['rating_scale'];
415 - $rating = min( (float) $settings['rating'], $rating_scale );
390 + $rating = (float) $settings['rating'] > $rating_scale ? $rating_scale : $settings['rating'];
416 391
417 392 return [ $rating, $rating_scale ];
418 393 }
419 394
@@ -434,17 +409,17 @@
434 409 $stars_html = '';
435 410
436 411 for ( $stars = 1.0; $stars <= $rating_data[1]; $stars++ ) {
437 412 if ( $stars <= $floored_rating ) {
438 - $stars_html .= '<i class="elementor-star-full" aria-hidden="true">' . $icon . '</i>';
413 + $stars_html .= '<i class="elementor-star-full">' . $icon . '</i>';
439 414 } elseif ( $floored_rating + 1 === $stars && $rating !== $floored_rating ) {
440 - $stars_html .= '<i class="elementor-star-' . ( $rating - $floored_rating ) * 10 . '" aria-hidden="true">' . $icon . '</i>';
415 + $stars_html .= '<i class="elementor-star-' . ( $rating - $floored_rating ) * 10 . '">' . $icon . '</i>';
441 416 } else {
442 - $stars_html .= '<i class="elementor-star-empty" aria-hidden="true">' . $icon . '</i>';
417 + $stars_html .= '<i class="elementor-star-empty">' . $icon . '</i>';
443 418 }
444 419 }
445 420
446 - Utils::print_unescaped_internal_string( $stars_html );
421 + return $stars_html;
447 422 }
448 423
449 424 /**
450 425 * @since 2.3.0
@@ -452,14 +427,9 @@
452 427 */
453 428 protected function render() {
454 429 $settings = $this->get_settings_for_display();
455 430 $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 - );
431 + $textual_rating = $rating_data[0] . '/' . $rating_data[1];
462 432 $icon = '&#xE934;';
463 433
464 434 if ( 'star_fontawesome' === $settings['star_style'] ) {
465 435 if ( 'outline' === $settings['unmarked_star_style'] ) {
@@ -474,48 +444,28 @@
474 444 }
475 445
476 446 $this->add_render_attribute( 'icon_wrapper', [
477 447 'class' => 'elementor-star-rating',
448 + 'title' => $textual_rating,
478 449 'itemtype' => 'http://schema.org/Rating',
479 450 'itemscope' => '',
480 451 'itemprop' => 'reviewRating',
481 452 ] );
453 +
454 + $schema_rating = '<span itemprop="ratingValue" class="elementor-screen-only">' . $textual_rating . '</span>';
455 + $stars_element = '<div ' . $this->get_render_attribute_string( 'icon_wrapper' ) . '>' . $this->render_stars( $icon ) . ' ' . $schema_rating . '</div>';
482 456 ?>
457 +
483 458 <div class="elementor-star-rating__wrapper">
484 459 <?php if ( ! Utils::is_empty( $settings['title'] ) ) : ?>
485 460 <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>
461 + <?php endif;
462 + // PHPCS - $stars_element contains an HTML string that cannot be escaped. ?>
463 + <?php echo $stars_element; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
491 464 </div>
492 465 <?php
493 466 }
494 467
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 468 /**
519 469 * @since 2.9.0
520 470 * @access protected
521 471 */
@@ -529,9 +479,9 @@
529 479 return [ rating, ratingScale ];
530 480 },
531 481 ratingData = getRating(),
532 482 rating = ratingData[0],
533 - textualRating = 'Rated ' + ratingData[0] + ' out of ' + ratingData[1],
483 + textualRating = ratingData[0] + '/' + ratingData[1],
534 484 renderStars = function( icon ) {
535 485 var starsHtml = '',
536 486 flooredRating = Math.floor( rating );
537 487
@@ -536,13 +486,13 @@
536 486 flooredRating = Math.floor( rating );
537 487
538 488 for ( var stars = 1; stars <= ratingData[1]; stars++ ) {
539 489 if ( stars <= flooredRating ) {
540 - starsHtml += '<i class="elementor-star-full" aria-hidden="true">' + icon + '</i>';
490 + starsHtml += '<i class="elementor-star-full">' + icon + '</i>';
541 491 } else if ( flooredRating + 1 === stars && rating !== flooredRating ) {
542 - starsHtml += '<i class="elementor-star-' + ( rating - flooredRating ).toFixed( 1 ) * 10 + '" aria-hidden="true">' + icon + '</i>';
492 + starsHtml += '<i class="elementor-star-' + ( rating - flooredRating ).toFixed( 1 ) * 10 + '">' + icon + '</i>';
543 493 } else {
544 - starsHtml += '<i class="elementor-star-empty" aria-hidden="true">' + icon + '</i>';
494 + starsHtml += '<i class="elementor-star-empty">' + icon + '</i>';
545 495 }
546 496 }
547 497
548 498 return starsHtml;
@@ -562,13 +512,15 @@
562 512 }
563 513
564 514 view.addRenderAttribute( 'iconWrapper', 'class', 'elementor-star-rating' );
565 515 view.addRenderAttribute( 'iconWrapper', 'itemtype', 'http://schema.org/Rating' );
516 + view.addRenderAttribute( 'iconWrapper', 'title', textualRating );
566 517 view.addRenderAttribute( 'iconWrapper', 'itemscope', '' );
567 518 view.addRenderAttribute( 'iconWrapper', 'itemprop', 'reviewRating' );
568 519
569 520 var stars = renderStars( icon );
570 521 #>
522 +
571 523 <div class="elementor-star-rating__wrapper">
572 524 <# if ( ! _.isEmpty( settings.title ) ) { #>
573 525 <div class="elementor-star-rating__title">{{ settings.title }}</div>
574 526 <# } #>
@@ -576,7 +528,8 @@
576 528 {{{ stars }}}
577 529 <span itemprop="ratingValue" class="elementor-screen-only">{{ textualRating }}</span>
578 530 </div>
579 531 </div>
532 +
580 533 <?php
581 534 }
582 535 }