PluginProbe
Elementor Website Builder – more than just a page builder / 3.2.3
Elementor Website Builder – more than just a page builder v3.2.3
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 +51 -150 4.1.53.2.3 View file →
@@ -41,9 +41,9 @@
41 41 *
42 42 * @return string Widget title.
43 43 */
44 44 public function get_title() {
45 - return esc_html__( 'Star Rating', 'elementor' );
45 + return __( 'Star Rating', 'elementor' );
46 46 }
47 47
48 48 /**
49 49 * Get widget icon.
@@ -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,27 +84,16 @@
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' => __( '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 - 'label' => esc_html__( 'Rating Scale', 'elementor' ),
95 + 'label' => __( 'Rating Scale', 'elementor' ),
141 96 'type' => Controls_Manager::SELECT,
142 97 'options' => [
143 98 '5' => '0-5',
144 99 '10' => '0-10',
@@ -149,9 +104,9 @@
149 104
150 105 $this->add_control(
151 106 'rating',
152 107 [
153 - 'label' => esc_html__( 'Rating', 'elementor' ),
108 + 'label' => __( 'Rating', 'elementor' ),
154 109 'type' => Controls_Manager::NUMBER,
155 110 'min' => 0,
156 111 'max' => 10,
157 112 'step' => 0.1,
@@ -164,9 +119,9 @@
164 119
165 120 $this->add_control(
166 121 'star_style',
167 122 [
168 - 'label' => esc_html__( 'Icon', 'elementor' ),
123 + 'label' => __( 'Icon', 'elementor' ),
169 124 'type' => Controls_Manager::SELECT,
170 125 'options' => [
171 126 'star_fontawesome' => 'Font Awesome',
172 127 'star_unicode' => 'Unicode',
@@ -180,17 +135,17 @@
180 135
181 136 $this->add_control(
182 137 'unmarked_star_style',
183 138 [
184 - 'label' => esc_html__( 'Unmarked Style', 'elementor' ),
139 + 'label' => __( 'Unmarked Style', 'elementor' ),
185 140 'type' => Controls_Manager::CHOOSE,
186 141 'options' => [
187 142 'solid' => [
188 - 'title' => esc_html__( 'Solid', 'elementor' ),
143 + 'title' => __( 'Solid', 'elementor' ),
189 144 'icon' => 'eicon-star',
190 145 ],
191 146 'outline' => [
192 - 'title' => esc_html__( 'Outline', 'elementor' ),
147 + 'title' => __( 'Outline', 'elementor' ),
193 148 'icon' => 'eicon-star-o',
194 149 ],
195 150 ],
196 151 'default' => 'solid',
@@ -199,9 +154,9 @@
199 154
200 155 $this->add_control(
201 156 'title',
202 157 [
203 - 'label' => esc_html__( 'Title', 'elementor' ),
158 + 'label' => __( 'Title', 'elementor' ),
204 159 'type' => Controls_Manager::TEXT,
205 160 'separator' => 'before',
206 161 'dynamic' => [
207 162 'active' => true,
@@ -211,37 +166,28 @@
211 166
212 167 $this->add_responsive_control(
213 168 'align',
214 169 [
215 - 'label' => esc_html__( 'Alignment', 'elementor' ),
170 + 'label' => __( 'Alignment', 'elementor' ),
216 171 'type' => Controls_Manager::CHOOSE,
217 172 'options' => [
218 - 'start' => [
219 - 'title' => esc_html__( 'Start', 'elementor' ),
173 + 'left' => [
174 + 'title' => __( 'Left', 'elementor' ),
220 175 'icon' => 'eicon-text-align-left',
221 176 ],
222 177 'center' => [
223 - 'title' => esc_html__( 'Center', 'elementor' ),
178 + 'title' => __( 'Center', 'elementor' ),
224 179 'icon' => 'eicon-text-align-center',
225 180 ],
226 - 'end' => [
227 - 'title' => esc_html__( 'End', 'elementor' ),
181 + 'right' => [
182 + 'title' => __( 'Right', 'elementor' ),
228 183 'icon' => 'eicon-text-align-right',
229 184 ],
230 185 'justify' => [
231 - 'title' => esc_html__( 'Justified', 'elementor' ),
186 + 'title' => __( '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 ],
@@ -252,9 +198,9 @@
252 198
253 199 $this->start_controls_section(
254 200 'section_title_style',
255 201 [
256 - 'label' => esc_html__( 'Title', 'elementor' ),
202 + 'label' => __( 'Title', 'elementor' ),
257 203 'tab' => Controls_Manager::TAB_STYLE,
258 204 'condition' => [
259 205 'title!' => '',
260 206 ],
@@ -263,9 +209,9 @@
263 209
264 210 $this->add_control(
265 211 'title_color',
266 212 [
267 - 'label' => esc_html__( 'Text Color', 'elementor' ),
213 + 'label' => __( 'Text Color', 'elementor' ),
268 214 'type' => Controls_Manager::COLOR,
269 215 'global' => [
270 216 'default' => Global_Colors::COLOR_TEXT,
271 217 ],
@@ -296,26 +242,19 @@
296 242
297 243 $this->add_responsive_control(
298 244 'title_gap',
299 245 [
300 - 'label' => esc_html__( 'Gap', 'elementor' ),
246 + 'label' => __( '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
@@ -323,9 +262,9 @@
323 262
324 263 $this->start_controls_section(
325 264 'section_stars_style',
326 265 [
327 - 'label' => esc_html__( 'Stars', 'elementor' ),
266 + 'label' => __( 'Stars', 'elementor' ),
328 267 'tab' => Controls_Manager::TAB_STYLE,
329 268 ]
330 269 );
331 270
@@ -331,23 +270,15 @@
331 270
332 271 $this->add_responsive_control(
333 272 'icon_size',
334 273 [
335 - 'label' => esc_html__( 'Size', 'elementor' ),
274 + 'label' => __( '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 ],
@@ -356,26 +287,19 @@
356 287
357 288 $this->add_responsive_control(
358 289 'icon_space',
359 290 [
360 - 'label' => esc_html__( 'Spacing', 'elementor' ),
291 + 'label' => __( '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
@@ -381,9 +305,9 @@
381 305
382 306 $this->add_control(
383 307 'stars_color',
384 308 [
385 - 'label' => esc_html__( 'Color', 'elementor' ),
309 + 'label' => __( 'Color', 'elementor' ),
386 310 'type' => Controls_Manager::COLOR,
387 311 'selectors' => [
388 312 '{{WRAPPER}} .elementor-star-rating i:before' => 'color: {{VALUE}}',
389 313 ],
@@ -393,9 +317,9 @@
393 317
394 318 $this->add_control(
395 319 'stars_unmarked_color',
396 320 [
397 - 'label' => esc_html__( 'Unmarked Color', 'elementor' ),
321 + 'label' => __( 'Unmarked Color', 'elementor' ),
398 322 'type' => Controls_Manager::COLOR,
399 323 'selectors' => [
400 324 '{{WRAPPER}} .elementor-star-rating i' => 'color: {{VALUE}}',
401 325 ],
@@ -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,27 @@
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 - <div class="elementor-star-rating__title"><?php echo esc_html( $settings['title'] ); ?></div>
409 + <div class="elementor-star-rating__title"><?php echo $settings['title']; ?></div>
486 410 <?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>
411 + <?php echo $stars_element; ?>
491 412 </div>
492 413 <?php
493 414 }
494 415
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 416 /**
519 417 * @since 2.9.0
520 418 * @access protected
521 419 */
@@ -529,9 +427,9 @@
529 427 return [ rating, ratingScale ];
530 428 },
531 429 ratingData = getRating(),
532 430 rating = ratingData[0],
533 - textualRating = 'Rated ' + ratingData[0] + ' out of ' + ratingData[1],
431 + textualRating = ratingData[0] + '/' + ratingData[1],
534 432 renderStars = function( icon ) {
535 433 var starsHtml = '',
536 434 flooredRating = Math.floor( rating );
537 435
@@ -536,13 +434,13 @@
536 434 flooredRating = Math.floor( rating );
537 435
538 436 for ( var stars = 1; stars <= ratingData[1]; stars++ ) {
539 437 if ( stars <= flooredRating ) {
540 - starsHtml += '<i class="elementor-star-full" aria-hidden="true">' + icon + '</i>';
438 + starsHtml += '<i class="elementor-star-full">' + icon + '</i>';
541 439 } else if ( flooredRating + 1 === stars && rating !== flooredRating ) {
542 - starsHtml += '<i class="elementor-star-' + ( rating - flooredRating ).toFixed( 1 ) * 10 + '" aria-hidden="true">' + icon + '</i>';
440 + starsHtml += '<i class="elementor-star-' + ( rating - flooredRating ).toFixed( 1 ) * 10 + '">' + icon + '</i>';
543 441 } else {
544 - starsHtml += '<i class="elementor-star-empty" aria-hidden="true">' + icon + '</i>';
442 + starsHtml += '<i class="elementor-star-empty">' + icon + '</i>';
545 443 }
546 444 }
547 445
548 446 return starsHtml;
@@ -562,13 +460,15 @@
562 460 }
563 461
564 462 view.addRenderAttribute( 'iconWrapper', 'class', 'elementor-star-rating' );
565 463 view.addRenderAttribute( 'iconWrapper', 'itemtype', 'http://schema.org/Rating' );
464 + view.addRenderAttribute( 'iconWrapper', 'title', textualRating );
566 465 view.addRenderAttribute( 'iconWrapper', 'itemscope', '' );
567 466 view.addRenderAttribute( 'iconWrapper', 'itemprop', 'reviewRating' );
568 467
569 468 var stars = renderStars( icon );
570 469 #>
470 +
571 471 <div class="elementor-star-rating__wrapper">
572 472 <# if ( ! _.isEmpty( settings.title ) ) { #>
573 473 <div class="elementor-star-rating__title">{{ settings.title }}</div>
574 474 <# } #>
@@ -576,7 +476,8 @@
576 476 {{{ stars }}}
577 477 <span itemprop="ratingValue" class="elementor-screen-only">{{ textualRating }}</span>
578 478 </div>
579 479 </div>
480 +
580 481 <?php
581 482 }
582 483 }