diff --git a/includes/Core/Consent_Mode/REST_Consent_Mode_Controller.php b/includes/Core/Consent_Mode/REST_Consent_Mode_Controller.php index 95041214215..d83e3297aaa 100644 --- a/includes/Core/Consent_Mode/REST_Consent_Mode_Controller.php +++ b/includes/Core/Consent_Mode/REST_Consent_Mode_Controller.php @@ -150,10 +150,10 @@ protected function get_rest_routes() { array( 'methods' => WP_REST_Server::READABLE, 'callback' => function () { - $is_active = function_exists( 'wp_set_consent' ); - $installed = $is_active; - $slug = 'wp-consent-api'; - $plugin = "$slug/$slug.php"; + $is_active = function_exists( 'wp_set_consent' ); + $installed = $is_active; + $plugin_uri = 'https://wordpress.org/plugins/wp-consent-api'; + $plugin = 'wp-consent-api/wp-consent-api.php'; $response = array( 'hasConsentAPI' => $is_active, @@ -163,10 +163,18 @@ protected function get_rest_routes() { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } - foreach ( array_keys( get_plugins() ) as $installed_plugin ) { - if ( $installed_plugin === $plugin ) { - $installed = true; - break; + + $plugins = get_plugins(); + + if ( array_key_exists( $plugin, $plugins ) ) { + $installed = true; + } else { + foreach ( $plugins as $plugin_file => $installed_plugin ) { + if ( $installed_plugin['PluginURI'] === $plugin_uri ) { + $plugin = $plugin_file; + $installed = true; + break; + } } } @@ -175,7 +183,7 @@ protected function get_rest_routes() { return add_query_arg( '_wpnonce', wp_create_nonce( $action ), $action_url ); }; $activate_url = $nonce_url( self_admin_url( 'plugins.php?action=activate&plugin=' . $plugin ), 'activate-plugin_' . $plugin ); - $install_url = $nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=' . $slug ), 'install-plugin_' . $slug ); + $install_url = $nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=wp-consent-api' ), 'install-plugin_wp-consent-api' ); $response['wpConsentPlugin'] = array( 'installed' => $installed,