8

I developed a plugin using the normal convention of naming the main plugin file after the plugin folder (i.e. prefix-someplugin for the folder and prefix-someplugin.php for the file). However, I saw some plugins that use the following structure:

prefix-someplugin
 - plugin-loader.php // This file just loads src/prefix-someplugin.php
 - /src
    - prefix-someplugin.php

Obviously, if they used such structure, it means that it works. The issue is that I'm not sure how it works, hence my question. How does WP know which file to load as the main plugin file? I would have assumed that it looked for a file named after a folder, just adding .php as an extension, but it seems I was wrong.

Does WPjust scan wp-content/plugins for folders, and loads all the files it finds in them, or does it follow a different logic?

Thanks in advance for the answers.

1 Answer 1

9

WordPress detects a file as plugin when there is a plugin header. So you can store multiple plugins in one directory, and they all will be recognized as different plugins.

Each file with at least /* Plugin Name: something */ is a plugin.

The reason is that WordPress scans all PHP files in the main directory of a plugin.

You can use any name for the plugin file. Avoid non-plugin files in the main directory. They just eat runtime. Put all other PHP files into sub-directories.

2
  • 5
  • A-ha! Now I get it. I checked the plugin loader file and it contains the plugin header, which is normally in the main plugin file. It seems that the author simply split the file in two (one with just header + loader and one with plugin code), so that all the plugin stuff is in src and the tests in test. Thanks for the answer. :)
    – Diego
    Commented Jun 6, 2013 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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