I get the basic plugin concept.
I’ve read the Codex article on Writing a Plugin
That article talks about the “main plugin file”.
How does WordPress determine “the main plugin file” ?
Q1:
Is it legal / supported to have a plugin that is structured like this:
- pluginname/
- pluginname/mainfile.php
- pluginname/supportingcode-1.php
- pluginname/supportingcode-2.php
- pluginname/Readme.txt
- etc..
?
Q2:
If so, how does wordpress determine which php file is the main plugin file?
I have seen recommendations that say “I structure my code this way“:
- pluginname/
- pluginname/mainfile.php
- pluginname/inc/supportingcode-1.php
- pluginname/inc/supportingcode-2.php
- pluginname/Readme.txt
- etc..
Q3:
Is the use of a subdirectory (like inc/
in the above example) a requirement when the PHP code spans
multiple modules?
Q4:
Is it true that there should be a maximum of ONE php file in the main plugin directory?
Thanks.
It is the file in your plugin that contains the plugin header comment
Yes. Every directory structure (as far as supported by servers) is legal.
See above â
Requirement? No. Nicer to read: yes. Easier to maintain: Also yes.
No. Simply no.
Summed up
The way you’re organizing your files and directories completely is up to you, your personal preferences and nothing else. If you want to make it easier for you to maintain and for other developers to step through your code, then you should use some sort of file/directory organization.
Examples
I personally append
.class.php
as extension, when I got a class in it. I also name my files right exactly like the class. The reason is simple: My “main plugin file” – which is mybootstrap
class, normally cares about loading all the needed stuff.This means my classes and files are named like the following:
settings.class.php
ANDsettings_extended.class.php
my_class_prefix_settings
ANDmy_class_prefix_settings_extended
I also do some basic directory organization, like storing all
js/css/img
files in directories named like this.Some people use (for larger plugin) folders that are named
inc/includes/assets/extensions/lib/etc.
. I’d recommend to use subfolders for large plugins only. If you got additional stuff like widgets, etc., then you could use specific subfolders for them.Last word: No, nothing what you’ve found is true, those (like the stuff I showed you) are only recommendations.