Great!
I had trouble with the anonymous callback function so I replaced it with a do_action()
. My application is to bulk tag a custom post type with wp_set_post_terms( $id, $tag, 'foo-custom-taxonomy', true );
Putting that in an anonymous callback failed in some mysterious way.
I think it is easier and cleaner to change the plugin as follows (version 0.1.1):
Delete line 64: $func["callback"] = $callback;
Delete lines 146 – 159: if (version_compare(PHP_VERSION... else ... }
Add this line after the deleted line 159:
do_action( "seravo_custom_bulk_action_{$action}", $post_ids );
Then in you application, instead of specifying a callback in register_bulk_action(), add an action to your code:
add_action( "seravo_custom_bulk_action_{$action}", 'foo' );
function foo( $post_ids ) {
// whatever you had in your anonymous callback
}
My foo
is actually in class, so array( $this, 'foo' )
. Maybe the class methods in my anonymous callback caused it to fail. Works now. And no PHP version checking is needed.
Hi.
congrats for the great code. Is it possible to make the code work for custom taxonomy? is something to chagne in the stable code of the plugin in order to achieve this?
I had to make a small change to your line 129. The syntax was not working in some of our older sites and we wanted to send class methods as callbacks. This is a fix working for us, in case anyone else needs.
$anon_fns = array();
foreach( $this->actions[$action] as $el) {
if ( is_callable( $el ) ) {
$anon_fns[] = $el;
}
}
]]>