validate_plugin_requirements( string $plugin ): true|WP_Error
- Since
- 5.2.0, 5.3.0, 5.8.0, 6.5.0
- Source
wp-admin/includes/plugin.php:1139
Description
Uses the information from Requires at least, Requires PHP and Requires Plugins headers defined in the plugin's main PHP file.
Compatibility
- WordPress
- since 6.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.
Parameters
$pluginstring- Path to the plugin file relative to the plugins directory.
Return value
true|WP_Error- True if requirements are met, WP_Error on failure.
Performance profile
How much work a call to validate_plugin_requirements() 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
- 65–124
- Plugin surface
- 1 hook
- Called by
- 1
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 246.
Third-party callbacks on 'validate_plugin_requirements' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - optionoption read or write
get_option()one call below validate_plugin_requirements()
Further down the call graph this can also reach cache, serialize, 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 · 7 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost validate_plugin_requirements() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!::WP_Plugin_Dependencies() | 65–71 | get_plugin_data(), is_wp_version_compatible(), is_php_version_compatible(), __(), wp_get_update_php_url(), esc_url(), sprintf(), wp_get_update_php_annotation(), ::WP_Plugin_Dependencies(), ::WP_Plugin_Dependencies(), apply_filters() |
| always | 72–78 | get_plugin_data(), is_wp_version_compatible(), is_php_version_compatible(), __(), wp_get_update_php_url(), esc_url(), sprintf(), wp_get_update_php_annotation(), _x(), sprintf() |
| always | 75–81 | get_plugin_data(), is_wp_version_compatible(), is_php_version_compatible(), __(), wp_get_update_php_url(), esc_url(), sprintf(), wp_get_update_php_annotation(), _x(), get_bloginfo(), sprintf() |
| always | 78–84 | get_plugin_data(), is_wp_version_compatible(), is_php_version_compatible(), __(), wp_get_update_php_url(), esc_url(), sprintf(), wp_get_update_php_annotation(), _x(), get_bloginfo(), sprintf(), requires() |
::WP_Plugin_Dependencies() && is_multisite() && !current_user_can() | 107–114 | get_plugin_data(), is_wp_version_compatible(), is_php_version_compatible(), __(), wp_get_update_php_url(), esc_url(), sprintf(), wp_get_update_php_annotation(), ::WP_Plugin_Dependencies(), ::WP_Plugin_Dependencies(), ::WP_Plugin_Dependencies(), _n(), wp_get_list_item_separator(), sprintf(), is_multisite(), current_user_can(), __() |
::WP_Plugin_Dependencies() && !is_multisite() | 112–119 | get_plugin_data(), is_wp_version_compatible(), is_php_version_compatible(), __(), wp_get_update_php_url(), esc_url(), sprintf(), wp_get_update_php_annotation(), ::WP_Plugin_Dependencies(), ::WP_Plugin_Dependencies(), ::WP_Plugin_Dependencies(), _n(), wp_get_list_item_separator(), sprintf(), is_multisite(), __(), admin_url(), esc_url(), sprintf() |
::WP_Plugin_Dependencies() && is_multisite() && current_user_can() | 117–124 | get_plugin_data(), is_wp_version_compatible(), is_php_version_compatible(), __(), wp_get_update_php_url(), esc_url(), sprintf(), wp_get_update_php_annotation(), ::WP_Plugin_Dependencies(), ::WP_Plugin_Dependencies(), ::WP_Plugin_Dependencies(), _n(), wp_get_list_item_separator(), sprintf(), is_multisite(), current_user_can(), __(), network_admin_url(), esc_url(), sprintf() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 246 | 65–124 | 15 | |
| 8.5 | 246 | 65–124 | 15 | |
| 8.4 | 246 | 65–124 | 15 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 249 | 65–127 | 15 | |
| 8.2 | 249 | 65–127 | 15 | |
| 8.1 | 249 | 65–127 | 15 | 3 fewer instructions than PHP 7.4 |
| 7.4 | 252 | 65–130 | 15 |
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.
Hooks and filters fired · 1
One hook fires while validate_plugin_requirements() runs, in this order:
- apply_filters( validate_plugin_requirements )filterline 1269 (+130 into the body)
Filters the plugin requirement validation response.
Uses · 22
- get_plugin_data()Parses the plugin contents to retrieve plugin's metadata.
- is_wp_version_compatible()Checks compatibility with the current WordPress version.
- is_php_version_compatible()Checks compatibility with the current PHP version.
- __()Retrieves the translation of $text.
- esc_url()Checks and cleans a URL.
- wp_get_update_php_url()Gets the URL to learn more about updating the PHP version the site is running on.
- wp_get_update_php_annotation()Returns the default annotation for the web hosting altering the "Update PHP" page URL.
- _x()Retrieves translated string with gettext context.
- get_bloginfo()Retrieves information about the current site.
- is_plugin_inactive()Determines whether the plugin is inactive.
- _n()Translates and retrieves the singular or plural form based on the supplied number.
- wp_get_list_item_separator()Retrieves the list item separator based on the locale.
Show all 22
- is_multisite()Determines whether Multisite is enabled.
- current_user_can()Returns whether the current user has the specified capability.
- network_admin_url()Retrieves the URL to the admin area for the network.
- admin_url()Retrieves the URL to the admin area for the current site.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- WP_Error::__construct()Initializes the error.
- WP_Plugin_Dependencies::initialize()Initializes by fetching plugin header and plugin API data.
- WP_Plugin_Dependencies::has_unmet_dependencies()Determines whether the plugin has unmet dependencies.
- WP_Plugin_Dependencies::get_dependency_names()Gets the names of plugins required by the plugin.
- WP_Plugin_Dependencies::get_dependency_filepath()Gets the filepath for a dependency, relative to the plugin's directory.
Used by · 1
- activate_plugin()Attempts activation of plugin in a "sandbox" and redirects on success.
Source code
function validate_plugin_requirements( $plugin ) { $plugin_headers = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); $requirements = array( 'requires' => ! empty( $plugin_headers['RequiresWP'] ) ? $plugin_headers['RequiresWP'] : '', 'requires_php' => ! empty( $plugin_headers['RequiresPHP'] ) ? $plugin_headers['RequiresPHP'] : '', 'requires_plugins' => ! empty( $plugin_headers['RequiresPlugins'] ) ? $plugin_headers['RequiresPlugins'] : '', ); $compatible_wp = is_wp_version_compatible( $requirements['requires'] ); $compatible_php = is_php_version_compatible( $requirements['requires_php'] ); $php_update_message = '</p><p>' . sprintf( /* translators: %s: URL to Update PHP page. */ __( '<a href="%s">Learn more about updating PHP</a>.' ), esc_url( wp_get_update_php_url() ) ); $annotation = wp_get_update_php_annotation(); if ( $annotation ) { $php_update_message .= '</p><p><em>' . $annotation . '</em>'; } if ( ! $compatible_wp && ! $compatible_php ) { return new WP_Error( 'plugin_wp_php_incompatible', '<p>' . sprintf( /* translators: 1: Current WordPress version, 2: Current PHP version, 3: Plugin name, 4: Required WordPress version, 5: Required PHP version. */ _x( '<strong>Error:</strong> Current versions of WordPress (%1$s) and PHP (%2$s) do not meet minimum requirements for %3$s. The plugin requires WordPress %4$s and PHP %5$s.', 'plugin' ), get_bloginfo( 'version' ), PHP_VERSION, $plugin_headers['Name'], $requirements['requires'], $requirements['requires_php'] ) . $php_update_message . '</p>' ); } elseif ( ! $compatible_php ) { return new WP_Error( 'plugin_php_incompatible', '<p>' . sprintf( /* translators: 1: Current PHP version, 2: Plugin name, 3: Required PHP version. */ _x( '<strong>Error:</strong> Current PHP version (%1$s) does not meet minimum requirements for %2$s. The plugin requires PHP %3$s.', 'plugin' ), PHP_VERSION, $plugin_headers['Name'], $requirements['requires_php'] ) . $php_update_message . '</p>' ); } elseif ( ! $compatible_wp ) { return new WP_Error( 'plugin_wp_incompatible', '<p>' . sprintf( /* translators: 1: Current WordPress version, 2: Plugin name, 3: Required WordPress version. */ _x( '<strong>Error:</strong> Current WordPress version (%1$s) does not meet minimum requirements for %2$s. The plugin requires WordPress %3$s.', 'plugin' ), get_bloginfo( 'version' ), $plugin_headers['Name'], $requirements['requires'] ) . '</p>' ); } WP_Plugin_Dependencies::initialize(); if ( WP_Plugin_Dependencies::has_unmet_dependencies( $plugin ) ) { $dependency_names = WP_Plugin_Dependencies::get_dependency_names( $plugin ); $unmet_dependencies = array(); $unmet_dependency_names = array(); foreach ( $dependency_names as $dependency => $dependency_name ) { $dependency_file = WP_Plugin_Dependencies::get_dependency_filepath( $dependency ); if ( false === $dependency_file ) { $unmet_dependencies['not_installed'][ $dependency ] = $dependency_name; $unmet_dependency_names[] = $dependency_name; } elseif ( is_plugin_inactive( $dependency_file ) ) { $unmet_dependencies['inactive'][ $dependency ] = $dependency_name; $unmet_dependency_names[] = $dependency_name; } }Changelog
Introduced in 5.2.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
readme.txt as a fallback.from the docblockreadme.txt as a fallback.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 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.