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.

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.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

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.

share|improve this answer
4  
    
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 Jun 6 '13 at 17:07

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.