wppaste
WordPress

wp_get_active_and_valid_plugins(): string[]

Since
3.0.0
Source
wp-includes/load.php:1013
Retrieves an array of active and valid plugin files.

Description

While upgrading or installing WordPress, no plugins are returned.

The default directory is wp-content/plugins. To change the default directory manually, define WP_PLUGIN_DIR and WP_PLUGIN_URL in wp-config.php.

Compatibility

WordPress
since 3.0.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Return value

string[]
Array of paths to plugin files relative to the plugins directory.

Performance profile

How much work a call to wp_get_active_and_valid_plugins() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads or writes the filesystem via file_exists().

Scaling
Scales with input

The body loops, so the work grows with how much data it finds.

Instructions
13–50

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 81.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • optionoption read or writeget_option()called directly
  • filesystemfilesystem accessfile_exists()called directly
  • hookthird-party callbacksapply_filters()one call below wp_get_active_and_valid_plugins()
  • cacheobject cachewp_cache_get()one call below wp_get_active_and_valid_plugins()
  • serializeserialisationmaybe_unserialize()one call below wp_get_active_and_valid_plugins()

Further down the call graph this can also reach query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 18 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_active_and_valid_plugins() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!get_option() && empty($active_plugins)13get_option(), get_option()
!get_option() && !empty($active_plugins) && wp_installing()16get_option(), get_option(), wp_installing()
get_option() && !file_exists() && empty($active_plugins)19get_option(), get_option(), file_exists()
get_option() && !file_exists() && !empty($active_plugins) && wp_installing()22get_option(), get_option(), file_exists(), wp_installing()
!get_option() && !empty($active_plugins) && !wp_installing() && !is_multisite() && !wp_is_recovery_mode()26–27get_option(), get_option(), wp_installing(), is_multisite(), wp_is_recovery_mode()
get_option() && file_exists() && empty($active_plugins)29get_option(), get_option(), file_exists(), _deprecated_file(), array_unshift()
!get_option() && !empty($active_plugins) && !wp_installing() && is_multisite() && !wp_is_recovery_mode()29–30get_option(), get_option(), wp_installing(), is_multisite(), wp_get_active_network_plugins(), wp_is_recovery_mode()
!get_option() && !empty($active_plugins) && !wp_installing() && !is_multisite() && wp_is_recovery_mode()30–31get_option(), get_option(), wp_installing(), is_multisite(), wp_is_recovery_mode(), wp_skip_paused_plugins()
get_option() && !file_exists() && !empty($active_plugins) && !wp_installing() && !is_multisite() && !wp_is_recovery_mode()32–33get_option(), get_option(), file_exists(), wp_installing(), is_multisite(), wp_is_recovery_mode()
get_option() && file_exists() && !empty($active_plugins) && wp_installing()32get_option(), get_option(), file_exists(), _deprecated_file(), array_unshift(), wp_installing()
!get_option() && !empty($active_plugins) && !wp_installing() && is_multisite() && wp_is_recovery_mode()33–34get_option(), get_option(), wp_installing(), is_multisite(), wp_get_active_network_plugins(), wp_is_recovery_mode(), wp_skip_paused_plugins()
get_option() && !file_exists() && !empty($active_plugins) && !wp_installing() && is_multisite() && !wp_is_recovery_mode()35–36get_option(), get_option(), file_exists(), wp_installing(), is_multisite(), wp_get_active_network_plugins(), wp_is_recovery_mode()
6 further outcomes, up to 50 instructions
get_option() && !file_exists() && !empty($active_plugins) && !wp_installing() && !is_multisite() && wp_is_recovery_mode()36–37get_option(), get_option(), file_exists(), wp_installing(), is_multisite(), wp_is_recovery_mode(), wp_skip_paused_plugins()
get_option() && !file_exists() && !empty($active_plugins) && !wp_installing() && is_multisite() && wp_is_recovery_mode()39–40get_option(), get_option(), file_exists(), wp_installing(), is_multisite(), wp_get_active_network_plugins(), wp_is_recovery_mode(), wp_skip_paused_plugins()
get_option() && file_exists() && !empty($active_plugins) && !wp_installing() && !is_multisite() && !wp_is_recovery_mode()42–43get_option(), get_option(), file_exists(), _deprecated_file(), array_unshift(), wp_installing(), is_multisite(), wp_is_recovery_mode()
get_option() && file_exists() && !empty($active_plugins) && !wp_installing() && is_multisite() && !wp_is_recovery_mode()45–46get_option(), get_option(), file_exists(), _deprecated_file(), array_unshift(), wp_installing(), is_multisite(), wp_get_active_network_plugins(), wp_is_recovery_mode()
get_option() && file_exists() && !empty($active_plugins) && !wp_installing() && !is_multisite() && wp_is_recovery_mode()46–47get_option(), get_option(), file_exists(), _deprecated_file(), array_unshift(), wp_installing(), is_multisite(), wp_is_recovery_mode(), wp_skip_paused_plugins()
get_option() && file_exists() && !empty($active_plugins) && !wp_installing() && is_multisite() && wp_is_recovery_mode()49–50get_option(), get_option(), file_exists(), _deprecated_file(), array_unshift(), wp_installing(), is_multisite(), wp_get_active_network_plugins(), wp_is_recovery_mode(), wp_skip_paused_plugins()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev8013–49131 fewer instruction than PHP 8.5
8.58113–5013
8.48113–50133 fewer instructions than PHP 8.3
8.38413–5013
8.28413–5013
8.18413–5013
7.48413–5013

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 9

Used by · 2

Source code

function wp_get_active_and_valid_plugins() {	$plugins        = array();	$active_plugins = (array) get_option( 'active_plugins', array() ); 	// Check for hacks file if the option is enabled.	if ( get_option( 'hack_file' ) && file_exists( ABSPATH . 'my-hacks.php' ) ) {		_deprecated_file( 'my-hacks.php', '1.5.0' );		array_unshift( $plugins, ABSPATH . 'my-hacks.php' );	} 	if ( empty( $active_plugins ) || wp_installing() ) {		return $plugins;	} 	$network_plugins = is_multisite() ? wp_get_active_network_plugins() : false; 	foreach ( $active_plugins as $plugin ) {		if ( ! validate_file( $plugin )                     // $plugin must validate as file.			&& str_ends_with( $plugin, '.php' )             // $plugin must end with '.php'.			&& file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist.			// Not already included as a network plugin.			&& ( ! $network_plugins || ! in_array( WP_PLUGIN_DIR . '/' . $plugin, $network_plugins, true ) )		) {			$plugins[] = WP_PLUGIN_DIR . '/' . $plugin;		}	} 	/*	 * Remove plugins from the list of active plugins when we're on an endpoint	 * that should be protected against WSODs and the plugin is paused.	 */	if ( wp_is_recovery_mode() ) {		$plugins = wp_skip_paused_plugins( $plugins );	} 	return $plugins;}

Changelog

Introduced in 3.0.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/load.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.