WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] do_action issue with parameters handling (2 posts)

  1. Zatsugami
    Member
    Posted 2 years ago #

    Ok, so I wanted to hook up to an action post_updated.

    /* Line 2654 wp-includes/post.php /*
    do_action( 'post_updated', $post_ID, $post_after, $post_before);

    As you can see, there are 3 parameters. But when you look at do_action definition in wp-inludes/plugin.php you can notice.

    /* Line 386 */
    $args = array();
    	if ( is_array($arg) && 1 == count($arg) && isset($arg[0]) && is_object($arg[0]) ) // array(&$this)
    		$args[] =& $arg[0];
    	else
    		$args[] = $arg;
    	for ( $a = 2; $a < func_num_args(); $a++ )
    		$args[] = func_get_arg($a);

    Notice the for loop with $a set to 2. It means, that this will omit next 2 parameters.
    Is this made on purpose?

  2. Zatsugami
    Member
    Posted 2 years ago #

    Looks like there just need to be a 4rd parameter in add_action(name, function, order, number_of_accepted_params).

Topic Closed

This topic has been closed to new replies.

About this Topic