id) {
return;
}
$consent = get_option('adscale__user_creation_consent', 'no');
$has_shop_rest_api= Helper::has_shop_rest_api();
if ('yes' !== $consent || $has_shop_rest_api) {
return; // Setup completed, no notice needed.
}
$url = admin_url('admin.php?page=wc_plugin_adscale_settings&consent_step=1');
echo '
';
}
/**
* Redirect to the consent step after plugin activation if needed.
*/
public static function redirect_after_activation()
{
// Check if user consent is needed
if (get_option('adscale__needs_user_consent', 'no') !== 'yes') {
return;
}
// Clear the flag to avoid repeated redirects
update_option('adscale__needs_user_consent', 'no');
if (isset($_GET['activate-multi'])) {
return; // Skip redirect for multisite activations
}
wp_safe_redirect(admin_url('admin.php?page=wc_plugin_adscale_settings&consent_step=1'));
exit;
}
/**
* Handle the generation of WooCommerce API keys.
*/
public static function handle_generate_wc_keys()
{
if (!self::current_user_can_manage() || !check_admin_referer('adscale_generate_wc_keys')) {
wp_die('Not allowed');
}
$result = ShopKeys::process_shop_access_keys();
if (is_wp_error($result)) {
// Save the error message to a transient and redirect back to settings
set_transient('adscale_last_error', $result->get_error_message(), 30);
wp_safe_redirect(admin_url('admin.php?page=wc_plugin_adscale_settings&auth=failed'));
exit;
}
wp_safe_redirect(admin_url('admin.php?page=wc_plugin_adscale_settings&auth=success'));
exit;
}
/**
* Handle user consent for creating the service user.
*/
public static function handle_user_creation_consent()
{
if (!self::current_user_can_manage() || !check_admin_referer('adscale_user_creation_consent')) {
wp_die('Not allowed');
}
if (empty($_POST['confirm']) || 'yes' !== $_POST['confirm']) {
set_transient(
'adscale_last_error',
__('You must approve the consent checkbox to continue.', 'adscale-ai'),
30
);
wp_safe_redirect(admin_url('admin.php?page=wc_plugin_adscale_settings&consent_step=1'));
exit;
}
// Save user consent
update_option('adscale__user_creation_consent', 'yes');
ShopKeys::process_shop_access_keys();
if (Helper::is_need_redirect_on_activation()) {
update_option('adscale__need_activation_redirect', 1);
}
wp_safe_redirect(admin_url('admin.php?page=wc_plugin_adscale_settings'));
exit;
}
/**
* Render the settings page for user consent.
*/
public static function render_settings_page()
{
if ($msg = get_transient('adscale_last_error')) {
delete_transient('adscale_last_error');
echo '';
}
?>