Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#41919 closed defect (bug) (fixed)

Image Widget Custom Link Target

Reported by: nenad-obradovic's profile Nenad Obradovic Owned by: westonruter's profile westonruter
Milestone: 4.9 Priority: normal
Severity: normal Version: 4.8
Component: Widgets Keywords: commit has-patch
Focuses: Cc:



I think there is a small issue inside WP_Widget_Media_Image Class with link_target_blank option, when you render html code for this widget (code below) you only set target value to be _blank if this option is set in otherwise target value is empty and HTML validator mark this empty target value as error because that attribute can't be empty. Thanks

! empty( $instance['link_target_blank'] ) ? '_blank' : '',

Best regards,

Attachments (3)

class-wp-widget-media-image.php.patch (499 bytes) - added by Nenad Obradovic 7 years ago.
Fixed image widget target value
41919.2.diff (609 bytes) - added by subrataemfluence 7 years ago.
41919.3.diff (2.5 KB) - added by westonruter 7 years ago.

Download all attachments as: .zip

Change History (11)

#1 @westonruter
7 years ago

  • Keywords needs-patch good-first-bug added
  • Milestone changed from Awaiting Review to 4.9
  • Version changed from 4.8.1 to 4.8

You're right. Would you like to submit a patch?

For reference, here's a direct link to the code in question:

Last edited 7 years ago by westonruter (previous) (diff)

@Nenad Obradovic
7 years ago

Fixed image widget target value

#2 @subrataemfluence
7 years ago

Good catch! Thanks for the ticket.

However, looking at HTML5 coding standard the only two values allowed for target attribute are _blank and _self.

Values like _top, _parent and <frame_name> are now deprecated in HTML5 standard.

The line in question is also checking only for the value _blank, keeping above in mind. So, how about we do not add the target attribute at all if the value is not _blank since _self is default if no target attribute is set.

I have uploaded a modified diff. Please let me know if this makes sense.

#3 follow-up: @westonruter
7 years ago

  • Keywords commit added; good-first-bug removed
  • Owner set to westonruter
  • Status changed from new to accepted

@subrataemfluence Your patch is perfect. Exactly what I was envisioning.

7 years ago

#4 @westonruter
7 years ago

It looks like actually 41919.2.diff doesn't go far enough. There are other attributes, including class and rel that also should be omitted when empty. See 41919.3.diff.

#5 @westonruter
7 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 41549:

Widgets: Omit attributes from an Image widget's link when they are empty.

Props subrataemfluence, Nenad Obradovic, westonruter.
See #39993.
Fixes #41919.

#6 @westonruter
7 years ago

  • Keywords has-patch added; needs-patch removed

#7 in reply to: ↑ 3 @subrataemfluence
7 years ago

@westonruter Thank you! Also thank you for considering class and rel attributes as well :)

Replying to westonruter:

@subrataemfluence Your patch is perfect. Exactly what I was envisioning.

#8 @westonruter
7 years ago

#42010 was marked as a duplicate.

Note: See TracTickets for help on using tickets.