What if the user ( by accident or intention ) has multiple twitch videos on the same page? I think you’re better off having the channel set in each shortcode. Trying to daisychain these shortcodes will only lead to headache down the line as the plugin grows and features get added.
For usability it may be best to create a page to generate these shortcodes for the user. Maybe a post type that generates the shortcodes and allows the user to set options for the different shortcode.
– – – – – –
If you really want to do something like this you can search the content for your specific shortcode: https://stackoverflow.com/a/32525101/800452
Thread Starter
Felty
(@felty)
That’s a good point. Generally, I was assuming it would be the content creator doing this themselves which would only be one stream at a time, but if you had a curator, that would be more of an issue.
I’ll require each of them to be set for each, but I’d still be interested if it’s possible as run into it before with other things I’ve done.
Shortcodes essentially call a function whose return is echoed out. Similar issues arise in any PHP function wanting data that is out of its scope. Thus similar solutions can be used for shortcodes. Globals, static class properties, cookies, session vars could all be used to get values that would otherwise be out of scope.
Your shortcode handler could take passed attributes as normal and set the chosen global scope mechanism. If no attribute value is passed, attempt to get the value from that global scope mechanism. Do some default action if neither are available. In the case of possibly multiple attributes used by one person, the value used ends up being the last value explicitly passed. It’s similar to trying to use global $post outside of the loop. Something we can do, but it’s not really a good idea.