WordPress.org

Make WordPress Core

Ticket #16031: 16031-plugin-example.php

File 16031-plugin-example.php, 770 bytes (added by ericlewis, 22 months ago)
Line 
1<?php
2// Add the button to the bulk action dropdown.
3add_action( 'bulk_actions-edit-post', function($actions) {
4        $actions['glerf'] = 'Glerf';
5        return $actions;
6});
7
8// Add a form submission handler.
9add_action( 'handle_bulk_actions-edit-post', function($action) {
10        if ( $action !== 'glerf') {
11                return;
12        }
13        // do something productive here
14});
15
16// Add a filter on the "sendback" URL, to give the next List Table load statefulness
17// about what happened. Then we could display an admin message to tell the user
18// about what happened here.
19add_filter( 'after_handle_bulk_actions_sendback_link-edit-post', function($sendback, $action) {
20        if ( $action !== 'glerf' ) {
21                return $sendback;
22        }
23        $sendback = add_query_arg('glerfed', 1, $sendback);
24        return $sendback;
25}, 10, 2);