PluginProbe
Elementor Website Builder – more than just a page builder / 3.0.6
Elementor Website Builder – more than just a page builder v3.0.6
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 +53 -160 4.2.23.0.6 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,73 +72,28 @@
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 *
115 - * @since 3.1.0
81 + * @since 2.3.0
116 82 * @access protected
117 83 */
118 - protected function register_controls() {
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 ],
@@ -285,37 +231,22 @@
285 231 ],
286 232 ]
287 233 );
288 234
289 - $this->add_group_control(
290 - Group_Control_Text_Shadow::get_type(),
291 - [
292 - 'name' => 'title_shadow',
293 - 'selector' => '{{WRAPPER}} .elementor-star-rating__title',
294 - ]
295 - );
296 -
297 235 $this->add_responsive_control(
298 236 'title_gap',
299 237 [
300 - 'label' => esc_html__( 'Gap', 'elementor' ),
238 + 'label' => __( 'Gap', 'elementor' ),
301 239 'type' => Controls_Manager::SLIDER,
302 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
303 240 'range' => [
304 241 'px' => [
242 + 'min' => 0,
305 243 'max' => 50,
306 244 ],
307 - 'em' => [
308 - 'min' => 0,
309 - 'max' => 5,
310 - ],
311 - 'rem' => [
312 - 'min' => 0,
313 - 'max' => 5,
314 - ],
315 245 ],
316 246 'selectors' => [
317 - '{{WRAPPER}}:not(.elementor-star-rating--align-justify) .elementor-star-rating__title' => 'margin-inline-end: {{SIZE}}{{UNIT}}',
247 + 'body:not(.rtl) {{WRAPPER}}:not(.elementor-star-rating--align-justify) .elementor-star-rating__title' => 'margin-right: {{SIZE}}{{UNIT}}',
248 + 'body.rtl {{WRAPPER}}:not(.elementor-star-rating--align-justify) .elementor-star-rating__title' => 'margin-left: {{SIZE}}{{UNIT}}',
318 249 ],
319 250 ]
320 251 );
321 252
@@ -323,9 +254,9 @@
323 254
324 255 $this->start_controls_section(
325 256 'section_stars_style',
326 257 [
327 - 'label' => esc_html__( 'Stars', 'elementor' ),
258 + 'label' => __( 'Stars', 'elementor' ),
328 259 'tab' => Controls_Manager::TAB_STYLE,
329 260 ]
330 261 );
331 262
@@ -331,23 +262,15 @@
331 262
332 263 $this->add_responsive_control(
333 264 'icon_size',
334 265 [
335 - 'label' => esc_html__( 'Size', 'elementor' ),
266 + 'label' => __( 'Size', 'elementor' ),
336 267 'type' => Controls_Manager::SLIDER,
337 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
338 268 'range' => [
339 269 'px' => [
270 + 'min' => 0,
340 271 'max' => 100,
341 272 ],
342 - 'em' => [
343 - 'min' => 0,
344 - 'max' => 10,
345 - ],
346 - 'rem' => [
347 - 'min' => 0,
348 - 'max' => 10,
349 - ],
350 273 ],
351 274 'selectors' => [
352 275 '{{WRAPPER}} .elementor-star-rating' => 'font-size: {{SIZE}}{{UNIT}}',
353 276 ],
@@ -356,26 +279,19 @@
356 279
357 280 $this->add_responsive_control(
358 281 'icon_space',
359 282 [
360 - 'label' => esc_html__( 'Spacing', 'elementor' ),
283 + 'label' => __( 'Spacing', 'elementor' ),
361 284 'type' => Controls_Manager::SLIDER,
362 - 'size_units' => [ 'px', 'em', 'rem', 'custom' ],
363 285 'range' => [
364 286 'px' => [
287 + 'min' => 0,
365 288 'max' => 50,
366 289 ],
367 - 'em' => [
368 - 'min' => 0,
369 - 'max' => 5,
370 - ],
371 - 'rem' => [
372 - 'min' => 0,
373 - 'max' => 5,
374 - ],
375 290 ],
376 291 'selectors' => [
377 - '{{WRAPPER}} .elementor-star-rating i:not(:last-of-type)' => 'margin-inline-end: {{SIZE}}{{UNIT}}',
292 + 'body:not(.rtl) {{WRAPPER}} .elementor-star-rating i:not(:last-of-type)' => 'margin-right: {{SIZE}}{{UNIT}}',
293 + 'body.rtl {{WRAPPER}} .elementor-star-rating i:not(:last-of-type)' => 'margin-left: {{SIZE}}{{UNIT}}',
378 294 ],
379 295 ]
380 296 );
381 297
@@ -381,9 +297,9 @@
381 297
382 298 $this->add_control(
383 299 'stars_color',
384 300 [
385 - 'label' => esc_html__( 'Color', 'elementor' ),
301 + 'label' => __( 'Color', 'elementor' ),
386 302 'type' => Controls_Manager::COLOR,
387 303 'selectors' => [
388 304 '{{WRAPPER}} .elementor-star-rating i:before' => 'color: {{VALUE}}',
389 305 ],
@@ -393,9 +309,9 @@
393 309
394 310 $this->add_control(
395 311 'stars_unmarked_color',
396 312 [
397 - 'label' => esc_html__( 'Unmarked Color', 'elementor' ),
313 + 'label' => __( 'Unmarked Color', 'elementor' ),
398 314 'type' => Controls_Manager::COLOR,
399 315 'selectors' => [
400 316 '{{WRAPPER}} .elementor-star-rating i' => 'color: {{VALUE}}',
401 317 ],
@@ -411,9 +327,9 @@
411 327 */
412 328 protected function get_rating() {
413 329 $settings = $this->get_settings_for_display();
414 330 $rating_scale = (int) $settings['rating_scale'];
415 - $rating = min( (float) $settings['rating'], $rating_scale );
331 + $rating = (float) $settings['rating'] > $rating_scale ? $rating_scale : $settings['rating'];
416 332
417 333 return [ $rating, $rating_scale ];
418 334 }
419 335
@@ -434,17 +350,17 @@
434 350 $stars_html = '';
435 351
436 352 for ( $stars = 1.0; $stars <= $rating_data[1]; $stars++ ) {
437 353 if ( $stars <= $floored_rating ) {
438 - $stars_html .= '<i class="elementor-star-full" aria-hidden="true">' . $icon . '</i>';
354 + $stars_html .= '<i class="elementor-star-full">' . $icon . '</i>';
439 355 } elseif ( $floored_rating + 1 === $stars && $rating !== $floored_rating ) {
440 - $stars_html .= '<i class="elementor-star-' . ( $rating - $floored_rating ) * 10 . '" aria-hidden="true">' . $icon . '</i>';
356 + $stars_html .= '<i class="elementor-star-' . ( $rating - $floored_rating ) * 10 . '">' . $icon . '</i>';
441 357 } else {
442 - $stars_html .= '<i class="elementor-star-empty" aria-hidden="true">' . $icon . '</i>';
358 + $stars_html .= '<i class="elementor-star-empty">' . $icon . '</i>';
443 359 }
444 360 }
445 361
446 - Utils::print_unescaped_internal_string( $stars_html );
362 + return $stars_html;
447 363 }
448 364
449 365 /**
450 366 * @since 2.3.0
@@ -452,14 +368,9 @@
452 368 */
453 369 protected function render() {
454 370 $settings = $this->get_settings_for_display();
455 371 $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 - );
372 + $textual_rating = $rating_data[0] . '/' . $rating_data[1];
462 373 $icon = '&#xE934;';
463 374
464 375 if ( 'star_fontawesome' === $settings['star_style'] ) {
465 376 if ( 'outline' === $settings['unmarked_star_style'] ) {
@@ -474,48 +385,27 @@
474 385 }
475 386
476 387 $this->add_render_attribute( 'icon_wrapper', [
477 388 'class' => 'elementor-star-rating',
389 + 'title' => $textual_rating,
478 390 'itemtype' => 'http://schema.org/Rating',
479 391 'itemscope' => '',
480 392 'itemprop' => 'reviewRating',
481 393 ] );
394 +
395 + $schema_rating = '<span itemprop="ratingValue" class="elementor-screen-only">' . $textual_rating . '</span>';
396 + $stars_element = '<div ' . $this->get_render_attribute_string( 'icon_wrapper' ) . '>' . $this->render_stars( $icon ) . ' ' . $schema_rating . '</div>';
482 397 ?>
398 +
483 399 <div class="elementor-star-rating__wrapper">
484 400 <?php if ( ! Utils::is_empty( $settings['title'] ) ) : ?>
485 - <div class="elementor-star-rating__title"><?php echo esc_html( $settings['title'] ); ?></div>
401 + <div class="elementor-star-rating__title"><?php echo $settings['title']; ?></div>
486 402 <?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>
403 + <?php echo $stars_element; ?>
491 404 </div>
492 405 <?php
493 406 }
494 407
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 408 /**
519 409 * @since 2.9.0
520 410 * @access protected
521 411 */
@@ -529,9 +419,9 @@
529 419 return [ rating, ratingScale ];
530 420 },
531 421 ratingData = getRating(),
532 422 rating = ratingData[0],
533 - textualRating = 'Rated ' + ratingData[0] + ' out of ' + ratingData[1],
423 + textualRating = ratingData[0] + '/' + ratingData[1],
534 424 renderStars = function( icon ) {
535 425 var starsHtml = '',
536 426 flooredRating = Math.floor( rating );
537 427
@@ -536,13 +426,13 @@
536 426 flooredRating = Math.floor( rating );
537 427
538 428 for ( var stars = 1; stars <= ratingData[1]; stars++ ) {
539 429 if ( stars <= flooredRating ) {
540 - starsHtml += '<i class="elementor-star-full" aria-hidden="true">' + icon + '</i>';
430 + starsHtml += '<i class="elementor-star-full">' + icon + '</i>';
541 431 } else if ( flooredRating + 1 === stars && rating !== flooredRating ) {
542 - starsHtml += '<i class="elementor-star-' + ( rating - flooredRating ).toFixed( 1 ) * 10 + '" aria-hidden="true">' + icon + '</i>';
432 + starsHtml += '<i class="elementor-star-' + ( rating - flooredRating ).toFixed( 1 ) * 10 + '">' + icon + '</i>';
543 433 } else {
544 - starsHtml += '<i class="elementor-star-empty" aria-hidden="true">' + icon + '</i>';
434 + starsHtml += '<i class="elementor-star-empty">' + icon + '</i>';
545 435 }
546 436 }
547 437
548 438 return starsHtml;
@@ -562,13 +452,15 @@
562 452 }
563 453
564 454 view.addRenderAttribute( 'iconWrapper', 'class', 'elementor-star-rating' );
565 455 view.addRenderAttribute( 'iconWrapper', 'itemtype', 'http://schema.org/Rating' );
456 + view.addRenderAttribute( 'iconWrapper', 'title', textualRating );
566 457 view.addRenderAttribute( 'iconWrapper', 'itemscope', '' );
567 458 view.addRenderAttribute( 'iconWrapper', 'itemprop', 'reviewRating' );
568 459
569 460 var stars = renderStars( icon );
570 461 #>
462 +
571 463 <div class="elementor-star-rating__wrapper">
572 464 <# if ( ! _.isEmpty( settings.title ) ) { #>
573 465 <div class="elementor-star-rating__title">{{ settings.title }}</div>
574 466 <# } #>
@@ -576,7 +468,8 @@
576 468 {{{ stars }}}
577 469 <span itemprop="ratingValue" class="elementor-screen-only">{{ textualRating }}</span>
578 470 </div>
579 471 </div>
472 +
580 473 <?php
581 474 }
582 475 }