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.

I notice that in some plugins you can override functions by ...

  1. Creating an uploads folder
  2. Creating a folder with the plugin name
  3. Using the following code

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

Is this standard for all Wordpress plugins or only if they're written in a specific way?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

If the plugin displays content via any function, the code:

if(!function_exists('function_name')) function_name();

... is used for safety.

If your plugin is disabled, and the if (!function_exists('function_name')) is missing, your theme will throw a fatal error.

share|improve this answer
    
ah I see...thanks! –  redconservatory Jul 26 '11 at 14:46
    
This isn't actually correct. The OP is referring to wrapping the function definition in a if( ! function_exists() ) conditional, not the actual function call in the template. –  Chip Bennett Jul 26 '11 at 15:00
1  
Yes, but his wording is not the best. The wrapping is done for theme safety only, and not for overriding WordPress functions. –  Ciprian Popescu Jul 26 '11 at 15:12

These are referred to as pluggable functions, and are intended to be able to be over-ridden, either by Plugins, Themes, or Child Themes.

It is only standard for functions that are intended to be over-ridden - and, generally speaking, the better practice is to add filter hooks to function outputs, rather than making functions pluggable.

share|improve this answer

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.