admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('bd_bookshelf_gdpr_nonce'), 'cookieDays' => 30, ]); } /** * Render consent banner */ public function render_consent_banner() { if (is_admin()) { return; } if ($this->has_consent()) { return; } $privacy_page_url = $this->get_privacy_page_url(); $privacy_text = get_option('bd_bookshelf_gdpr_text', 'We use cookies for affiliate tracking only. By clicking "Accept", you agree to our use of cookies as described in our Privacy Policy.' ); echo '
'; echo '
'; echo '

' . wp_kses_post($privacy_text) . '

'; echo ''; echo '
'; echo '
'; } /** * Check if user has given consent */ public static function has_consent() { if (isset($_COOKIE['bd_bookshelf_consent'])) { return true; } return false; } /** * AJAX handler for accepting consent */ public function ajax_accept_consent() { check_ajax_referer('bd_bookshelf_gdpr_nonce', 'nonce'); // Set consent cookie (30 days) setcookie('bd_bookshelf_consent', '1', time() + (30 * DAY_IN_SECONDS), '/'); wp_send_json_success(['message' => 'Consent accepted']); } /** * Get privacy page URL */ private function get_privacy_page_url() { $privacy_page_id = get_option('wp_page_for_privacy_policy'); if ($privacy_page_id) { return get_permalink($privacy_page_id); } return '#'; } /** * Get GDPR consent banner text */ public static function get_consent_text() { return get_option('bd_bookshelf_gdpr_text', ''); } /** * Update GDPR consent banner text */ public static function update_consent_text($text) { update_option('bd_bookshelf_gdpr_text', sanitize_text_field($text)); } }