jjgrainger / PostTypes

Simple WordPress custom post types.
https://posttypes.jjgrainger.co.uk/
MIT License
372 stars 48 forks source link

Create custom actions #84

Open jjgrainger opened 2 years ago

jjgrainger commented 2 years ago

Provide the ability to create custom bulk and row actions with PostTypes. An example of the API could be as follows, but needs further exploration.

// Create a basic event post type.
$event = new PostType('event');

// Create a 'Cancel Event' Bulk Actions
$event->actions()->bulk(
    'cancel-event',     // The unique action name.
    __('Cancel Event'), // The action label.
    function($redirect_url, $action, $post_ids) { // Callback to handle the bulk action request.
        // Do stuff
        return $redirect_url;
    },
    'upload_files' // Optional: Set the capability required to use the bulk action.
);