Make WordPress Core

Ticket #16031: bulk_action_test.php

File bulk_action_test.php, 1.4 KB (added by Veraxus, 10 years ago)

Sample plugin for testing 16031-4.7.patch (all screens)

Line 
1<?php
2/*
3Plugin Name: Bulk Actions Test
4Plugin URI:
5Description: Tests bulk actions for all screens
6Author: Matt van Andel
7Version: 1.0
8Author URI:
9*/
10
11add_filter( 'pre_option_link_manager_enabled', '__return_true' );
12
13add_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
26function bulkactiontest_add_bulk_action( $actions ) {
27 $actions['tstbkact'] = 'Test Bulk Action';
28
29 return $actions;
30}
31
32function 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
42function 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}