Ticket #6812 (closed enhancement: fixed)

Opened 4 months ago

Last modified 2 weeks ago

Image captions

Reported by: matt Assigned to: azaozz
Priority: normal Milestone: 2.6
Component: Administration Version: 2.5
Severity: normal Keywords: has-patch
Cc:

Description

Once #6811 is in, a great enhancement to the unified image editor would be the ability to have a caption, and for that to be inserted in a standard easy-to-style way. Here's a great use of image captions:

http://politicalticker.blogs.cnn.com/

We already have a caption field, it's just a matter of exposing that data with the image, maybe shortcode style?

Attachments

img-captions.patch (24.8 kB) - added by azaozz on 07/02/08 10:26:27.
img-captions2.patch (2.0 kB) - added by azaozz on 07/03/08 00:30:00.
img-captions3.patch (2.9 kB) - added by azaozz on 07/03/08 01:04:14.
img_captions4.patch (14.2 kB) - added by azaozz on 07/06/08 13:14:02.
img_captions5.patch (10.2 kB) - added by azaozz on 07/08/08 23:32:37.
img_captions6.patch (11.4 kB) - added by azaozz on 07/10/08 10:40:37.
disable-captions-support.patch (10.3 kB) - added by azaozz on 07/11/08 04:22:22.
disable-captions-support.2.patch (17.7 kB) - added by azaozz on 07/11/08 12:07:53.
img_captions7.patch (11.5 kB) - added by azaozz on 07/13/08 12:34:41.

Change History

06/19/08 23:02:07 changed by azaozz

Have been thinking what's the best way to do this. Generally there seem to be four options:

- Hard-coding the caption tags when the image is inserted. That seems like the easiest/most compatible way. Will only need few lines of css added to wp_head(). Disadvantages: cannot be removed later without editing the posts, no backwards compatibility.

