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.

Sorry, this is a noob question. But, I want to follow the best practices.

I read that functions and global variables should be prefixed in plugins.

So, for example, myfunction(), should be lax_myplugin_myfunction(). And a variable, such as $myvar, should be $lax_myplugin_myvar.

Do I need to prefix a variable if it's in a function? For example,

lax_myplugin_myfunction() {

$count = 50;

return $count;

}

Should I prefix $count and make it $lax_myplugin_count? Or I don't have to bother with it as it's in a function. What's the best practice?

Thank you.

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

Functions - yes.

Class methods - no (but prefix the class name).

Variables - inside your functions/methods - no (like in your example); inside template files - yes, because there are lots of global variables exposed by WP in them, and you might get conflicts...

share|improve this answer
    
Thank you for the detailed answer One Trick Pony. Awesome! –  Laxmidi Sep 7 '11 at 21:16
    
In addition to @One Trick Pony's great answer here is a link you may find useful: codex.wordpress.org/User:CharlesClarkson/Global_Variables –  hsatterwhite Sep 8 '11 at 0:02
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.