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.

Plugin is defining pluggable wp_mail() function. My idea was to check if function is defined already and throw warning if other plugin beat me to it.

However this warning causes issues on activation. As far as I understand during normal operation plugin is loaded before pluggable.php but for the purpose of activation check it is loaded after pluggables.

What would be the robust/proper/suggested way to implement such check for pluggable function? There is no obvious (for me) way to distinguish activation and handle it separately.

share|improve this question
    
isn't "function_exists()" good enough ? –  Bainternet Mar 9 '11 at 13:21
    
@Bainternet on activation pluggables.php had already been processed and wp_mail() always exists. –  Rarst Mar 9 '11 at 13:33
    
@Rarst then i guess I'm missing the point here. –  Bainternet Mar 9 '11 at 13:35
    
@Bainternet the point is that load order is different on activation and I don't see a robust way to handle that. I cannot implement check for environment I need if environment is not the same because of different load order. –  Rarst Mar 9 '11 at 13:49
    
@Rarst thanks for explaining, then in that case i have no idea. –  Bainternet Mar 9 '11 at 13:55
show 3 more comments

1 Answer

up vote 0 down vote accepted

Don't do the check on activation?

Seriously, the best way I can think of is not to check for this on activation, but only in the normal plugin load process. And instead of throwing a warning (I assume you mean a PHP E_WARNING), perhaps putting an admin error box up would make more sense.

share|improve this answer
    
Still same sub-question - how do I know it is activation? The idea to check for plugins_loaded fired might work, but had not tested yet. Warning was more of a debug thing. Overall I no longer think this makes much sense to mess with in my case, but still interested in technical side. –  Rarst Mar 17 '11 at 12:45
    
A plugin should never really do anything just by being included. Everything should be put in a function that is hooked somewhere. plugins_loaded isn't run on the activation include, so any actual checks you want to do at "load" time should be hooked there. –  Otto Mar 18 '11 at 15:44
    
please see context - plugins_loaded fires after loading pluggable stuff. It is useless for check if specific pluggable function is available and useless for defining such function. I don't see another way of timing defining pluggable function other than on include. –  Rarst Mar 18 '11 at 17:29
1  
You can do checks on include, sure, but you need to defer taking actions on the results of those checks until at least plugins_loaded. In other words, you can check for a function's existence at include time, but you need to wait until at least plugins_loaded before doing anything like throwing up a warning or something. –  Otto Mar 19 '11 at 19:54
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.