guard(); // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verified in guard() via check_admin_referer(). $key = isset($_POST['provision_key']) ? sanitize_text_field(wp_unslash($_POST['provision_key'])) : ''; // API base is fixed to ADVERSHIPS_AFF_DEFAULT_API (overridable only via a // wp-config constant for staging) — not a merchant-facing field. $result = Adverships_Affiliate_Client::connect($key); if (is_wp_error($result)) { $this->redirect_with('error', $result->get_error_message()); return; } $isNew = !empty($result['is_new']); $msg = $isNew ? __('Connected to Adverships. Your store is now linked.', 'adverships-affiliate') : __('Reconnected to Adverships (connection refreshed).', 'adverships-affiliate'); $this->redirect_with('success', $msg); } /** POST handler: clear local connection state. */ public function handle_disconnect() { $this->guard(); Adverships_Affiliate_Client::disconnect(); $this->redirect_with('success', __('Disconnected from Adverships.', 'adverships-affiliate')); } /** POST handler: save the sales-alerts toggle + notification email. */ public function handle_save_alerts() { $this->guard(); // Nonce is verified in guard() (check_admin_referer) before we reach here. // phpcs:disable WordPress.Security.NonceVerification.Missing $enabled = !empty($_POST['alerts_enabled']); $emailIn = isset($_POST['alerts_email']) ? sanitize_email(wp_unslash($_POST['alerts_email'])) : ''; $rawIn = isset($_POST['alerts_email']) ? sanitize_text_field(wp_unslash($_POST['alerts_email'])) : ''; // phpcs:enable WordPress.Security.NonceVerification.Missing // A non-empty entry that isn't a valid address is a user error. if ($rawIn !== '' && !is_email($emailIn)) { $this->redirect_with('error', __('Enter a valid notification email, or leave it blank to use the site admin email.', 'adverships-affiliate')); return; } Adverships_Affiliate_Client::update_settings(array( 'alerts_enabled' => $enabled, 'alerts_email' => $rawIn === '' ? '' : $emailIn, )); // Arm/disarm the poll immediately rather than waiting for the next load. if (class_exists('Adverships_Affiliate_Alerts')) { ( new Adverships_Affiliate_Alerts() )->sync_schedule(); } $this->redirect_with('success', __('Alert settings saved.', 'adverships-affiliate')); } /** Render the settings page. */ public function render() { if (!current_user_can($this->cap())) { wp_die(esc_html__('You do not have permission to access this page.', 'adverships-affiliate')); } $s = Adverships_Affiliate_Client::settings(); $connected = Adverships_Affiliate_Client::is_connected(); $notice = ''; // Read-only display of our own redirect status message; no state change → nonce not applicable. // phpcs:disable WordPress.Security.NonceVerification.Recommended if (isset($_GET['av_status'], $_GET['av_msg'])) { $type = sanitize_text_field(wp_unslash($_GET['av_status'])) === 'success' ? 'success' : 'error'; $text = sanitize_text_field(wp_unslash($_GET['av_msg'])); $notice = '
' . esc_html($text) . '
Privacy Policy and Terms.', 'adverships-affiliate'), array('a' => array('href' => array(), 'target' => array(), 'rel' => array()))), esc_url(ADVERSHIPS_AFF_DEFAULT_API . '/privacy'), esc_url(ADVERSHIPS_AFF_DEFAULT_API . '/terms') ); ?>