wp_get_active_and_valid_plugins(): string[]
- Since
- 3.0.0
- Source
wp-includes/load.php:984
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
- Scaling
- Scales with input
- Instructions
- 13–50
- Plugin surface
- None
- Called by
- 1
Reads or writes the filesystem via file_exists().
The body loops, so the work grows with how much data it finds.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 81.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- optionoption read or write
get_option()called directly - filesystemfilesystem access
file_exists()called directly - hookthird-party callbacks
apply_filters()one call below wp_get_active_and_valid_plugins() - cacheobject cache
wp_cache_get()one call below wp_get_active_and_valid_plugins() - serializeserialisation
maybe_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.
| When | Instructions | Calls it makes |
|---|---|---|
!get_option() && empty($active_plugins) | 13 | get_option(), get_option() |
!get_option() && !empty($active_plugins) && wp_installing() | 16 | get_option(), get_option(), wp_installing() |
get_option() && !file_exists() && empty($active_plugins) | 19 | get_option(), get_option(), file_exists() |
get_option() && !file_exists() && !empty($active_plugins) && wp_installing() | 22 | get_option(), get_option(), file_exists(), wp_installing() |
!get_option() && !empty($active_plugins) && !wp_installing() && !is_multisite() && !wp_is_recovery_mode() | 26–27 | get_option(), get_option(), wp_installing(), is_multisite(), wp_is_recovery_mode() |
get_option() && file_exists() && empty($active_plugins) | 29 | get_option(), get_option(), file_exists(), _deprecated_file(), array_unshift() |
!get_option() && !empty($active_plugins) && !wp_installing() && is_multisite() && !wp_is_recovery_mode() | 29–30 | get_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–31 | get_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–33 | get_option(), get_option(), file_exists(), wp_installing(), is_multisite(), wp_is_recovery_mode() |
get_option() && file_exists() && !empty($active_plugins) && wp_installing() | 32 | get_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–34 | get_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–36 | get_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–37 | get_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–40 | get_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–43 | get_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–46 | get_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–47 | get_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–50 | get_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 80 | 13–49 | 13 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 81 | 13–50 | 13 | |
| 8.4 | 81 | 13–50 | 13 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 84 | 13–50 | 13 | |
| 8.2 | 84 | 13–50 | 13 | |
| 8.1 | 84 | 13–50 | 13 | |
| 7.4 | 84 | 13–50 | 13 |
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
- get_option()Retrieves an option value based on an option name.
- _deprecated_file()Marks a file as deprecated and inform when it has been used.
- wp_installing()Checks or sets whether WordPress is in "installation" mode.
- is_multisite()Determines whether Multisite is enabled.
- wp_get_active_network_plugins()Returns array of network plugin files to be included in global scope.
- validate_file()Validates a file name and path against an allowed set of rules.
- str_ends_with()Polyfill for `str_ends_with()` function added in PHP 8.0.
- wp_is_recovery_mode()Determines whether WordPress is in Recovery Mode.
- wp_skip_paused_plugins()Filters a given list of plugins, removing any paused plugins from it.
Used by · 1
- WP_REST_Templates_Controller::get_wp_templates_author_text_field()Returns a human readable text for the author of the template.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 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.