WordPress 6.5 It is now possible to make dependencies between plugins.
WordPress' extensibility is one of its most useful features, and it accomplishes this through plugins and the Hooks API. Many plugins are built on top of other plugins to extend their functionality. The purpose of the plugin dependency feature is to make the process of installing and activating extended plugins and the plugins they depend on consistent and easy.
New plug-in header
A new header "Requires Plugins" is now introduced. This header must contain a comma-separated WordPress.org formatted list of plugin aliases that list other plugins that the plugin depends on. For example, the format should look like this: my-plugin, another-plugin. note that the list of aliases cannot contain the path to the plugin's main file, only the plugin's alias.
How to use the new header
Simply add a new item in the plugin's header with the name "Requires Plugins".
![Image [1] - WordPress 6.5 now supports plugin dependencies, which makes it easier for developers to manage relationships between plugins. -Photonflux.com | Professional WordPress Repair Service, Worldwide, Fast Response](https://www.361sale.com/wp-content/uploads/2024/03/1710928604367-1024x177.png)
request
with regards toDependency plug-ins, with the following requirements:
- Before installing the plugin, its dependencies must be installed.
- Before activating a plugin, its dependencies must be activated.
Dependent Plugins
For dependent plugins, there are the following requirements:
- It is not possible to deactivate dependent plugins when their dependencies are activated.
- After installing its dependencies, it is not possible to remove the dependent plugins.
What happens if dependency is no longer met?
If you remove a dependent plugin via FTP or other means, the WordPress admin page will display a notification reminding you that you need to install and/or activate the associated dependency. Additionally, an error notification will be displayed on the plugin row of each dependency, alerting you that a plugin is not functioning properly because its dependencies have been removed.
What happens if a plugin update has new dependencies?
For now, you can continue to update plugins even if they have dependencies, and those dependencies will remain active. When you operate on the Manage Plugins page, you will receive a notification reminding you that you need to install and/or activate the relevant dependencies.
What happens if there is a circular dependency?
A circular dependency is a loop formed between two or more plugins that depend on each other, resulting in an unclear requirement relationship between the plugins.
As an example: plugin A needs plugin B, plugin B needs plugin C, and plugin C needs plugin A.
The Plugin Dependencies feature includes the detection of circular dependencies and will display a notification to the user alerting them that there are unmet needs between plugins. This means that these plugins cannot be activated. Users should contact the plugin authors to have them resolve these circular references if necessary.
Is defensive coding still needed?
YES. The plugin dependency feature makes it easier for users to install and activate the plugins they need and alerts them when they are missing. This means that plugin authors can safely remove the checking and notification features when users do not install or activate the plugins they need.
However, currently, the plugin dependency feature does not include minimum or maximum version support for dependent plugins, nor does it take into account the order in which plugins are loaded. Therefore, plugin authors should continue to use the function|class|interface_exists() and version checking to ensure that their plugins are working properly when specific functionality is available, even if they depend on plugins that may not be available at load time.
Do plugin dependencies affect WP-CLI?
The Plugin Dependencies feature does not prevent the installation of dependent plugins without dependencies via WP-CLI, as we assume that users using WP-CLI are advanced users who understand plugin dependencies. However, to avoid dependencies being lost and ignored, WP-CLI cannot activate dependent plugins until the dependencies are activated.
This may affect the wp plugin activate -all command, which may need to be run multiple times if dependencies appear before its dependencies. We plan to work with the maintainers of WP-CLI to explore ways to alleviate this burden by adjusting the load order of WordPress core, WP-CLI, or both.
limitations
Plugins hosted on WordPress.org
Plugins hosted on WordPress.org can only declare dependencies on plugins that are also hosted on WordPress.org. If your plugin needs to depend on a plugin that is not hosted on WordPress.org, it is recommended that you do not use "Requires Plugins"Marker.
Plugin not hosted on WordPress.org
Dependency plugins that are not hosted on WordPress.org can declare their dependencies, whether those dependencies are hosted on WordPress.org or elsewhere. However, please note that users will not be able to find installation links for third-party dependencies in the UI, which means that users will have to install these dependencies manually.
Plugins must be used as dependencies
Currently, WordPress core does not officially support must-use plugins as dependencies. We will be adding a new plugin to the#60504The issue will continue to be discussed in the report and more information will be released when a decision is made regarding possible future support.
Themes that require plugins
Currently, plugin dependencies do not yet support the plugins required by the theme. Therefore, theme authors should continue to use the checking methods and messaging they already have in place.
New filters
We have introduced a program called wp_plugin_dependencies_slug filter hook, which serves to allow modification of the plugin's dependencies. As an example, if a plugin declaration depends on the my-pluginand there exists an advanced version of the my-pluginThen the advanced version can be filtered by slug parameter, converting it to the my-plugin-pro, so that the plugin can detect new plugin dependencies.
Parameters:
string $slug: Alias.
usage example
![Image [2] - WordPress 6.5 now supports plugin dependencies, which makes it easier for developers to manage relationships between plugins. -Photonflux.com | Professional WordPress Repair Service, Worldwide, Fast Response](https://www.361sale.com/wp-content/uploads/2024/03/1710930173563.png)
Changes to the user interface
Plugins > Installed Plugins
We have made the following changes to the plugin's dependency lines:
- The Dependency Plugin row now contains a list of its required dependencies and provides links to the corresponding plugin pages so that users can install and activate them.
- If the plugin has uninstalled and inactive dependencies, the "Activate" link will be disabled to prevent user error.
- If the plugin's dependent plugins are active, the Disable and Remove links will be disabled to ensure that the dependent plugins remain active.
- For batch operations that depend on plugins, this is now disabled to avoid potentially confusing situations.
ahead
![Image [3] - WordPress 6.5 now supports plugin dependencies, which makes it easier for developers to manage relationships between plugins. -Photonflux.com | Professional WordPress Repair Service, Worldwide, Fast Response](https://www.361sale.com/wp-content/uploads/2024/03/image-69.png)
empress
![Image [4] - WordPress 6.5 now supports plugin dependencies, which makes it easier for developers to manage relationships between plugins. -Photonflux.com | Professional WordPress Repair Service, Worldwide, Fast Response](https://www.361sale.com/wp-content/uploads/2024/03/image-70.png)
Plugins > Add New Plugin
We have made the following changes:
- If the plugin has unmet dependencies, the Install Now and Activate buttons in the Plugin Card and Plugin Information module will be disabled. This prevents the user from attempting to install or activate the plugin until all of its dependencies are met.
- The Dependency Plugin Card now displays a notification listing its dependencies and providing a "More Details" link to the Dependency Information page. Users can use this link to learn more about the dependency and can "Install Now" or "Activate" it directly from that page.
- The Plugin Information module now stays open when the button is clicked, and users can perform module-based plugin installation and activation using AJAX directly from within the module without leaving the current page.
ahead
![Image [5] - WordPress 6.5 now supports plugin dependencies, which makes it easier for developers to manage relationships between plugins. -Photonfluctuation.com | Professional WordPress Repair Service, Worldwide, Fast Response](https://www.361sale.com/wp-content/uploads/2024/03/image-71.png)
empress
![Image [6] - WordPress 6.5 now supports plugin dependencies, which makes it easier for developers to manage relationships between plugins. -Photonflux.com | Professional WordPress Repair Service, Worldwide, Fast Response](https://www.361sale.com/wp-content/uploads/2024/03/image-72.png)
Getting Started
As a result of the unified AJAX approach now used on the Plugins > Add New screen, plugin activation no longer automatically redirects the user to the Plugins > Installed Plugins screen or to the Getting Started page designed by the plugin author. This means that users can install and activate multiple plugins without leaving their current context.
Typically, plugins with a Getting Started experience will include some sort of checking mechanism. For example, if the user installs and activates the plugin via the WP-CLI, the Getting Started experience is triggered when the user enters one of the plugin's setup screens. This implementation is independent of plugin dependencies, and the user can also activate the plugin via the activation link on the Plugins > Installed Plugins screen.
renewedWP_Plugin_Dependenciesresemble
WP_Plugin_Dependencies A new class is introduced.
The following public API methods are available:
- static method
initialize()Initializes the plugin's dependencies by reading the plugin's "Requires Plugins" header and getting the API data that depends on the plugin. Each execution is run only once.
- static method
has_dependents( $plugin_file )Determines if a specific plugin has other plugins that depend on it.
Parameters:
$plugin_file: The path to the plugin file, relative to the plugin directory.
Return Value:
bool: A boolean indicating whether the plugin has other plugins that depend on it.
- static method
has_dependencies( $plugin_file ): Used to determine if a particular plugin has other plugins as its dependencies.
Parameters:
$plugin_file: The path to the plugin file, relative to the plugin directory.
Return Value:
bool: A boolean value indicating whether the plugin has other plugins as its dependencies.
- static method
has_active_dependents( $plugin_file ) mark>: Used to determine if a particular plugin has other plugins activated as its dependencies.
Parameters:
$plugin_file: The path to the plugin file, relative to the plugin directory.
Return Value:
bool: Boolean value indicating whether the plugin has other plugins activated as its dependencies.
- static method
get_dependents( $slug ): Used to get the file paths of other plugins that depend on the specified plugin.
Parameters:
$slug: Dependency slug.
Return Value:
array: An array containing the paths to dependent plugin files relative to the plugin directory.
- static method
get_dependencies( $plugin_file )::- Description: The slugs used to get the dependent plugins required by the specified plugin.
- Parameters:
$plugin_file: The path to the files that depend on the plugin, relative to the plugin directory.
- Return Value:
array: An array of slugs that depend on the plugin.
- static method
get_dependent_filepath( $slug )::- Description: Used to get the file path of the specified dependent plugin.
- Parameters:
$slug: Depends on the slug of the plugin.
- Return Value:
string|false: The file path of the dependent plugin, relative to the plugin directory. Returns false if the plugin has no dependencies.
- static method
get_dependency_filepath( $slug )::- Description: Used to get the file path of the specified dependency relative to the plugin directory.
- Parameters:
$slug: Dependency slug.
- Return Value:
string|false: The file path of the dependency relative to the plugin directory if it is installed, otherwise false.
- static method
has_unmet_dependencies( $plugin_file ) mark>::- Description: Used to determine if the specified plugin has unmet dependencies.
- Parameters:
$plugin_file: The file path of the plugin, relative to the plugin directory.
- Return Value:
bool: Whether the plugin has unmet dependencies.
- static method
has_circular_dependency( $plugin_file ) mark>::- Description: Used to determine if a circular dependency exists for the specified plugin.
- Parameters:
$plugin_file: The file path of the plugin, relative to the plugin directory.
- Return Value:
bool: Whether the plugin has circular dependencies.
- static method
get_dependent_names( $plugin_file )::- Description: Used to get the name of the plugin for which the plugin needs to be specified.
- Parameters:
$plugin_file: The file path of the plugin, relative to the plugin directory.
- Return Value:
array: Dependency name array.
- static method
get_dependency_names( $plugin_file ) mark>::- Description: Used to get the name of the plugin required for the specified plugin.
- Parameters:
$plugin_file: The path to the files that depend on the plugin, relative to the plugin directory.
- Return Value:
array: An array of dependency names.
- static method
get_dependency_data( $slug )::- Description: Used to return API data for the specified dependency.
- Parameters:
$slug: Dependency slug.
- Return Value:
array|false: API data for the dependency on success, otherwise false.
To learn more, visitOfficial LogThe
Link to this article:https://www.361sale.com/en/6125The article is copyrighted and must be reproduced with attribution.






















![Emoji[wozuimei]-Photonflux.com | Professional WordPress repair service, worldwide, rapid response](https://www.361sale.com/wp-content/themes/zibll/img/smilies/wozuimei.gif)
![Emoticon[baoquan] - Photon Wave Network | Professional WordPress Repair Services, Worldwide Coverage, Rapid Response](https://www.361sale.com/wp-content/themes/zibll/img/smilies/baoquan.gif)

No comments