Skip to content
This repository has been archived by the owner on Apr 2, 2020. It is now read-only.

Default to media library caption and omit caption attribute #77

Open
montchr opened this issue Aug 29, 2017 · 7 comments
Open

Default to media library caption and omit caption attribute #77

montchr opened this issue Aug 29, 2017 · 7 comments

Comments

@montchr
Copy link
Contributor

montchr commented Aug 29, 2017

Current Behavior

When an image in the media library is given a caption and inserted into a post, the caption at that moment will be saved in the caption attribute of the shortcode. If the caption is later changed in the media library, the caption does not change in the post.

This could be a significant issue especially in cases where an image was inserted into multiple posts and a factual error needs to be changed in the caption for all of those posts.

Suggested Behavior

When an attachment with a caption is added to a post, it should not have a caption attribute on the shortcode. That way the image caption in the post will be linked to the image caption as it exists in the media library.

If the user wants to override the caption for a specific instance of the shortcode in a post, they should still be able to do so by either adding the caption attribute manually or editing the caption with the shortcode UI. At that point, the caption will be unique to that particular instance and will no longer be linked to the value of the caption in the media library until the caption attribute is removed.

@goldenapples
Copy link
Contributor

goldenapples commented Aug 30, 2017

I think the suggestion makes good sense. But this would be inconsistent with the core media experience. I think the current experience was designed for people familiar with the core media management flow - where a caption is set as text in the shortcode when the image is first sent to the the editor and then remains the same, whatever happens to the attachment post.

We're not constrained by the same limitations here, so it would be possible to pull the caption field dynamically from the attachment post. It just requires a bit of thinking through to be unsurprising.

In your suggestion, how would you indicate a selection of "no caption" - if the attachment in the media library has a caption set, but the post author doesn't want it to display with a caption in a specific post?

@davisshaver
Copy link
Member

Was going to make same point @goldenapples did about no caption, maybe this could also be considered as an opt-in for "dynamic caption" or something else to remind folks it's different from typical behavior? In general though, thumbs up from me.

@montchr
Copy link
Contributor Author

montchr commented Aug 31, 2017

How about this:

  • Insert the shortcode normally, no changes to behavior
  • The caption at the time of insertion will be stored in the caption attribute as it is currently
  • The input field will mirror the caption as set in the caption attribute
  • Add a single checkbox field associated with the caption field, displayed above/alongside/below the input field, labelled something like Link with the caption from the media library?, default unchecked
  • Add a new attribute to store the checkbox setting, something like attachment_caption="true"
  • If unchecked, then the input field will be editable, with changes taking effect on the frontend
  • If unchecked, and the text in the input field is deleted, then the caption will be empty and the attribute caption will be removed
  • If checked, the input field will be disabled – the input text and caption attribute will remain – and the rendered caption will match whatever is in the media library

If the default should be unchecked, for my use case we need to provide an option to switch the default to checked – what would be the best way to do this in a way consistent with the plugin? Would it be something like a filter with a callback that returns a boolean?

Would it also make sense to extend this behavior to the alt attribute of the image? If the field is empty, then use the alt from media library since that attribute is required for <img> elements.

I'll gladly put together a pull request if this proposal sounds good.

@davisshaver
Copy link
Member

+1 from me, I think this is an improvement over the existing handling. I believe the filtering we did in the PDF shortcode might help with your question about the specific use but let me know what you think: https://github.com/wp-shortcake/shortcake-bakery/blob/master/inc/shortcodes/class-pdf.php

@montchr
Copy link
Contributor Author

montchr commented Sep 5, 2017

Okay great I'll put something together.

@montchr
Copy link
Contributor Author

montchr commented Sep 5, 2017

I believe the filtering we did in the PDF shortcode might help with your question about the specific use but let me know what you think: https://github.com/wp-shortcake/shortcake-bakery/blob/master/inc/shortcodes/class-pdf.php

You mean this? Yeah that makes sense.

@davisshaver
Copy link
Member

@montchr Exactly... lmk if you need any help with this, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants