'How to add a bulk action to the admin order list when another filter is already being added?

I would like to write some orderdata to a custom database using a bulk action. Now I know how to write to a database but I can't seem to get the bulk action to work. I wrote the following:

<?php    
add_filter( 'bulk_actions-edit-shop_order', 'doa_bulk_actions_collect_products', 20, 1 );
function doa_bulk_actions_collect_products( $actions ) {
    $actions['doa-collect-orders'] = __( 'Verzamel producten', 'woocommerce' );
    return $actions;
}

add_filter( 'handle_bulk_actions-edit-shop_order', 'doa_handle_bulk_action_collect_products', 10, 3 );
function doa_handle_bulk_action_collect_products( $redirect_to, $action, $post_ids ) {
    if ( $action !== 'doa-collect-orders' ) {
        return $redirect_to;
    }
    //write to database
    return $redirect_to = add_query_arg( array( 'doa_collect_orders' => 'thisisatest' ), $redirect_to );

}
?>

According to my knowledge this should work fine. But when I use the action I get a white page. On the following URL:

wp-admin/edit.php?s=&post_status=all&post_type=shop_order&_wpnonce=cb753a3863&_wp_http_referer=%2Fwp-admin%2Fedit.php%3Fpost_type%3Dshop_order&action=doa-collect-orders&m=0&deliveryDate=&_customer_user=&paged=1&post%5B%5D=204576&action2=doa-collect-orders

Now after some more testing, I found out that another plugin is using this same filter but somehow that is messing up.

Now this plugin is build in a different programming style:

class WCDN_Writepanel {

    /**
     * Constructor
     */
    public function __construct() {
        // Load the hooks.
        add_action( 'admin_init', array( $this, 'load_admin_hooks' ) );
    }

    /**
     * Load the admin hooks
     */
    public function load_admin_hooks() {
        // Removing the following hook will make my code work:
        add_filter( 'handle_bulk_actions-edit-shop_order', array( $this, 'my_bulk_action_handler' ), 10, 3 );
    }
}

Now for some reason this is already enough to break everything. Even after removing everything from the filter I still get a white screen. Only removing the actual add_filter will make my code work. What is going on?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source