(Background: I'm trying to automate the setup of some WP blogs by writing directly to the active_plugins row in wp_options, and I'm having an issue in determining the primary PHP file for some plugins.)

The main PHP file for most plugins is simply the name of the stub, with .php appended; for example, plugin-name/plugin-name.php.

However that's not the case for all plugins. WP Super Cache for example has the following structure:

├── Changelog.txt
├── advanced-cache.php
├── languages
├── ossdl-cdn.php
├── plugins
├── readme.txt
├── wp-cache-base.php
├── wp-cache-config-sample.php
├── wp-cache-phase1.php
├── wp-cache-phase2.php
├── wp-cache.php
└── wp-super-cache.pot

If you go look in the Plugin admin panel, this plugin can be activated with the following link:


/* Note how WP has determined: plugin=wp-super-cache/wp-cache.php */

My question is, how does WP determine which PHP file in a plugin directory is the main PHP file?

Or in other words, if I wanted to manually update the active_plugins option_value in the wp_options table, how would I know what PHP file to reference?

I've tried to figure this out by digging through the code, but it's very convoluted and I'm getting lost. I thought WP might look at the first X lines of every file to find the one with the banner info (Author, Plugin Name etc...) but that seems very awkward.

1 Answer 1


There is no "main" file to a plugin. Every file that has the plugin header is a plugin and the rest are not. Convention is that there is only one file with the header in a directory, but I saw "plugins" that had more than one such file in a directory, and they appeared as multiple plugins in the admin, but that was long time ago, don't think anybody does it now.

  • What I'm trying to understand then is how WP determines the PHP file that it will pass by the plugin GET parameter when you activate a plugin from the admin panel (see second code snippet in my post). You can hover over the Activate link in the Plugin panel to see it on your WP setup. This is the same PHP file that gets inserted into the active_plugins option in the wp_options DB table... I'm just calling it "Primary" for lack of better term.
    – Juicy
    Commented Jan 10, 2017 at 18:56
  • 1
    on the plugin admin page it scans all the subdirectories under the plugins directory and reads the header info.from the php files. the get_plugins function does it developer.wordpress.org/reference/functions/get_plugins Commented Jan 10, 2017 at 19:43
  • I always set only one plugin file with the header.
    – prosti
    Commented Jan 16, 2017 at 19:51
  • To look for the actual plugin files in a particular plugin folder, the get_plugins() function needs the name of the folder starting with /. So, for example, to get the actual plugin filename and info for "Akismet Anti-Spam", call get_plugins("/akismet"). The leading "/" is counterintuitive!
    – Martin_W
    Commented Aug 28, 2019 at 0:09

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.