diff --git src/wp-includes/widgets/class-wp-widget-media-image.php src/wp-includes/widgets/class-wp-widget-media-image.php
index e0dafd3733..8fbb952f9a 100644
|
|
|
class WP_Widget_Media_Image extends WP_Widget_Media { |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | if ( $url ) { |
| 243 | | $image = sprintf( |
| 244 | | '<a href="%1$s" class="%2$s" rel="%3$s" target="%4$s">%5$s</a>', |
| 245 | | esc_url( $url ), |
| 246 | | esc_attr( $instance['link_classes'] ), |
| 247 | | esc_attr( $instance['link_rel'] ), |
| 248 | | ! empty( $instance['link_target_blank'] ) ? '_blank' : '', |
| 249 | | $image |
| 250 | | ); |
| | 243 | $link = sprintf( '<a href="%s"', esc_url( $url ) ); |
| | 244 | if ( ! empty( $instance['link_classes'] ) ) { |
| | 245 | $link .= sprintf( ' class="%s"', esc_attr( $instance['link_classes'] ) ); |
| | 246 | } |
| | 247 | if ( ! empty( $instance['link_rel'] ) ) { |
| | 248 | $link .= sprintf( ' rel="%s"', esc_attr( $instance['link_rel'] ) ); |
| | 249 | } |
| | 250 | if ( ! empty( $instance['link_target_blank'] ) ) { |
| | 251 | $link .= ' target="_blank"'; |
| | 252 | } |
| | 253 | $link .= '>'; |
| | 254 | $link .= $image; |
| | 255 | $link .= '</a>'; |
| | 256 | $image = $link; |
| 251 | 257 | } |
| 252 | 258 | |
| 253 | 259 | if ( $caption ) { |
diff --git tests/phpunit/tests/widgets/media-image-widget.php tests/phpunit/tests/widgets/media-image-widget.php
index 7fadbbc7d3..408123bef7 100644
|
|
|
class Test_WP_Widget_Media_Image extends WP_UnitTestCase { |
| 393 | 393 | |
| 394 | 394 | $link = '<a href="' . wp_get_attachment_url( $attachment_id ) . '"'; |
| 395 | 395 | $this->assertContains( $link, $output ); |
| 396 | | $link .= ' class=""'; |
| 397 | | $this->assertContains( $link, $output ); |
| 398 | | $link .= ' rel=""'; |
| 399 | | $this->assertContains( $link, $output ); |
| 400 | | $link .= ' target=""'; |
| 401 | | $this->assertContains( $link, $output ); |
| | 396 | $this->assertTrue( (bool) preg_match( '#<a href.*?>#', $output, $matches ) ); |
| | 397 | $this->assertNotContains( ' class="', $matches[0] ); |
| | 398 | $this->assertNotContains( ' rel="', $matches[0] ); |
| | 399 | $this->assertNotContains( ' target="', $matches[0] ); |
| 402 | 400 | |
| 403 | 401 | ob_start(); |
| 404 | 402 | $widget->render_media( array( |
| … |
… |
class Test_WP_Widget_Media_Image extends WP_UnitTestCase { |
| 413 | 411 | $this->assertContains( '<a href="' . get_attachment_link( $attachment_id ) . '"', $output ); |
| 414 | 412 | $this->assertContains( 'class="custom-link-class"', $output ); |
| 415 | 413 | $this->assertContains( 'rel="attachment"', $output ); |
| 416 | | $this->assertContains( 'target=""', $output ); |
| | 414 | $this->assertNotContains( 'target=""', $output ); |
| 417 | 415 | |
| 418 | 416 | ob_start(); |
| 419 | 417 | $widget->render_media( array( |