Use wp_plugin_dependencies_slug in PluginVersionRuleProcessor (#47235)

* Use wp_plugin_dependencies_slug

* Fix incorrect function name

* Remove unnessary content-type header

* Add doc block for wp_plugin_dependencies_slug filter

* Add changefile(s) from automation for the following project(s): woocommerce-beta-tester, woocommerce

* Tmp fix - fix broken test

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Moon 2024-05-10 10:30:12 +12:00 committed by GitHub
parent 576db0933c
commit 7360928502
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 21 additions and 4 deletions

View File

@ -0,0 +1,4 @@
Significance: patch
Type: update
Applies `wp_plugin_dependencies_slug` filter to get the correct plugin name in PluginVersionRuleProcessor.

View File

@ -14,7 +14,6 @@ export function* validate( jsonString ) {
const response = yield apiFetch( {
method: 'POST',
path: `${ API_NAMESPACE }/remote-spec-validator/validate`,
headers: { 'content-type': 'application/json' },
data: {
spec: JSON.stringify( JSON.parse( jsonString ) ),
},

View File

@ -0,0 +1,4 @@
Significance: patch
Type: update
Applies `wp_plugin_dependencies_slug` filter to get the correct plugin name in PluginVersionRuleProcessor.

View File

@ -45,12 +45,20 @@ class PluginVersionRuleProcessor implements RuleProcessorInterface {
*/
public function process( $rule, $stored_state ) {
$active_plugin_slugs = $this->plugins_provider->get_active_plugin_slugs();
/**
* Filters a plugin dependencys slug before matching to the WordPress.org slug format.
*
* @since 9.0.0
*
* @param string $plugin_name requested plugin name
*/
$plugin_name = apply_filters( 'wp_plugin_dependencies_slug', $rule->plugin );
if ( ! in_array( $rule->plugin, $active_plugin_slugs, true ) ) {
if ( ! in_array( $plugin_name, $active_plugin_slugs, true ) ) {
return false;
}
$plugin_data = $this->plugins_provider->get_plugin_data( $rule->plugin );
$plugin_data = $this->plugins_provider->get_plugin_data( $plugin_name );
if ( ! is_array( $plugin_data ) || ! array_key_exists( 'Version', $plugin_data ) ) {
return false;

View File

@ -116,7 +116,9 @@ class WC_Admin_Tests_API_Plugins extends WC_REST_Unit_Test_Case {
*/
public function test_activate_plugin() {
wp_set_current_user( $this->user );
if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
activate_plugin( 'woocommerce/woocommerce.php' );
}
$request = new WP_REST_Request( 'POST', $this->endpoint . '/activate' );
$request->set_query_params(
array(