- Filtering the content and adding them to each image. This will require a regexp filtering for the blog and similar js for TinyMCE. Advantages: backwards compatible, can be disabled. Disadvantages: the regexp have to run on each page load and may have to check image sizes (captions on thumbnail sized images don't look good). That could be problematic/quite slow when the image is hosted elsewhere and width/height are not set.

- A combination of the above two. A shortcode can be added around the image tag when inserting the image, then either rendered or removed when displaying the post (or perhaps the whole image tag can be a shortcode). Still won't be backwards compatible, but display of captions could be enabled/disabled on demand.

- The captions can be handled entirely with JavaScript?. This seems the most flexible way. It would be backwards compatible and could be enabled/disabled at any time. Disadvantages: may conflict with some plugins that also use js to change the images (that is also a possibility for all methods).

Also think that we will need another checkbox in the miscellaneous settings to enable/disable the captions globally.

07/02/08 10:26:27 changed by azaozz

  • attachment img-captions.patch added.

07/02/08 11:07:14 changed by azaozz

  • keywords set to has-patch.

Support for image captions, first run. Uses shortcode around the img tag for the caption's settings, so <img/> or <a><img /></a> becomes

[wp_caption]<a><img /></a>[/wp_caption]

This way seems most compatible and at the same time futureproof. Any king of tags can be generated while processing the shortcode, or if captions are not needed, the shortcode can be filtered out and the default tag(s) returned.

Currently the captions are rendered similarly to the gallery page:

<dl>
<dt><a><img /></a></dt>
<dd>caption text</dd>
</dl>

This is supported in both TinyMCE and on the blog. All images that have alt text (attachment excerpt) will have captions when inserted in the editor. Also while editing older posts, if the images are edited and have alt text, the caption will be added. To stop showing caption for an image, the caption text should be deleted while editing the image (with the new popup), or the shortcode can be deleted from the HTML editor.

07/02/08 11:15:33 changed by azaozz

The basic styles for the captions are in the Default and the Classic themes' style.css files. The users would have to copy/paste them in their current theme's style.css, similarly to the alignment classes.

07/02/08 18:41:11 changed by ryan

(In [8239]) Image captions from azaozz. see #6812

07/02/08 22:15:11 changed by ryan

Sometimes I get the raw wp_caption code surrounding the image in the RTE.

07/02/08 23:08:34 changed by ryan

Editing the image and clicking "Update" will sometimes fix it. FF3 on Mac OS.

07/03/08 00:30:00 changed by azaozz

  • attachment img-captions2.patch added.

07/03/08 00:33:51 changed by azaozz

Fix for showing of raw shortcode in the editor: creates the caption HTML before inserting new image, rather than on TinyMCE cleanup.

07/03/08 01:04:14 changed by azaozz

  • attachment img-captions3.patch added.

07/03/08 05:11:00 changed by ryan

(In [8245]) Image caption fixes from azaozz. see #6812

07/06/08 13:14:02 changed by azaozz

  • attachment img_captions4.patch added.

07/06/08 13:19:52 changed by azaozz

This patch includes several fixes: captions are properly created in tables and in lists, all tags are properly removed when deleting a caption, the "align" buttons can be used to align the captions.

07/06/08 16:38:40 changed by ryan

(In [8260]) Image caption fixes from azaozz: captions are properly created in tables and in lists, all tags are properly removed when deleting a caption, the align buttons can be used to align the captions. see #6812

07/08/08 23:32:37 changed by azaozz

  • attachment img_captions5.patch added.

07/08/08 23:37:49 changed by azaozz

Fix for single and double quotes entered in the captions, also simplifies the HTML tags on the site, renames the css classes to use dashes.

07/08/08 23:37:57 changed by ryan

(In [8289]) Use dash instead of underscore for CSS names. Props azaozz. see #6812

07/08/08 23:38:54 changed by ryan

(In [8290]) Fix quotes in captions. Props azaozz. see #6812

07/09/08 21:40:15 changed by Otto42

Caption styles in the default theme are not correct. Dashes instead of underscores, that sort of thing.

07/09/08 21:41:49 changed by Otto42

Additional: My bad, I see that was intentional. Well, if you're going to use dashes, then you should probably make the shortcode actually produce them, because on trunk it's still making underscores and such.

07/09/08 21:44:03 changed by Otto42

Never mind. I'm a moron and forgot to update the wp-include directory.

07/10/08 10:40:37 changed by azaozz

  • attachment img_captions6.patch added.

07/10/08 10:53:23 changed by azaozz

Fixes image resizing inside captions, adds edit alt field to the advanced tab.

07/10/08 16:39:15 changed by ryan

(In [8307]) Fix image resizing inside captions, add edit alt field to the advanced tab. Props azaozz. see #6812

07/11/08 04:22:22 changed by azaozz

  • attachment disable-captions-support.patch added.

07/11/08 04:30:27 changed by azaozz

Support for disabling captions. To disable, define the constant DISABLE_IMAGE_CAPTIONS as true:

define('DISABLE_IMAGE_CAPTIONS', true);

either in wp-config.php or in the theme's functions.php.

07/11/08 08:24:03 changed by matt

That constant is complete bloat, and I don't think it's worth having in WP.

07/11/08 12:07:53 changed by azaozz

  • attachment disable-captions-support.2.patch added.

07/11/08 12:15:44 changed by azaozz

Agree, renamed to CAPTIONS_OFF, also renamed the shortcode to "caption" (the old one is still registered for back compat).

(follow-up: ↓ 26 ) 07/11/08 13:23:20 changed by Otto42

You don't need a constant to not display the captions. Just either don't use the shortcode or hide them using CSS.

Instead of a useless constant, simply make a checkbox for captions on/off on the image insertion screen.

07/11/08 15:26:48 changed by ryan

This is so that themes that provide their own captioning can disable WP's.

07/11/08 15:59:14 changed by ryan

(In [8313]) Rename wp_caption shortcode to caption. Allow themes to disable captioning. Use dashes instead of underscores in class names. Props azaozz. see #6812

07/11/08 15:59:53 changed by ryan

Went with the patch to get the other changes. We change how disabling is done if need be.

(in reply to: ↑ 22 ) 07/11/08 21:11:39 changed by azaozz

Replying to Otto42:

You don't need a constant to not display the captions. Just either don't use the shortcode or hide them using CSS. Instead of a useless constant, simply make a checkbox for captions on/off on the image insertion screen.

It's very easy to stop displaying the captions on the blog. Registering an empty shortcode that returns the <img> tag would do it (the <img> tag is the content of the [caption] shortcode).

Not so easy to disable the adding of captions when inserting or editing an image in the editor though. Of course it can be done with another checkbox in the user's settings, or a checkbox/cookie from js, but that would make it harder for themes/plugins. They will have to support both states, disabled and enabled, as it would be an user setting.

07/12/08 18:02:29 changed by ryan

(In [8321]) Denote CAPTIONS_OFF as temporary. see #6812

07/13/08 12:34:41 changed by azaozz

  • attachment img_captions7.patch added.

07/13/08 12:38:25 changed by azaozz

Removes the disabling of captions, but leaves couple of hooks so a plugin can do it easily.

07/15/08 17:21:34 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.
  • milestone changed from 2.9 to 2.6.

07/16/08 21:36:18 changed by azaozz

(In [8358]) Removes the disabling of captions, but leaves couple of hooks so a plugin can do it easily. see #6812

(follow-up: ↓ 32 ) 07/23/08 20:34:46 changed by Otto42

I don't even see why that filter hook for disable captions is necessary. You've already got a filter to replace the captions system entirely. So disabling captions is as easy as this:

function no_caption($deprecated, $attr, $content) { return $content; };
add_filter('img_caption_shortcode', 'no_caption', 10, 3);

Why have yet another useless filter hook?

(in reply to: ↑ 31 ) 08/10/08 19:26:33 changed by azaozz

Replying to Otto42:

I don't even see why that filter hook for disable captions is necessary. You've already got a filter to replace the captions system entirely. So disabling captions is as easy as this: {{{ function no_caption($deprecated, $attr, $content) { return $content; }; add_filter('img_caption_shortcode', 'no_caption', 10, 3); }}} Why have yet another useless filter hook?

That would stop the captions from displaying on the site, but not in the visual editor and the user will still be able to enter them.

08/10/08 19:33:46 changed by azaozz

(In [8607]) Removes the disabling of captions, but leaves couple of hooks so a plugin can do it easily. For 2.6.1, see #6812