Skip to content

Commit

Permalink
Merge pull request #9010 from google/enhancement/#8307-follow-up
Browse files Browse the repository at this point in the history
  • Loading branch information
aaemnnosttv authored Jul 12, 2024
2 parents ae72724 + 778c18c commit d2e83bd
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions includes/Core/Consent_Mode/REST_Consent_Mode_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
}
}

Expand All @@ -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,
Expand Down

0 comments on commit d2e83bd

Please sign in to comment.