Widgets: Omit attributes from an Image widget's link when they are empty.
Props subrataemfluence, Nenad Obradovic, westonruter. See #39993. Fixes #41919. git-svn-id: https://develop.svn.wordpress.org/trunk@41549 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
6d341ef5e5
commit
ebb578b2d9
@ -240,14 +240,20 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
|
||||
}
|
||||
|
||||
if ( $url ) {
|
||||
$image = sprintf(
|
||||
'<a href="%1$s" class="%2$s" rel="%3$s" target="%4$s">%5$s</a>',
|
||||
esc_url( $url ),
|
||||
esc_attr( $instance['link_classes'] ),
|
||||
esc_attr( $instance['link_rel'] ),
|
||||
! empty( $instance['link_target_blank'] ) ? '_blank' : '',
|
||||
$image
|
||||
);
|
||||
$link = sprintf( '<a href="%s"', esc_url( $url ) );
|
||||
if ( ! empty( $instance['link_classes'] ) ) {
|
||||
$link .= sprintf( ' class="%s"', esc_attr( $instance['link_classes'] ) );
|
||||
}
|
||||
if ( ! empty( $instance['link_rel'] ) ) {
|
||||
$link .= sprintf( ' rel="%s"', esc_attr( $instance['link_rel'] ) );
|
||||
}
|
||||
if ( ! empty( $instance['link_target_blank'] ) ) {
|
||||
$link .= ' target="_blank"';
|
||||
}
|
||||
$link .= '>';
|
||||
$link .= $image;
|
||||
$link .= '</a>';
|
||||
$image = $link;
|
||||
}
|
||||
|
||||
if ( $caption ) {
|
||||
|
@ -393,12 +393,10 @@ class Test_WP_Widget_Media_Image extends WP_UnitTestCase {
|
||||
|
||||
$link = '<a href="' . wp_get_attachment_url( $attachment_id ) . '"';
|
||||
$this->assertContains( $link, $output );
|
||||
$link .= ' class=""';
|
||||
$this->assertContains( $link, $output );
|
||||
$link .= ' rel=""';
|
||||
$this->assertContains( $link, $output );
|
||||
$link .= ' target=""';
|
||||
$this->assertContains( $link, $output );
|
||||
$this->assertTrue( (bool) preg_match( '#<a href.*?>#', $output, $matches ) );
|
||||
$this->assertNotContains( ' class="', $matches[0] );
|
||||
$this->assertNotContains( ' rel="', $matches[0] );
|
||||
$this->assertNotContains( ' target="', $matches[0] );
|
||||
|
||||
ob_start();
|
||||
$widget->render_media( array(
|
||||
@ -413,7 +411,7 @@ class Test_WP_Widget_Media_Image extends WP_UnitTestCase {
|
||||
$this->assertContains( '<a href="' . get_attachment_link( $attachment_id ) . '"', $output );
|
||||
$this->assertContains( 'class="custom-link-class"', $output );
|
||||
$this->assertContains( 'rel="attachment"', $output );
|
||||
$this->assertContains( 'target=""', $output );
|
||||
$this->assertNotContains( 'target=""', $output );
|
||||
|
||||
ob_start();
|
||||
$widget->render_media( array(
|
||||
|
Loading…
Reference in New Issue
Block a user