PHP code example of seravo / wp-custom-bulk-actions
1. Go to this page and download the library: Download seravo/wp-custom-bulk-actions library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
seravo / wp-custom-bulk-actions example snippets
new Seravo_Custom_Bulk_Action(array('post_type' => $custom_post));
function($post_ids) {
//Do something here
};
$post_ids //Array of post IDs selected by user in admin panel
init();
//Define bulk actions for custom-post-type property
$bulk_actions = new Seravo_Custom_Bulk_Action(array('post_type' => 'property'));
//ACTION EXAMPLE 1:
$bulk_actions->register_bulk_action(array(
'menu_text'=>'Mark as sold (Myyty)',
'admin_notice'=>'Properties marked as sold',
'callback' => function($post_ids) {
//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 action_name is optional but useful if you want to have non-ascii chars in menu_text
$bulk_actions->register_bulk_action(array(
'menu_text'=>'Mark for sale (Myytäväksi)',
'admin_notice'=>'Properties marked for sale',
'action_name'=>'for_sale',
'callback' => function($post_ids) {
//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();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.