2017 © Pedro PelĂĄez
 

wordpress-plugin wp-custom-bulk-actions

Custom bulk actions for any type of posts in WordPress.

image

seravo/wp-custom-bulk-actions

Custom bulk actions for any type of posts in WordPress.

  • Monday, April 2, 2018
  • by Seravo
  • Repository
  • 11 Watchers
  • 37 Stars
  • 94 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 1 Open issues
  • 4 Versions
  • 11 % Grown

The README.md

Custom Bulk Actions

Build Status Custom bulk actions for any type of posts in WordPress., (*1)

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

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

Installation

Available for installation via Composer via Packagist or GitHub Plugin Search., (*4)

Plugin

This plugin adds a class named Seravo_Custom_Bulk_Action, (*5)

Class functions

Constructor with post as default post type, (*6)

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

Add actions. You must define at least menu_text and callback function., (*7)

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

admin_notice parameter accepts arrays for plural texts too (thanks @cyberwani) For example:, (*8)

register_bulk_action(array(
'menu_text' => $your_menu_text,
'admin_notice' => 'admin_notice'=>array(
    'single' => '%s Appointment cancelled.',
    'plural' => '%s Appointments cancelled.',
),
'action_name' => $optional_action_name,
'callback' => $anonymous_function
));

Your anonymous callback function needs to have post_ids as parameter:, (*9)

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

Init functions to wordpress, (*10)

init();

Example & how to use

Install plugin and define your bulk actions in functions.php., (*11)

In this example we're going to update metadata _property_status of custom posts called property, (*12)

//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();

The Versions

02/04 2018

dev-master

9999999-dev https://github.com/Seravo/wp-custom-bulk-actions

Custom bulk actions for any type of posts in WordPress.

  Sources   Download

GPLv3 GPL-3.0

wordpress posts custom bulk action

01/04 2018

0.1.4

0.1.4.0 https://github.com/Seravo/wp-custom-bulk-actions

Custom bulk actions for any type of posts in WordPress.

  Sources   Download

GPLv3

wordpress posts custom bulk action

06/08 2015

0.1.3

0.1.3.0 https://github.com/Seravo/wp-custom-bulk-actions

Custom bulk actions for any type of posts in WordPress.

  Sources   Download

GPLv3

wordpress posts custom bulk action

17/06 2015

0.1.2

0.1.2.0 https://github.com/Seravo/wp-custom-bulk-actions

Custom bulk actions for any type of posts in WordPress.

  Sources   Download

GPLv3

wordpress posts custom bulk action