[wp-hackers] overriding pluggable.php functions

Otto otto at ottodestruct.com
Fri Jan 9 20:55:56 GMT 2009


I think that is a really solid idea. Make an enhancement ticket on
trac about it.

On Fri, Jan 9, 2009 at 2:09 PM, Will Norris <will at willnorris.com> wrote:
> I've been toying around with this thought for a little while, and would like
> hear what others think.  Right now I'm working on an OAuth plugin for
> WordPress.  If we can get it all done in time, it may go into WP 2.8, but
> for the time being I'm just writing it as a plugin.  One of the things I'm
> doing is to override wp_authenticate for XML-RPC requests so that I can do
> OAuth authentication rather than standard username and password.  This much
> is really simple:
>
> if (XMLRPC_REQUEST && !function_exists('wp_authenticate')) {
>    function wp_authenticate($username, $password) { /* My custom function */
> }
> }
>
> My problem is that if the current request is not using OAuth, then I'd like
> to fall back to the standard username/password logic found in pluggable.php.
>  Unfortunately, because pluggable.php works by completely replacing the
> functions, I can't call that version of wp_authenticate.  The only way I
> could fall back to that logic is to completely copy and paste it all into my
> custom wp_authenticate function.  This is of course bad practice, and not
> future-proof.  So I've been thinking about how it would work if
> pluggable.php were instead made up of functions like:
>
> if (!function_exists('wp_authenticate')) {
>    function wp_authenticate($username, $password) {
>        return _wp_authenticate($username, $password) {
>    }
> }
>
> function _wp_authenticate($username, $password) {
>    /* all the normal authentication logic */
> }
>
> So basically, the functions which can be replaced by plugins don't actually
> include any logic whatsoever, they simply call "private" counterparts.  This
> way, I can override wp_authenticate, but can still fall back by calling
> _wp_authenticate myself.  Just to be clear, this has nothing to do with
> OAuth directly... that just happens to be the thing I'm working on right
> now.  I've actually run into this quite regularly for a number of different
> functions in pluggable.php.  If this has already been discussed, just point
> me to that thread so I can get caught up.
>
> Thoughts?
>
> -will
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list