• msteel

    (@msteelnapcocom)


    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;
    	}
    }

    https://www.ads-software.com/plugins/custom-bulk-actions/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter msteel

    (@msteelnapcocom)

    Also, around 141 I had to update to this:

    $callback = $this->actions[$action]['callback'];
    if ( is_array( $callback ) ) {
      if (method_exists( $callback[0], $callback[1] ) ) {
    	call_user_func_array(array($callback[0], $callback[1]), $post_ids);
      }
    } else {
    		$this->actions[$action]['callback']($post_ids);
    }

    Don’t get me wrong, it’s a great plugin, I just needed to expand it a bit.

    Thanks!

    Is there a way to avoid anonymous functions altogether taking into consideration the fact that my hosting company has PHP 5.2.17 and therefore even after applying the tweak suggested I cannot initialize the bulk actions in functions.php.

    Thank You

    Hi bogdan.melinte, you should be able to just use the name of the in place of an anonymous function. Here is “ACTION EXAMPLE 1” without using an anonymous function:

    // ACTION EXAMPLE 1:
    
    function wp6215656_bulk_actions_callback( $post_ids ) {
    	if ( ! is_array( $post_ids ) || ! count( $post_ids ) ) {
    		return false;
    	}
    
    	foreach ( $post_ids as $post_id ) {
    		update_post_meta( $post_id, '_property_status', 'sold' );
    	}
    
    	return true;
    }
    
    $bulk_actions->register_bulk_action( array(
    	'menu_text'    => 'Mark as sold (Myyty)',
    	'admin_notice' => 'Properties marked as sold',
    	'callback'     => wp6215656_bulk_actions_callback,
    ) );

    Please note that the name of the callback function is not quoted and does not have parenthesis.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Tweak to anonymous function as a callback check’ is closed to new replies.