wp-shortcake / shortcake

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

How to add buttons to Shortcake UI postMediaFrame #754

Closed nicoladj77 closed 6 years ago

nicoladj77 commented 7 years ago

Hi, for a UI reason I would want to add buttons to the Shortcake UI postMediaFrame that, when clicked, perform a custom js action.

To add a button I can simply do:

add_filter('shortcode_ui_shortcodes', function($shortcodes){
    $shortcodes['section'] = [
        'label' => 'Section',
        'shortcode_tag' => 'section',
        'listItemImage' => 'dashicons-forms',
        'attrs' => [],
    ];
    return $shortcodes;
});

Which adds a button ( The fourth one )

image

What I would like to do is that, when I click the new button, I run custom js code. What would be the cleanest way to do this?

szepeviktor commented 7 years ago

Enqueue your JavaScript file on post edit pages and add an event to the Section element with preventDefault()

goldenapples commented 6 years ago

Closing unless there are other questions here.