wp-shortcake / shortcake

Shortcake makes using WordPress shortcodes a piece of cake.
GNU General Public License v2.0
664 stars 143 forks source link

Can shortcodes with content be made reusable? #609

Open aaires opened 8 years ago

aaires commented 8 years ago

Hi there, first of all thanks for the amazing plugin. Second I would like to pick your brain with something I'm trying to accomplish. I would like to have the possibility to save a shortcode created with the UI (shortcode + content) so it can than be re-used in the future. Lets say I have a quote I need to use in several posts instead of writing every time the quote it would be great to re-use it. So I can see how to extend the plugin to search and filter a CPT with the "saved" shortcodes but I am still struggling in finding a way to save it on the fly. Did you ever think on a solution for this? Do you have any hints on how to accomplish something like this?

Thank you in advance

StaggerLeee commented 8 years ago

You cant, unless you save your "quotes" directly in Shortcake PHP file. This should not be done. I guess you want to call values form Posts and save them back on the fly (one Post per "quote"). What makes it even much more complex to achieve.

Reusable content is easy to make with other means and tools, not Shortcake. But problem is your wish to save it when you want it, how you want it. No TinyMce content snippets tool, or custom fields, will allow you do this.

Sorry if I am wrong, others can say it better.

goldenapples commented 8 years ago

What I've done in similar cases in the past is to use a javascript hook on updating a field in Shortcake, which pings an Ajax endpoint that can handle whatever data storage format you need (saving the text to a custom post type, for example). You then could have a Post Select field to choose items in that custom post type.

The shortcode UI for the Protected Embeds plugin takes an approach like this. Only the ID of the embed post is actually stored as a shortcode attribute, but on rendering the shortcode, that ID is made read-only and the content of the embed is loaded from an admin-ajax endpoint. That content is then exposed in a textarea, and edits to that textarea are saved back to the CPT.

It sounds like the approach you're hoping to take has an extra step to it, but hopefully this can get you part of the way there?

mattheu commented 8 years ago

Yes I like this idea. I think using some kind of external (and potentially re-usable) data store has other benefits too - handling complex data such as HTML that doesn't play nice with shortcode attributes.

We've discussed using Post meta with some kind of UUID to tie the 2 together, or using a separate post type for content blocks. Possibly even combining this with Widgets and moving those out of the options table.