Why do I have to use required parameters?

59 Views Asked by At

Why, when I want to use

add_filter( 'author_link', 'foo', 10, 3 );
function foo ( $link, $author_id, $author_nicename ) {}

Why do I have to use 3 required parameters?

Why can't I do this:

add_filter( 'author_link', 'foo' );
function foo ( $author_id ) {}

It would be nice to get some article(s) about this. Thanks in advance.

PS beginner in WP-dev.^

1

There are 1 best solutions below

0
On BEST ANSWER

It's allowed to do this theoretically, however it's not guaranteed that 2nd and 3rd parameters would be properly delivered to your function. If you need to make sure that first two parameters are correctly passed you should declare this like:

add_filter( 'author_link', 'foo', 10, 2 ); function foo ( $link, $author_id ) {}

You might like to read more about API at http://codex.wordpress.org/Plugin_API