WP_Plugin_Dependencies

Static class for resolving plugin dependencies declared via the Requires Plugins header.

Source: wp-includes/class-wp-plugin-dependencies.php
Since: 6.5.0

Overview

All methods are static. The class maintains internal state via static properties and must be initialized before use.

Properties

PropertyTypeVisibilityDescription
$pluginsarrayprotected staticCached result of get_plugins()
$plugin_dirnamesarrayprotected staticMap of slug → plugin filepath
$dependenciesarrayprotected staticMap of plugin filepath → dependency slugs
$dependency_slugsarrayprotected staticAll unique dependency slugs
$dependent_slugsarrayprotected staticMap of plugin filepath → dependent slug
$dependency_api_dataarrayprotected staticWordPress.org API data for dependencies
$dependency_filepathsstring[]protected staticMap of dependency slug → installed filepath
$circular_dependencies_pairsarray[]protected staticCircular dependency pairings
$circular_dependencies_slugsstring[]protected staticSlugs involved in circular deps
$initializedboolprotected staticWhether class has been initialized

Public Methods

initialize()

Initializes dependency data by reading plugin headers and fetching API data.

php
public static function initialize(): void

Note: Only runs once; subsequent calls are no-ops.


has_dependents()

Checks if other plugins depend on this plugin.

php
public static function has_dependents( string $plugin_file ): bool
ParameterTypeDescription
$plugin_filestringPlugin filepath relative to plugins directory

Returns: true if other plugins list this as a dependency.


has_dependencies()

Checks if this plugin requires other plugins.

php
public static function has_dependencies( string $plugin_file ): bool
ParameterTypeDescription
$plugin_filestringPlugin filepath relative to plugins directory

Returns: true if plugin has a Requires Plugins header.


has_active_dependents()

Checks if any active plugins depend on this plugin.

php
public static function has_active_dependents( string $plugin_file ): bool
ParameterTypeDescription
$plugin_filestringPlugin filepath relative to plugins directory

Returns: true if at least one active plugin requires this one.

Use Case: Prevent deactivation of plugins that active plugins depend on.


get_dependents()

Gets filepaths of plugins that require a dependency.

php
public static function get_dependents( string $slug ): array
ParameterTypeDescription
$slugstringDependency plugin slug

Returns: Array of dependent plugin filepaths.


get_dependencies()

Gets dependency slugs for a plugin.

php
public static function get_dependencies( string $plugin_file ): array
ParameterTypeDescription
$plugin_filestringPlugin filepath relative to plugins directory

Returns: Array of dependency slugs, or empty array if none.


get_dependent_filepath()

Gets the filepath for a dependent plugin by its slug.

php
public static function get_dependent_filepath( string $slug ): string|false
ParameterTypeDescription
$slugstringDependent plugin slug

Returns: Plugin filepath, or false if not found.


has_unmet_dependencies()

Checks if any required plugins are missing or inactive.

php
public static function has_unmet_dependencies( string $plugin_file ): bool
ParameterTypeDescription
$plugin_filestringPlugin filepath relative to plugins directory

Returns: true if any dependency is not installed or inactive.


has_circular_dependency()

Checks if plugin is involved in a circular dependency.

php
public static function has_circular_dependency( string $plugin_file ): bool
ParameterTypeDescription
$plugin_filestringPlugin filepath relative to plugins directory

Returns: true if plugin has circular dependencies (A→B→A).


get_dependent_names()

Gets human-readable names of plugins that require this one.

php
public static function get_dependent_names( string $plugin_file ): array
ParameterTypeDescription
$plugin_filestringPlugin filepath relative to plugins directory

Returns: Array of dependent plugin names (sorted alphabetically).


get_dependency_names()

Gets human-readable names of required plugins.

php
public static function get_dependency_names( string $plugin_file ): array
ParameterTypeDescription
$plugin_filestringPlugin filepath relative to plugins directory

Returns: Map of dependency slug → name. Falls back to API data, then installed plugin name, then slug.


