wp-shortcake / shortcake

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

Conditionally show/hide in modal selection? #464

Closed GaryJones closed 1 year ago

GaryJones commented 9 years ago

Is there a feature (if not, please consider this a suggestion) to conditionally hide certain post elements in the modal selection?

screenshot 2015-09-24 10 59 26

Here, all of the Member Area items are really "use once" shortcodes, in the pages that output that logic (but which clients may want to add manually entered content between). However, for the regular posts where a client wants to use the EIA Visualization, the Member Area icons clutter up the view.

Is there a way to conditionally choose when icons appear i.e. not only when editing a Page (vs Post) (using existing post_type key) but also when the user has a certain ID, or it's a Friday, or some other condition? i.e. some filterable value that accepts a custom closure (which returns true or false) before showing the icon in the modal?

shortcode_ui_register_for_shortcode(
        'shortcake_dev',
        array(
            ...
            'post_type'     => array( 'post' ),
            'show_ui'      => function() {
                // Some custom condition that determines when the icon appears. Overrides `post_type`.
                if ( $foo ) { // Show icon if $foo.
                    return true;
                }

                return false;
            }
            ...

In my case, since our Member Area is a Page, with child pages, my custom condition would be to only show the Member Area icons when the current Page being edited has an ID of 123 / slug of profile, or has a parent with that ID / slug.

goldenapples commented 9 years ago

Is there a way to conditionally choose when icons appear i.e. not only when editing a Page (vs Post) (using existing post_type key) but also when the user has a certain ID, or it's a Friday, or some other condition?

You can look at the context available to the register_shortcode_ui hook, which will give you the ID and the settings of the first editor on the page. (If you register the shortcode UI at that point, globals will also be set up, and you can check for the global post object, or current user, or any other variant).