__('GDPR', 'cookieadmin'), 'cookieadmin_us' => __('US State Laws', 'cookieadmin'), ]); echo '
'; // .cookieadmin-geo-page \CookieAdmin\Admin::footer_theme(); } static function render_card_form($countries, $laws){ $law_options = ''; foreach($laws as $key => $label){ $law_options .= ''; } $country_options = ''; foreach($countries['countries'] as $code => $name){ $country_options .= ''; } echo ' '; } static function render_rules_table($rules, $countries, $laws){ if(empty($rules)){ return; } $shortcuts = $countries['continents']; $shortcut_labels = [ 'eu' => __('EU', 'cookieadmin'), 'eea' => __('EEA', 'cookieadmin'), 'africa' => __('Africa', 'cookieadmin'), 'asia' => __('Asia', 'cookieadmin'), 'europe' => __('Europe', 'cookieadmin'), 'north_america' => __('North America', 'cookieadmin'), 'south_america' => __('South America', 'cookieadmin'), 'oceania' => __('Oceania', 'cookieadmin'), 'antarctica' => __('Antarctica', 'cookieadmin'), 'caribbean' => __('Caribbean', 'cookieadmin'), 'asean' => __('ASEAN', 'cookieadmin'), 'worldwide' => __('Worldwide', 'cookieadmin'), ]; echo ''; } static function render_toggle_html($suffix, $field, $value){ $inherit_active = ($value === 'inherit') ? ' cookieadmin-geo-toggle-active' : ''; $on_active = ($value === 'on') ? ' cookieadmin-geo-toggle-active' : ''; $off_active = ($value === 'off') ? ' cookieadmin-geo-toggle-active' : ''; return ''; } static function render_badge($value){ $class = ''; $label = ''; switch($value){ case 'inherit': $class = 'cookieadmin-info'; $label = __('Inherit', 'cookieadmin'); break; case 'on': $class = 'cookieadmin-success'; $label = __('On', 'cookieadmin'); break; case 'off': $class = 'cookieadmin-danger'; $label = __('Off', 'cookieadmin'); break; default: $class = 'cookieadmin-info'; $label = __('Inherit', 'cookieadmin'); } return ''; } // Deleting the rule based on ID static function delete_rule($id){ $rules = get_option('cookieadmin_geo_rules', []); if(empty($rules)){ wp_send_json_error(['message' => __('There is no rule added to delete from', 'cookieadmin')]); } if(empty($rules[$id])){ wp_send_json_error(['message' => __('Request rule ID is not present, can not delete', 'cookieadmin')]); } unset($rules[$id]); update_option('cookieadmin_geo_rules', $rules); wp_send_json_success(['message' => __('Rule Deleted successfully', 'cookieadmin'), 'rules' => $rules]); } static function save_geo_settings(){ check_ajax_referer('cookieadmin_pro_admin_js_nonce', 'cookieadmin_pro_security'); if(!current_user_can('administrator')){ wp_send_json_error(['message' => __('Sorry, but you do not have permissions to perform this action', 'cookieadmin')]); } if(empty($_REQUEST['rule'])){ // If we need to delete the rule? if(!empty($_REQUEST['delete_id'])){ $delete_id = sanitize_key(wp_unslash($_REQUEST['delete_id'])); self::delete_rule($delete_id); } wp_send_json_error(['message' => __('Request came empty', 'cookieadmin')]); } $rule_json = !empty($_REQUEST['rule']) ? wp_unslash($_REQUEST['rule']) : ''; $rule = json_decode($rule_json, true); if(empty($rule) || !is_array($rule)){ wp_send_json_error(['message' => __('Invalid rules data', 'cookieadmin')]); } $rule = map_deep($rule, 'sanitize_text_field'); $sanitized_rules = []; $locations = include(COOKIEADMIN_PRO_DIR . 'lib/locations.php'); $valid_countries = $locations['countries']; $valid_shortcuts = $locations['continents']; $valid_laws = apply_filters('cookieadmin_geo_law_options', [ 'cookieadmin_gdpr' => 'GDPR', 'cookieadmin_us' => 'US State Laws', ]); if(empty($rule['name'])){ wp_send_json_error(['message' => __('Enter a valid rule name', 'cookieadmin')]); } if(!empty($rule['law']) && !isset($valid_laws[$rule['law']])){ wp_send_json_error(['message' => __('Please select a valid law type', 'cookieadmin')]); } $countries = []; if(!empty($rule['countries']) && is_array($rule['countries'])){ foreach($rule['countries'] as $country_code){ if(isset($valid_countries[$country_code])){ $countries[] = $country_code; }elseif(isset($valid_shortcuts[$country_code])){ $countries[] = $country_code; }elseif($country_code === 'worldwide'){ $countries[] = $country_code; } } } if(empty($countries)){ wp_send_json_error(['message' => __('Please select a valid country', 'cookieadmin')]); } $sanitized_rules = get_option('cookieadmin_geo_rules', []); if(!empty($rule['id'])){ $rule_id = $rule['id']; } else { $rule_id = 'rule_' . uniqid(); } $sanitized_rules[$rule_id] = [ 'name' => $rule['name'], 'law' => !empty($rule['law']) ? $rule['law'] : '', 'countries' => $countries, 'block_scripts' => in_array($rule['block_scripts'], ['inherit', 'on', 'off']) ? $rule['block_scripts'] : 'inherit', 'content_blocking' => in_array($rule['content_blocking'], ['inherit', 'on', 'off']) ? $rule['content_blocking'] : 'inherit', 'google_consent_mode_v2' => in_array($rule['google_consent_mode_v2'], ['inherit', 'on', 'off']) ? $rule['google_consent_mode_v2'] : 'inherit', 'clarity_consent' => in_array($rule['clarity_consent'], ['inherit', 'on', 'off']) ? $rule['clarity_consent'] : 'inherit', ]; update_option('cookieadmin_geo_rules', $sanitized_rules, true); wp_send_json_success([ 'message' => __('Geo targeting rules saved successfully', 'cookieadmin'), 'rules' => $sanitized_rules ]); } static function add_default_rules_ajax(){ check_ajax_referer('cookieadmin_pro_admin_js_nonce', 'cookieadmin_pro_security'); if(!current_user_can('administrator')){ wp_send_json_error(['message' => __('Sorry, but you do not have permissions to perform this action', 'cookieadmin')]); } $preset = !empty($_REQUEST['preset']) ? sanitize_text_field(wp_unslash($_REQUEST['preset'])) : ''; $rules = get_option('cookieadmin_geo_rules', []); if($preset === 'gdpr'){ $rules[] = [ 'id' => 'rule_' . uniqid(), 'name' => __('GDPR Countries', 'cookieadmin'), 'law' => 'cookieadmin_gdpr', 'countries' => ['europe'], 'block_scripts' => 'on', 'content_blocking' => 'on', 'google_consent_mode_v2' => 'on', 'clarity_consent' => 'inherit', ]; }elseif($preset === 'us'){ $rules[] = [ 'id' => 'rule_' . uniqid(), 'name' => __('US State Laws', 'cookieadmin'), 'law' => 'cookieadmin_us', 'countries' => ['US'], 'block_scripts' => 'inherit', 'content_blocking' => 'inherit', 'google_consent_mode_v2' => 'inherit', 'clarity_consent' => 'inherit', ]; } update_option('cookieadmin_geo_rules', $rules, true); wp_send_json_success(['rules' => $rules]); } static function toggle_geo_enabled(){ check_ajax_referer('cookieadmin_pro_admin_js_nonce', 'cookieadmin_pro_security'); if(!current_user_can('administrator')){ wp_send_json_error(['message' => __('Sorry, but you do not have permissions to perform this action', 'cookieadmin')]); } $enabled = !empty($_REQUEST['enabled']) ? true : false; update_option('cookieadmin_geo_enabled', $enabled, true); wp_send_json_success(['message' => $enabled ? __('Geo targeting enabled', 'cookieadmin') : __('Geo targeting disabled', 'cookieadmin')]); } static function show_db_update_notice(){ global $cookieadmin; // Check if the page belongs to the cookieadmin $current_page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : ''; if(strpos($current_page, 'cookieadmin') !== 0){ return false; } // Chekc if the database has been updated $db_data = get_option('cookieadmin_pro_geo_db_update_available', []); if(empty($db_data['filename'])){ return false; } echo ''.cookieadmin_logo_svg().' '.esc_html__('GeoIP database update.', 'cookieadmin').' '.esc_html__('A newer GeoIP database is available for download. Visit ', 'cookieadmin').' '.esc_html__('GEO Targeting', 'cookieadmin').''.esc_html__(' page to download the database.','cookieadmin').'