WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 2 years ago

Last modified 2 years ago

#12464 closed defect (bug) (duplicate)

Text links are stripped from image captions

Reported by: dnusim Owned by: azaozz
Milestone: Priority: normal
Severity: normal Version: 2.9.2
Component: TinyMCE Keywords: needs-patch gsoc
Focuses: Cc:

Description

Basic HTML, like text links, should be allowed in image captions. Links are now stripped from the captions.

Text links in the image caption would be the most logical way to credit the photographer. In some cases, a link to the license covering the image is also mandatory. Creative Commons-licensed images are a great example of this.

Attachments (2)

12464.diff (1.3 KB) - added by ericlewis 2 years ago.
12464.2.diff (1.3 KB) - added by ericlewis 2 years ago.
Fix replace ' instead of ' for single quotes in [caption] string

Download all attachments as: .zip

Change History (19)

comment:1 simonlawrence4 years ago

  • Cc simonlawrence added

When you use the visual editor to add a link to the caption text it is stripped out when saving but you can edit the caption attribute in the HTML view and it will save.

I have found several people talking about it:

http://www.priceplow.com/wordpress-link-in-image-caption
http://www.transformationpowertools.com/wordpress/hyperlinks-in-wordpress-image-captions
http://blogwip.com/images/adding-linked-captions-images-wordpress/

Looking through the code and it appears to be the "wpeditimage" TinyMCE JavaScript plugin that is replacing all HTML tags in the contents of the caption attribute:

h=h.replace(/<\S[^<>]*>/gi,"").replace(/'/g,"&#39;").replace(/"/g,"&quot;");

from /wp-includes/js/tinymce/wp-tinymce.php

comment:2 dnusim4 years ago

  • Cc wordpress-thomas@… added

comment:3 nacin4 years ago

  • Component changed from Gallery to TinyMCE
  • Milestone changed from Unassigned to Future Release
  • Owner set to azaozz

comment:4 dnusim4 years ago

  • Milestone changed from Future Release to 3.1

As it turns out: Links with singly-quoted attributes are only stripped if you are using the visual editor (in WP 2.9.2). If you are using the basic (HTML) editor, they are instead escaped before inserting them into the shortcode, which works fine.

I'm guessing a solution would involve doubly-quoted attributes being made singly-quoted before they are escaped, as I'm guessing the double quotes mess up the way shortcodes work. On top of that we need to figure out why the visual editor doesn't give the same result as the basic editor.

Changing milestone to 3.1 as this seems to affect a lot of people.

comment:5 dnusim4 years ago

  • Keywords needs-patch added

comment:6 wojtek.szkutnik4 years ago

  • Keywords gsoc added

comment:7 dnusim4 years ago

This issue seems to be resolved in trunk. If someone will confirm, I think we can close this.

comment:8 blepoxp4 years ago

Single quotes work in HTML mode. Double quotes in HTML mode (escaped or not) break the caption if caption="..." uses double quotes. Tags are stripped if you use the caption field in the Image GUI but the caption still works.

comment:9 nacin3 years ago

  • Milestone changed from Awaiting Triage to 3.1

I thought this was going to happen in 3.1 with the TinyMCE update. Moving there just because I think there might be a duplicate ticket or some code somewhere. Otherwise, punt.

comment:10 ryan3 years ago

  • Milestone changed from 3.1 to Future Release

comment:11 jane2 years ago

  • Milestone changed from Future Release to 3.4

comment:12 anointed2 years ago

  • Cc anointed added

comment:13 DrewAPicture2 years ago

  • Cc xoodrew@… added

ericlewis2 years ago

comment:15 ericlewis2 years ago

I'm not sure if this is perfect, but I think a step in the right direction here. This patch helps with adding links to captions in the visual editor mode.

The issue with links in the visual editor is that captions have all HTML entities filtered out of them. The patch filters out only non-anchor tags, leaving anchors there.

The other issue is the caption shortcode holds the text for caption between double quotes. To deal with this all quotes within the caption are converted to single quotes.

ericlewis2 years ago

Fix replace ' instead of &#39; for single quotes in [caption] string

comment:16 ericlewis2 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

This has at this point been taken care of in #18311

Last edited 2 years ago by nacin (previous) (diff)

comment:17 nacin2 years ago

  • Milestone 3.4 deleted
Note: See TracTickets for help on using tickets.