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 Know it's not needed if we're using the latest wordpress but I'm just wondering if it's a good practice to always use it or just use new 3.0+ functions without it, and should we use it for commercial themes ?

thanks in advance.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Asking the core

WP currently has ~2.5k functions. So if you'd check for every function existence on runtime, then you'd really slow things down.

What is it for?

When you're looking at wp core or some themes and it's »pluggables«, then you'll see that those are wrapped inside if ( function_exists('fn_nam') ) calls.

The reason to do this is to allow overwriting of functions in plugins, themes or child themes.

So if you want to let people alter stuff, then you'll want to wrap them up, so they don't get used when there's already a (child theme) function replacing it.

Summed up

Don't do this for core functions. Core functions (or some of their arguments) have the call to…

  1. _deprecated_argument($function, $version)
  2. _deprecated_file($file, $version)
  3. _deprecated_function($function, $version)

…for a reason: Save execution time, provide feedback for developers and a smooth running system for users as those won't be outputted if WP_DEBUG isn't set to TRUE.

So: Only do this for functions that you want people be able to replace.

share|improve this answer
    
Great point about checking for function existence on runtime for everything. I can't imagine the performance hit that would come from actually doing function_exists() throughout your theme. –  Brian Feb 20 '13 at 23:29
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.