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.

Based on some advice I read[1], I have meticulously named all my plugin php files with my adopted plugin prefix, being 'wpsm-' in this case. All my class files have the additional 'class' qualifier, making their prefix 'wpsm-class-'.

Now, while doing some early morning housekeeping, trying to get zoned into serious coding, I realised that as long as all my php files stay in my plugin's folder, there is no reason to prefix them all, and removing the prefix actually improves readability. Further, if I place all my class files in a 'code' or 'class' folder, I don't need the additional 'class' prefix.

What do readers of this question suggest for my naming conventions, in the context I describe above?

[1] Professional WordPress Plugin Development:

"When building a custom plugin, it’s essential that you prefix everything with a unique prefix. This means all plugins files, function names, variable names, and everything included with your plugin."

share|improve this question

2 Answers 2

up vote 1 down vote accepted

There's certainly no need to name plugin files with prefixes (although some plugin authors like to do this). I suspect the advice you read was referring to functions within your plugin files. Structuring you plugin folders as you suggest (using a class folder) is fine.

See this link for more information on writing plugins:

http://codex.wordpress.org/Writing_a_Plugin

Specifically the section "Plugin Development Suggestions" towards the end where it says:

All the functions in your Plugin need to have unique names that are different from functions in the WordPress core, other Plugins, and themes. For that reason, it is a good idea to use a unique function name prefix on all of your Plugin's functions. A far superior possibility is to define your Plugin functions inside a class (which also needs to have a unique name).

share|improve this answer
    
The advice I read specifically stated to prefix "everything". I have amended my question to quote the source. –  ProfK Nov 27 '11 at 19:50

As for the plugin-name prefix I couldn't agree more. If all files are kept within the plugin's folder (and why wouldn't they?), I see no reason whatsoever to prefix every single file with the plugin name. As you pointed out, it actually worsens readability and that is the only effect it has in my opinion. The files are uniquely identifiable by the folder they are in. I omit this prefix in my plugin files.

When it comes to the class- prefix, the situation is not as clear. Again, I see your reasoning behind it possibly being superfluous, but personally I use it in for my OOP plugin files for two reasons: For one, I like to name plugin subfolders by the role that the files they contain play in the plugin, i.e. my plugin subfolders are usually named /includes, /modules, /admin and the like. Now there might be classes relevant to the back end, those go into /admin. Classes indispensable to the plugin into /includes and classes for components the user may or may not choose to use into /modules. All those folders may also contain files that are not object oriented. The second reason being that this prefix is recommended by the Naming Conventions of the Wordpress Coding Standard.

Should your plugin ever have to be maintained by someone other that you, the class- prefix makes sense.

As an aside, the standard also recommends hyphens for file names, not underscores.

share|improve this answer
    
Yeah, I've often wondered why they recommend hyphens instead of underscores for file names. –  Tom Auger Apr 5 '13 at 16:09

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.