https://github.com/arraypress/wp-register-bulk-actions
Lightweight library for registering custom bulk actions in WordPress admin tables.
https://github.com/arraypress/wp-register-bulk-actions
Last synced: 5 days ago
JSON representation
Lightweight library for registering custom bulk actions in WordPress admin tables.
- Host: GitHub
- URL: https://github.com/arraypress/wp-register-bulk-actions
- Owner: arraypress
- Created: 2025-10-26T21:26:57.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-11-30T20:07:02.000Z (about 2 months ago)
- Last Synced: 2025-12-27T21:09:40.296Z (29 days ago)
- Language: PHP
- Size: 7.81 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# WordPress Register Bulk Actions
Simple library for adding custom bulk actions to WordPress admin tables.
## Installation
```bash
composer require arraypress/wp-register-bulk-actions
```
## Usage
### Posts
```php
register_post_bulk_actions( 'post', [
'mark_featured' => [
'label' => 'Mark as Featured',
'capability' => 'edit_posts',
'callback' => function( $post_ids ) {
foreach ( $post_ids as $post_id ) {
update_post_meta( $post_id, '_featured', true );
}
return [ 'message' => count($post_ids) . ' posts marked as featured' ];
}
]
] );
```
### Users
```php
register_user_bulk_actions( [
'send_welcome' => [
'label' => 'Send Welcome Email',
'capability' => 'edit_users',
'callback' => function( $user_ids ) {
// Send emails...
return [ 'message' => 'Emails sent!' ];
}
]
] );
```
### Taxonomies
```php
register_taxonomy_bulk_actions( 'category', [
'feature_terms' => [
'label' => 'Mark as Featured',
'callback' => function( $term_ids ) {
foreach ( $term_ids as $term_id ) {
update_term_meta( $term_id, '_featured', true );
}
return [ 'message' => 'Done!' ];
}
]
] );
```
### Comments
```php
register_comment_bulk_actions( [
'mark_helpful' => [
'label' => 'Mark as Helpful',
'callback' => function( $comment_ids ) {
foreach ( $comment_ids as $comment_id ) {
update_comment_meta( $comment_id, '_helpful', true );
}
return [ 'message' => 'Marked as helpful' ];
}
]
] );
```
### Media
```php
register_media_bulk_actions( [
'regenerate' => [
'label' => 'Regenerate Thumbnails',
'callback' => function( $attachment_ids ) {
require_once ABSPATH . 'wp-admin/includes/image.php';
foreach ( $attachment_ids as $attachment_id ) {
$file = get_attached_file( $attachment_id );
$meta = wp_generate_attachment_metadata( $attachment_id, $file );
wp_update_attachment_metadata( $attachment_id, $meta );
}
return [ 'message' => 'Thumbnails regenerated' ];
}
]
] );
```
## Options
```php
[
'label' => 'Action Label', // Required - shown in dropdown
'capability' => 'manage_options', // Optional - default: manage_options
'callback' => function( $ids ) { // Required - receives array of IDs
// Do something with $ids
// Return success message
return [ 'message' => 'Done!' ];
// Or return error
return [
'success' => false,
'message' => 'Error occurred'
];
}
]
```
## Multiple Post Types/Taxonomies
```php
register_post_bulk_actions( ['post', 'page', 'product'], [
'my_action' => [ /* ... */ ]
] );
register_taxonomy_bulk_actions( ['category', 'post_tag'], [
'my_action' => [ /* ... */ ]
] );
```
## Features
- ✅ Automatic admin notices
- ✅ Capability checking
- ✅ Success/error handling
- ✅ Works on all admin tables
- ✅ No hooks needed - just call the function
## Requirements
- PHP 7.4+
- WordPress 5.0+
## License
GPL-2.0-or-later