Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

WordPress has a file called pluggable.php which contains a list of functions you can override in your plugin.

The problem I am facing (I am overriding wp_authenticate) is for each blog in my network I try to activate this plugin, I get:

failure, can't re-declare wp_authenticate which was previously declared in pluggable.php

This somewhat defeats the ease of use, I have to comment the function in the plugin file, activate the plugin, un-comment the function for it to work properly.

What is the correct way to do it?
Can't expect users who download plugin to do all that.

I am using 3.5 + multi-site configuration

share|improve this question
    
have you wrapped the function in if(!function_exists()) as in the example? show us your code. –  Milo Jan 4 '13 at 20:05
    
Why do I need to wrap? I want my function to ALWAYS take precedence. Or, do I have towrap it all the time and plugins are loaded first? –  Itay Moav -Malimovka Jan 4 '13 at 20:15
    
see my answer below. –  Milo Jan 4 '13 at 20:21
add comment

1 Answer 1

up vote 4 down vote accepted

Wrap your function in if( ! function_exists( 'wp_authenticate' ) ) to get rid of the error and successfully activate your plugin:

if( ! function_exists( 'wp_authenticate' ) ){
    function wp_authenticate(){}
}

This is necessary because in the context of activating a plugin, the function does already exist, only after it is activated will your plugin load first and override the original in pluggable.php. Plugins are activated in a sandbox to capture any fatal errors which may prevent activation and successful recovery to a working state.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.