[wp-hackers] overriding pluggable.php functions
Will Norris
will at willnorris.com
Sat Jan 10 10:36:20 GMT 2009
On Jan 10, 2009, at 1:22 AM, Ryan McCue wrote:
> Will Norris wrote:
>> if (!function_exists('wp_authenticate')) {
>> function wp_authenticate($username, $password) {
>> return apply_filters('authenticate', null, $username, password);
>> }
>> }
>
> Instead of calling apply_filters() with a null value to filter, call
> do_action() instead, as that's what it's built for.
Actions are just for firing off events at a particular point in the
code. The different functions which implement the same action hook do
not interact with each other at all, nor do they return any values.
Filters on the other hand, are specifically for taking a value, and
passing it through the multiple filters, with the expectation that a
final (perhaps modified) value will be returned at the end. The
functions which implement the same filter hook are each passed the
newly updated value in turn, and have the opportunity to modify the
value further before passing it on to the next function.
in the case of wp_authenticate(), it is expected to return either null
or an WP_User object. We begin by passing in null. If any of the
filter implementations are able to authenticate the user by whatever
means, all they need to do is return a new WP_User object. Otherwise,
they just return what they were originally passed in. If no filter
function is able to authenticate the user, then null ends up being
returned.
If we were to use do_action(), nothing would ever be returned by
wp_authenticate.
-will
More information about the wp-hackers
mailing list