wp-custom-bulk-actions

Currently Wordpress doesn't allow you to add custom bulk actions. See codex. Adding them is super easy with this plugin.

This is based on solution found here, but makes it more easier to use.

Plugin

This plugin adds a class named SeravoCustomBulk_Action

Class functions

Constructor with post as default post type

php new Seravo_Custom_Bulk_Action(array('post_type' => $custom_post));

Add actions. You must define at least menu_text and callback function.

php register_bulk_action(array( 'menu_text'=>$your_menu_text, 'admin_notice'=>$display_text_for_admin, 'action_name'=>$optional_action_name, 'callback'=>$anonymous_function ));

Your anonymous callback function needs to have post_ids as parameter:

php function($post_ids) { //Do something here }; $post_ids //Array of post IDs selected by user in admin panel

Init functions to wordpress

php init();

Example & how to use

Install plugin and define your bulk actions in functions.php.

In this example we're going to update metadata propertystatus of custom posts called property

`

//Define bulk actions for custom-post-type property $bulkactions = new SeravoCustomBulkAction(array('post_type' => 'property'));

//ACTION EXAMPLE 1:

$bulkactions->registerbulkaction(array( 'menutext'=>'Mark as sold (Myyty)', 'adminnotice'=>'Properties marked as sold', 'callback' => function($postids) {

//Do something with $post_ids here

//In this example properties are marked as sold
foreach ($post_ids as $post_id) {
    update_post_meta($post_id,"_property_status", "sold");
}
return true;

}));

//ACTION EXAMPLE 2, non-ascii chars in menutext: //Defining the actionname is optional but useful if you want to have non-ascii chars in menutext

$bulkactions->registerbulkaction(array( 'menutext'=>'Mark for sale (Myytäväksi)', 'adminnotice'=>'Properties marked for sale', 'actionname'=>'forsale', 'callback' => function($postids) {

//Do something with $post_ids here

//In this example properties are marked for sale
foreach ($post_ids as $post_id) {
    update_post_meta($post_id,"_property_status", "sale");
}
return true;

}));

//Finally init actions $bulk_actions->init();