Changeset 54101
- Timestamp:
- 09/08/2022 02:32:07 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-supports/duotone.php
r53012 r54101 374 374 * 375 375 * @since 5.9.0 376 * @since 6.1.0 Allow unset for preset colors. 376 377 * @access private 377 378 * … … 380 381 */ 381 382 function wp_get_duotone_filter_property( $preset ) { 383 if ( isset( $preset['colors'] ) && 'unset' === $preset['colors'] ) { 384 return 'none'; 385 } 382 386 $filter_id = wp_get_duotone_filter_id( $preset ); 383 387 return "url('#" . $filter_id . "')"; … … 459 463 // Clean up the whitespace. 460 464 $svg = preg_replace( "/[\r\n\t ]+/", ' ', $svg ); 461 $svg = preg_replace( '/> </', '><', $svg );465 $svg = str_replace( '> <', '><', $svg ); 462 466 $svg = trim( $svg ); 463 467 } … … 497 501 * 498 502 * @since 5.8.0 503 * @since 6.1.0 Allow unset for preset colors. 499 504 * @access private 500 505 * … … 520 525 } 521 526 527 $colors = $block['attrs']['style']['color']['duotone']; 528 $filter_key = is_array( $colors ) ? implode( '-', $colors ) : $colors; 522 529 $filter_preset = array( 523 'slug' => wp_unique_id( sanitize_key( implode( '-', $block['attrs']['style']['color']['duotone'] ). '-' ) ),524 'colors' => $ block['attrs']['style']['color']['duotone'],530 'slug' => wp_unique_id( sanitize_key( $filter_key . '-' ) ), 531 'colors' => $colors, 525 532 ); 526 533 $filter_property = wp_get_duotone_filter_property( $filter_preset ); 527 534 $filter_id = wp_get_duotone_filter_id( $filter_preset ); 528 $filter_svg = wp_get_duotone_filter_svg( $filter_preset );529 535 530 536 $scope = '.' . $filter_id; … … 546 552 wp_enqueue_style( $filter_id ); 547 553 548 add_action( 549 'wp_footer', 550 static function () use ( $filter_svg, $selector ) { 551 echo $filter_svg; 552 553 /* 554 * Safari renders elements incorrectly on first paint when the SVG 555 * filter comes after the content that it is filtering, so we force 556 * a repaint with a WebKit hack which solves the issue. 557 */ 558 global $is_safari; 559 if ( $is_safari ) { 560 printf( 561 // Simply accessing el.offsetHeight flushes layout and style 562 // changes in WebKit without having to wait for setTimeout. 563 '<script>( function() { var el = document.querySelector( %s ); var display = el.style.display; el.style.display = "none"; el.offsetHeight; el.style.display = display; } )();</script>', 564 wp_json_encode( $selector ) 565 ); 554 if ( 'unset' !== $colors ) { 555 $filter_svg = wp_get_duotone_filter_svg( $filter_preset ); 556 add_action( 557 'wp_footer', 558 static function () use ( $filter_svg, $selector ) { 559 echo $filter_svg; 560 561 /* 562 * Safari renders elements incorrectly on first paint when the 563 * SVG filter comes after the content that it is filtering, so 564 * we force a repaint with a WebKit hack which solves the issue. 565 */ 566 global $is_safari; 567 if ( $is_safari ) { 568 /* 569 * Simply accessing el.offsetHeight flushes layout and style 570 * changes in WebKit without having to wait for setTimeout. 571 */ 572 printf( 573 '<script>( function() { var el = document.querySelector( %s ); var display = el.style.display; el.style.display = "none"; el.offsetHeight; el.style.display = display; } )();</script>', 574 wp_json_encode( $selector ) 575 ); 576 } 566 577 } 567 }568 );578 ); 579 } 569 580 570 581 // Like the layout hook, this assumes the hook only applies to blocks with a single wrapper.
Note: See TracChangeset
for help on using the changeset viewer.