0

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.

1

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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