We're about to start developing a new relatively simple widget in the form of a plugin for a specific client job - but want to create something that will be usable on future projects.
This plugin will allow a user to highlight one or more lines of text in the page they are editing and select these to be shown on the page as suggested content to share via Social Networks - such as Facebook.
Here are a few possible methods to achieve this:
Method One - Shortcodes
Add a shortcode which the user can wrap around text they wish to be used for the suggested share content.
Pros:
- Shortcodes are built-in functionality for WordPress - even if the plugin was disabled, they would not mess up the content.
- existing content will always match the snippets for sharing - as they need to exist in the actual page content.
Cons:
- Users always mess-up shortcodes, they are tricky and when mixed together with other shortcodes, soon become hard to manage.
Method Two - Post Meta
Add a custom "Meta Box" to the post edit screen and use JavaScript to allow the user to highlight text and a click a button to add individual snippets - allowing for multiple snippets.
On post save, grab all the snippet and save in an Array as a single post meta row.
Pros:
- Original content is not edited in case of plugin problems, nothing else goes wrong.
Cons:
- Content might be edited or removed from the original post, so we'll need extra steps to sync or remove outdated snippets.
- Polylang translated websites often share post meta values content across posts ( it's a configuration option ), invalidating this method - without additional tricks.
Of course, there are more routes - that's what this question is about - how else could / would you do it and why - and what important considerations did we miss?