1 | <?php |
---|
2 | /* |
---|
3 | Plugin Name: Bulk Actions Test |
---|
4 | Plugin URI: |
---|
5 | Description: Tests bulk actions for all screens |
---|
6 | Author: Matt van Andel |
---|
7 | Version: 1.0 |
---|
8 | Author URI: |
---|
9 | */ |
---|
10 | |
---|
11 | add_filter( 'pre_option_link_manager_enabled', '__return_true' ); |
---|
12 | |
---|
13 | add_action( 'current_screen', function () { |
---|
14 | |
---|
15 | // Add new bulk action to all screens |
---|
16 | add_filter( 'bulk_actions-' . get_current_screen()->id, 'bulkactiontest_add_bulk_action' ); |
---|
17 | |
---|
18 | // Add new bulk action handler to all screens |
---|
19 | add_filter( 'handle_bulk_actions-' . get_current_screen()->id, 'bulkactiontest_handle_bulk_action', 10, 3 ); |
---|
20 | |
---|
21 | // Display notice after bulk action is handled |
---|
22 | add_action( 'admin_notices', 'bulkactiontest_admin_notice' ); |
---|
23 | add_action( 'network_admin_notices', 'bulkactiontest_admin_notice' ); |
---|
24 | } ); |
---|
25 | |
---|
26 | function bulkactiontest_add_bulk_action( $actions ) { |
---|
27 | $actions['tstbkact'] = 'Test Bulk Action'; |
---|
28 | |
---|
29 | return $actions; |
---|
30 | } |
---|
31 | |
---|
32 | function bulkactiontest_handle_bulk_action( $sendback, $action = false, $items = false, $site_id = false ) { |
---|
33 | if ( $action === 'tstbkact' ) { |
---|
34 | $sendback = add_query_arg( 'tstbkact', count( $items ), $sendback ); |
---|
35 | |
---|
36 | return $sendback; |
---|
37 | } |
---|
38 | |
---|
39 | return $sendback; |
---|
40 | } |
---|
41 | |
---|
42 | function bulkactiontest_admin_notice() { |
---|
43 | $current_screen = get_current_screen(); |
---|
44 | |
---|
45 | if ( isset( $_REQUEST['tstbkact'] ) ) { |
---|
46 | printf( '<div id="message" class="updated fade"><p>Test bulk action caught for %s items on %s!</p></div>', $_REQUEST['tstbkact'], $current_screen->id ); |
---|
47 | } |
---|
48 | } |
---|