Advice on naming files for a plugin

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.

Read More

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

Related posts

Leave a Reply

2 comments

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

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