WordPress.org

Make WordPress Core

Opened 2 months ago

Closed 2 months ago

Last modified 8 weeks ago

#41919 closed defect (bug) (fixed)

Image Widget Custom Link Target

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

Description

Hi,

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,
Nenad

Attachments (3)

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

Download all attachments as: .zip

Change History (11)

#1 @westonruter
2 months 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:

https://github.com/WordPress/wordpress-develop/blob/88464ec/src/wp-includes/widgets/class-wp-widget-media-image.php#L244-L248

Last edited 2 months ago by westonruter (previous) (diff)

@Nenad Obradovic
2 months ago

Fixed image widget target value

#2 @subrataemfluence
2 months 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.

http://html.com/attributes/a-target/

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
2 months 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.

@westonruter
2 months ago

#4 @westonruter
2 months 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
2 months 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
2 months ago

  • Keywords has-patch added; needs-patch removed

#7 in reply to: ↑ 3 @subrataemfluence
2 months 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
8 weeks ago

#42010 was marked as a duplicate.

Note: See TracTickets for help on using tickets.