validate_active_plugins(): WP_Error[]
- Since
- 2.5.0
- Source
wp-admin/includes/plugin.php:1069
Description
Validate all active plugins, deactivates invalid and returns an array of deactivated ones.
Compatibility
- WordPress
- since 2.5.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
WP_Error[]- Array of plugin errors keyed by plugin file name.
Performance profile
How much work a call to validate_active_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–39
- Plugin surface
- None
- Called by
- 0
Reads stored settings via get_option(), cached per request but not free on a cold cache.
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 55.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()one call below validate_active_plugins() - cacheobject cache
wp_cache_get()one call below validate_active_plugins() - serializeserialisation
maybe_unserialize()one call below validate_active_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 · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost validate_active_plugins() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
is_array($plugins) && !is_multisite() | 13–17 | get_option(), is_multisite() |
is_array($plugins) && is_multisite() && !current_user_can() | 17–21 | get_option(), is_multisite(), current_user_can() |
!is_array($plugins) && !is_multisite() | 18–22 | get_option(), update_option(), is_multisite() |
!is_array($plugins) && is_multisite() && !current_user_can() | 22–26 | get_option(), update_option(), is_multisite(), current_user_can() |
is_array($plugins) && is_multisite() && current_user_can() | 30–34 | get_option(), is_multisite(), current_user_can(), get_site_option(), array_keys(), array_merge() |
!is_array($plugins) && is_multisite() && current_user_can() | 35–39 | get_option(), update_option(), is_multisite(), current_user_can(), get_site_option(), array_keys(), array_merge() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 55 instructions, 13–39 executed per call, 7 branches. The work does not change between versions.
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 · 8
- get_option()Retrieves an option value based on an option name.
- update_option()Updates the value of an option that was already added.
- is_multisite()Determines whether Multisite is enabled.
- current_user_can()Returns whether the current user has the specified capability.
- get_site_option()Retrieve an option value for the current network based on name of option.
- validate_plugin()Validates the plugin path.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- deactivate_plugins()Deactivates a single plugin or multiple plugins.
Source code
function validate_active_plugins() { $plugins = get_option( 'active_plugins', array() ); // Validate vartype: array. if ( ! is_array( $plugins ) ) { update_option( 'active_plugins', array() ); $plugins = array(); } if ( is_multisite() && current_user_can( 'manage_network_plugins' ) ) { $network_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); $plugins = array_merge( $plugins, array_keys( $network_plugins ) ); } if ( empty( $plugins ) ) { return array(); } $invalid = array(); // Invalid plugins get deactivated. foreach ( $plugins as $plugin ) { $result = validate_plugin( $plugin ); if ( is_wp_error( $result ) ) { $invalid[ $plugin ] = $result; deactivate_plugins( $plugin, true ); } } return $invalid;}Changelog
Introduced in 2.5.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 7.1.0 tag, from
src/wp-admin/includes/plugin.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.