diff --git src/wp-includes/widgets/class-wp-widget-media-image.php src/wp-includes/widgets/class-wp-widget-media-image.php
index 2b9bff221b..a0359bcbfd 100644
|
|
|
class WP_Widget_Media_Image extends WP_Widget_Media {
|
| 261 | 261 | $link .= sprintf( ' rel="%s"', esc_attr( $instance['link_rel'] ) ); |
| 262 | 262 | } |
| 263 | 263 | if ( ! empty( $instance['link_target_blank'] ) ) { |
| | 264 | if ( empty( $instance['link_rel'] ) ) { |
| | 265 | $link .= ' rel="noopener noreferrer"'; |
| | 266 | } |
| 264 | 267 | $link .= ' target="_blank"'; |
| 265 | 268 | } |
| 266 | 269 | $link .= '>'; |
diff --git tests/phpunit/tests/widgets/media-image-widget.php tests/phpunit/tests/widgets/media-image-widget.php
index e138f3e796..755a65c171 100644
|
|
|
class Test_WP_Widget_Media_Image extends WP_UnitTestCase {
|
| 503 | 503 | 'link_type' => 'custom', |
| 504 | 504 | 'link_url' => 'https://example.org', |
| 505 | 505 | 'link_target_blank' => true, |
| | 506 | 'link_rel' => false, |
| 506 | 507 | ) |
| 507 | 508 | ); |
| 508 | 509 | $output = ob_get_clean(); |
| 509 | 510 | |
| 510 | 511 | $this->assertContains( '<a href="https://example.org"', $output ); |
| 511 | 512 | $this->assertContains( 'target="_blank"', $output ); |
| | 513 | $this->assertContains( 'rel="noopener noreferrer"', $output ); |
| 512 | 514 | |
| 513 | 515 | // Populate caption in attachment. |
| 514 | 516 | wp_update_post( |