PluginProbe
Elementor Website Builder – more than just a page builder / 3.9.2
Elementor Website Builder – more than just a page builder v3.9.2
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 +33 -131 4.2.43.9.2 View file →
@@ -72,43 +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 - * Hide widget from panel.
96 - *
97 - * Hide the star rating widget from the panel.
98 - *
99 - * @since 3.17.0
100 - * @return bool
101 - */
102 - public function show_in_panel(): bool {
103 - return false;
104 - }
105 -
106 - public function has_widget_inner_wrapper(): bool {
107 - return ! Plugin::$instance->experiments->is_feature_active( 'e_optimized_markup' );
108 - }
109 -
110 - /**
111 77 * Register star rating widget controls.
112 78 *
113 79 * Adds different input fields to allow the user to change and customize the widget settings.
114 80 *
@@ -118,23 +84,12 @@
118 84 protected function register_controls() {
119 85 $this->start_controls_section(
120 86 'section_rating',
121 87 [
122 - 'label' => esc_html__( 'Star Rating', 'elementor' ),
88 + 'label' => esc_html__( 'Rating', 'elementor' ),
123 89 ]
124 90 );
125 91
126 - if ( Plugin::$instance->widgets_manager->get_widget_types( 'rating' ) ) {
127 - $this->add_deprecation_message(
128 - '3.17.0',
129 - esc_html__(
130 - 'You are currently editing a Star Rating widget in its old version. Drag a new Rating widget onto your page to use a newer version, providing better capabilities.',
131 - 'elementor'
132 - ),
133 - 'rating'
134 - );
135 - }
136 -
137 92 $this->add_control(
138 93 'rating_scale',
139 94 [
140 95 'label' => esc_html__( 'Rating Scale', 'elementor' ),
@@ -214,10 +169,10 @@
214 169 [
215 170 'label' => esc_html__( 'Alignment', 'elementor' ),
216 171 'type' => Controls_Manager::CHOOSE,
217 172 'options' => [
218 - 'start' => [
219 - 'title' => esc_html__( 'Start', 'elementor' ),
173 + 'left' => [
174 + 'title' => esc_html__( 'Left', 'elementor' ),
220 175 'icon' => 'eicon-text-align-left',
221 176 ],
222 177 'center' => [
223 178 'title' => esc_html__( 'Center', 'elementor' ),
@@ -222,10 +177,10 @@
222 177 'center' => [
223 178 'title' => esc_html__( 'Center', 'elementor' ),
224 179 'icon' => 'eicon-text-align-center',
225 180 ],
226 - 'end' => [
227 - 'title' => esc_html__( 'End', 'elementor' ),
181 + 'right' => [
182 + 'title' => esc_html__( 'Right', 'elementor' ),
228 183 'icon' => 'eicon-text-align-right',
229 184 ],
230 185 'justify' => [
231 186 'title' => esc_html__( 'Justified', 'elementor' ),
@@ -231,17 +186,8 @@
231 186 'title' => esc_html__( 'Justified', 'elementor' ),
232 187 'icon' => 'eicon-text-align-justify',
233 188 ],
234 189 ],
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 190 'prefix_class' => 'elementor-star-rating%s--align-',
245 191 'selectors' => [
246 192 '{{WRAPPER}}' => 'text-align: {{VALUE}}',
247 193 ],
@@ -298,24 +244,17 @@
298 244 'title_gap',
299 245 [
300 246 'label' => esc_html__( 'Gap', 'elementor' ),
301 247 'type' => Controls_Manager::SLIDER,
302 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
303 248 'range' => [
304 249 'px' => [
250 + 'min' => 0,
305 251 'max' => 50,
306 252 ],
307 - 'em' => [
308 - 'min' => 0,
309 - 'max' => 5,
310 - ],
311 - 'rem' => [
312 - 'min' => 0,
313 - 'max' => 5,
314 - ],
315 253 ],
316 254 'selectors' => [
317 - '{{WRAPPER}}:not(.elementor-star-rating--align-justify) .elementor-star-rating__title' => 'margin-inline-end: {{SIZE}}{{UNIT}}',
255 + 'body:not(.rtl) {{WRAPPER}}:not(.elementor-star-rating--align-justify) .elementor-star-rating__title' => 'margin-right: {{SIZE}}{{UNIT}}',
256 + 'body.rtl {{WRAPPER}}:not(.elementor-star-rating--align-justify) .elementor-star-rating__title' => 'margin-left: {{SIZE}}{{UNIT}}',
318 257 ],
319 258 ]
320 259 );
321 260
@@ -333,21 +272,13 @@
333 272 'icon_size',
334 273 [
335 274 'label' => esc_html__( 'Size', 'elementor' ),
336 275 'type' => Controls_Manager::SLIDER,
337 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
338 276 'range' => [
339 277 'px' => [
278 + 'min' => 0,
340 279 'max' => 100,
341 280 ],
342 - 'em' => [
343 - 'min' => 0,
344 - 'max' => 10,
345 - ],
346 - 'rem' => [
347 - 'min' => 0,
348 - 'max' => 10,
349 - ],
350 281 ],
351 282 'selectors' => [
352 283 '{{WRAPPER}} .elementor-star-rating' => 'font-size: {{SIZE}}{{UNIT}}',
353 284 ],
@@ -358,24 +289,17 @@
358 289 'icon_space',
359 290 [
360 291 'label' => esc_html__( 'Spacing', 'elementor' ),
361 292 'type' => Controls_Manager::SLIDER,
362 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
363 293 'range' => [
364 294 'px' => [
295 + 'min' => 0,
365 296 'max' => 50,
366 297 ],
367 - 'em' => [
368 - 'min' => 0,
369 - 'max' => 5,
370 - ],
371 - 'rem' => [
372 - 'min' => 0,
373 - 'max' => 5,
374 - ],
375 298 ],
376 299 'selectors' => [
377 - '{{WRAPPER}} .elementor-star-rating i:not(:last-of-type)' => 'margin-inline-end: {{SIZE}}{{UNIT}}',
300 + 'body:not(.rtl) {{WRAPPER}} .elementor-star-rating i:not(:last-of-type)' => 'margin-right: {{SIZE}}{{UNIT}}',
301 + 'body.rtl {{WRAPPER}} .elementor-star-rating i:not(:last-of-type)' => 'margin-left: {{SIZE}}{{UNIT}}',
378 302 ],
379 303 ]
380 304 );
381 305
@@ -411,9 +335,9 @@
411 335 */
412 336 protected function get_rating() {
413 337 $settings = $this->get_settings_for_display();
414 338 $rating_scale = (int) $settings['rating_scale'];
415 - $rating = min( (float) $settings['rating'], $rating_scale );
339 + $rating = (float) $settings['rating'] > $rating_scale ? $rating_scale : $settings['rating'];
416 340
417 341 return [ $rating, $rating_scale ];
418 342 }
419 343
@@ -434,17 +358,17 @@
434 358 $stars_html = '';
435 359
436 360 for ( $stars = 1.0; $stars <= $rating_data[1]; $stars++ ) {
437 361 if ( $stars <= $floored_rating ) {
438 - $stars_html .= '<i class="elementor-star-full" aria-hidden="true">' . $icon . '</i>';
362 + $stars_html .= '<i class="elementor-star-full">' . $icon . '</i>';
439 363 } elseif ( $floored_rating + 1 === $stars && $rating !== $floored_rating ) {
440 - $stars_html .= '<i class="elementor-star-' . ( $rating - $floored_rating ) * 10 . '" aria-hidden="true">' . $icon . '</i>';
364 + $stars_html .= '<i class="elementor-star-' . ( $rating - $floored_rating ) * 10 . '">' . $icon . '</i>';
441 365 } else {
442 - $stars_html .= '<i class="elementor-star-empty" aria-hidden="true">' . $icon . '</i>';
366 + $stars_html .= '<i class="elementor-star-empty">' . $icon . '</i>';
443 367 }
444 368 }
445 369
446 - Utils::print_unescaped_internal_string( $stars_html );
370 + return $stars_html;
447 371 }
448 372
449 373 /**
450 374 * @since 2.3.0
@@ -452,14 +376,9 @@
452 376 */
453 377 protected function render() {
454 378 $settings = $this->get_settings_for_display();
455 379 $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 - );
380 + $textual_rating = $rating_data[0] . '/' . $rating_data[1];
462 381 $icon = '&#xE934;';
463 382
464 383 if ( 'star_fontawesome' === $settings['star_style'] ) {
465 384 if ( 'outline' === $settings['unmarked_star_style'] ) {
@@ -474,48 +393,28 @@
474 393 }
475 394
476 395 $this->add_render_attribute( 'icon_wrapper', [
477 396 'class' => 'elementor-star-rating',
397 + 'title' => $textual_rating,
478 398 'itemtype' => 'http://schema.org/Rating',
479 399 'itemscope' => '',
480 400 'itemprop' => 'reviewRating',
481 401 ] );
402 +
403 + $schema_rating = '<span itemprop="ratingValue" class="elementor-screen-only">' . $textual_rating . '</span>';
404 + $stars_element = '<div ' . $this->get_render_attribute_string( 'icon_wrapper' ) . '>' . $this->render_stars( $icon ) . ' ' . $schema_rating . '</div>';
482 405 ?>
406 +
483 407 <div class="elementor-star-rating__wrapper">
484 408 <?php if ( ! Utils::is_empty( $settings['title'] ) ) : ?>
485 409 <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>
410 + <?php endif;
411 + // PHPCS - $stars_element contains an HTML string that cannot be escaped. ?>
412 + <?php echo $stars_element; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
491 413 </div>
492 414 <?php
493 415 }
494 416
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 417 /**
519 418 * @since 2.9.0
520 419 * @access protected
521 420 */
@@ -529,9 +428,9 @@
529 428 return [ rating, ratingScale ];
530 429 },
531 430 ratingData = getRating(),
532 431 rating = ratingData[0],
533 - textualRating = 'Rated ' + ratingData[0] + ' out of ' + ratingData[1],
432 + textualRating = ratingData[0] + '/' + ratingData[1],
534 433 renderStars = function( icon ) {
535 434 var starsHtml = '',
536 435 flooredRating = Math.floor( rating );
537 436
@@ -536,13 +435,13 @@
536 435 flooredRating = Math.floor( rating );
537 436
538 437 for ( var stars = 1; stars <= ratingData[1]; stars++ ) {
539 438 if ( stars <= flooredRating ) {
540 - starsHtml += '<i class="elementor-star-full" aria-hidden="true">' + icon + '</i>';
439 + starsHtml += '<i class="elementor-star-full">' + icon + '</i>';
541 440 } else if ( flooredRating + 1 === stars && rating !== flooredRating ) {
542 - starsHtml += '<i class="elementor-star-' + ( rating - flooredRating ).toFixed( 1 ) * 10 + '" aria-hidden="true">' + icon + '</i>';
441 + starsHtml += '<i class="elementor-star-' + ( rating - flooredRating ).toFixed( 1 ) * 10 + '">' + icon + '</i>';
543 442 } else {
544 - starsHtml += '<i class="elementor-star-empty" aria-hidden="true">' + icon + '</i>';
443 + starsHtml += '<i class="elementor-star-empty">' + icon + '</i>';
545 444 }
546 445 }
547 446
548 447 return starsHtml;
@@ -562,13 +461,15 @@
562 461 }
563 462
564 463 view.addRenderAttribute( 'iconWrapper', 'class', 'elementor-star-rating' );
565 464 view.addRenderAttribute( 'iconWrapper', 'itemtype', 'http://schema.org/Rating' );
465 + view.addRenderAttribute( 'iconWrapper', 'title', textualRating );
566 466 view.addRenderAttribute( 'iconWrapper', 'itemscope', '' );
567 467 view.addRenderAttribute( 'iconWrapper', 'itemprop', 'reviewRating' );
568 468
569 469 var stars = renderStars( icon );
570 470 #>
471 +
571 472 <div class="elementor-star-rating__wrapper">
572 473 <# if ( ! _.isEmpty( settings.title ) ) { #>
573 474 <div class="elementor-star-rating__title">{{ settings.title }}</div>
574 475 <# } #>
@@ -576,7 +477,8 @@
576 477 {{{ stars }}}
577 478 <span itemprop="ratingValue" class="elementor-screen-only">{{ textualRating }}</span>
578 479 </div>
579 480 </div>
481 +
580 482 <?php
581 483 }
582 484 }