get_dependency_filepath()

Gets installed filepath for a dependency.

php
public static function get_dependency_filepath( string $slug ): string|false
ParameterTypeDescription
$slugstringDependency plugin slug

Returns: Plugin filepath, or false if not installed.


get_dependency_data()

Gets WordPress.org API data for a dependency.

php
public static function get_dependency_data( string $slug ): array|false
ParameterTypeDescription
$slugstringDependency plugin slug

Returns: API data array (name, short_description, icons, etc.), or false if unavailable.


display_admin_notice_for_unmet_dependencies()

Displays admin warning if dependencies are missing.

php
public static function display_admin_notice_for_unmet_dependencies(): void

Output: Warning notice with link to plugins page (respects multisite).


display_admin_notice_for_circular_dependencies()

Displays admin warning for circular dependencies.

php
public static function display_admin_notice_for_circular_dependencies(): void

Output: Warning notice listing circular dependency pairs.


check_plugin_dependencies_during_ajax()

AJAX handler for post-installation dependency validation.

php
public static function check_plugin_dependencies_during_ajax(): void

AJAX Action: Called after plugin installation.
Nonce: updates
POST Parameter: slug

Response:

KeyTypeDescription
slugstringPlugin slug
pluginNamestringPlugin name
pluginstringPlugin filepath
activateUrlstringActivation URL (if eligible)
messagestringSuccess message
errorCodestringError type
errorMessagestringError description
errorDataarrayInactive dependency names

Protected Methods

get_plugins()

Returns cached plugin data.

php
protected static function get_plugins(): array

Returns: Result of get_plugins().


read_dependencies_from_plugin_headers()

Parses Requires Plugins headers from all plugins.

php
protected static function read_dependencies_from_plugin_headers(): void

Populates: $dependencies, $dependency_slugs, $dependent_slugs


sanitize_dependency_slugs()

Sanitizes comma-separated dependency slugs.

php
protected static function sanitize_dependency_slugs( string $slugs ): array
ParameterTypeDescription
$slugsstringComma-separated slug string

Returns: Array of sanitized slugs.

Validation: Must match WordPress.org slug format (/^[a-z0-9]+(-[a-z0-9]+)*$/).

Filters: Applies wp_plugin_dependencies_slug to each slug.


get_dependency_filepaths()

Builds map of dependency slugs to installed filepaths.

php
protected static function get_dependency_filepaths(): array

Returns: Map of slug → filepath (or false if not installed).


get_dependency_api_data()

Fetches plugin data from WordPress.org API.

php
protected static function get_dependency_api_data(): array|void

Returns: API data array, or void if not in admin context.

Caching:

  • Main data: wp_plugin_dependencies_plugin_data transient (no expiry)
  • Per-slug timeout: wp_plugin_dependencies_plugin_timeout_{$slug} (12 hours)

Context: Only runs on plugins.php or plugin-install.php.


get_plugin_dirnames()

Builds slug → filepath map for all plugins.

php
protected static function get_plugin_dirnames(): array

Returns: Map of slug → plugin filepath.


get_circular_dependencies()

Detects all circular dependency pairs.

php
protected static function get_circular_dependencies(): array[]

Returns: Array of [slug_a, slug_b] pairs.


check_for_circular_dependencies()

Recursive helper for circular dependency detection.

php
protected static function check_for_circular_dependencies( 
    array $dependents, 
    array $dependencies 
): array
ParameterTypeDescription
$dependentsarrayChain of dependent slugs being checked
$dependenciesarrayDependencies to check against

Returns: Array of circular dependency pairs found.


convert_to_slug()

Converts plugin filepath to slug.

php
protected static function convert_to_slug( string $plugin_file ): string
ParameterTypeDescription
$plugin_filestringPlugin filepath

Returns: Plugin slug.

Special Case: hello.phphello-dolly

Logic:

  • With directory: my-plugin/my-plugin.phpmy-plugin
  • Single file: my-plugin.phpmy-plugin