2

(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:

wp-super-cache
├── 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:

'http://localhost/testing/wp-admin/plugins.php?action=activate&plugin=wp-super-cache%2Fwp-cache.php&plugin_status=all&paged=1&s&_wpnonce=cbc0e620a3'

/* 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.

6

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 Jan 10 '17 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 – Mark Kaplun Jan 10 '17 at 19:43
  • I always set only one plugin file with the header. – prosti Jan 16 '17 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_ATS Aug 28 at 0:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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