[wp-hackers] overriding pluggable.php functions
Dougal Campbell
dougal at gunters.org
Sat Jan 10 03:12:25 GMT 2009
Will Norris wrote:
> [...] 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. [...]
*headslap, because I didn't think of it myself*
+1 on this idea.
Sometime back, I had run into a a similar problem, wanting to override a
pluggable function, but still be able to fall back to the original code.
Of course, I went with the quick-and-dirty solution of just copying the
original function. But I knew it was an ugly solution, because it wasn't
future-proof.
This is the kind of elegant solution that's needed. It's basically the
procedural programming equivalent of being able to call a super() method
in OOP. :)
--
Dougal Campbell <dougal at gunters.org <mailto:dougal at gunters.org>>
http://dougal.gunters.org/
http://twitter.com/dougal
More information about the wp-hackers
mailing list