Changeset 3304864
- Timestamp:
- 06/02/2025 11:05:49 AM (10 months ago)
- Location:
- aa-block-country
- Files:
-
- 5 edited
-
assets/banner-772x250.png (modified) (previous)
-
tags/1.0.1/aablockcountry.php (modified) (12 diffs)
-
tags/1.0.1/readme.txt (modified) (1 diff)
-
trunk/aablockcountry.php (modified) (12 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
aa-block-country/tags/1.0.1/aablockcountry.php
r3304395 r3304864 1 1 <?php 2 /* *3 *Plugin Name: AA Block Country4 *Plugin URI: https://wordpress.org/plugins/aa-block-country/5 *Description: Blocks visitors from selected countries using IP geolocation. GDPR-compliant with consent banner.6 *Version: 1.0.17 *Author: Syed Ashik Mahmud8 *Author URI: https://aaextensions.com9 *License: GPL210 *License URI: https://www.gnu.org/licenses/gpl-2.0.html11 *Text Domain: aa-block-country12 *Domain Path: /languages13 */2 /* 3 Plugin Name: AA Block Country 4 Plugin URI: https://wordpress.org/plugins/aa-block-country/ 5 Description: Blocks visitors from selected countries using IP geolocation. GDPR-compliant with consent banner. 6 Version: 1.0.1 7 Author: Syed Ashik Mahmud 8 Author URI: https://aaextensions.com 9 License: GPL2 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 Text Domain: aa-block-country 12 Domain Path: /languages 13 */ 14 14 15 if (!defined('ABSPATH')) exit; // Exit if accessed directly15 if (!defined('ABSPATH')) exit; 16 16 17 // ===== Helper: Get visitor IP ===== 17 // Load plugin textdomain 18 function aa_block_load_textdomain() { 19 load_plugin_textdomain('aa-block-country', false, dirname(plugin_basename(__FILE__)) . '/languages'); 20 } 21 add_action('plugins_loaded', 'aa_block_load_textdomain'); 22 23 // Get user IP 18 24 function aa_block_get_user_ip() { 19 25 $client = $_SERVER['HTTP_CLIENT_IP'] ?? ''; … … 26 32 } 27 33 28 // ===== Helper: Get geolocation with transient caching =====34 // Get user country code with caching 29 35 function aa_block_get_user_country_code($ip) { 30 36 $transient_key = 'aa_geo_' . md5($ip); … … 38 44 $body = wp_remote_retrieve_body($response); 39 45 $data = json_decode($body); 40 46 41 47 if (!empty($data->countryCode)) { 42 48 set_transient($transient_key, $data->countryCode, HOUR_IN_SECONDS * 24); … … 46 52 } 47 53 48 // ===== Main: Block user if needed =====54 // Block user based on country 49 55 function aa_block_country_check() { 50 56 if (is_admin()) return; … … 54 60 55 61 if ($require_consent && !isset($_COOKIE['aa_geo_consent'])) { 56 return; // Skip blocking until consent given62 return; 57 63 } 58 64 … … 61 67 62 68 $blocked_countries = array_map('trim', explode(',', get_option('aa_block_countries', ''))); 63 $blocked_message = get_option('aa_block_message', 'Access denied for your region.');69 $blocked_message = get_option('aa_block_message', __('Access denied for your region.', 'aa-block-country')); 64 70 65 71 if (in_array(strtoupper($user_country), $blocked_countries)) { … … 69 75 add_action('init', 'aa_block_country_check'); 70 76 71 // ===== Admin: Register settings =====77 // Register settings 72 78 function aa_block_register_settings() { 73 79 register_setting('aa_block_settings_group', 'aa_block_countries', ['type' => 'string', 'sanitize_callback' => 'sanitize_text_field']); … … 77 83 add_action('admin_init', 'aa_block_register_settings'); 78 84 79 // ===== Admin: Menu page =====85 // Add admin menu 80 86 function aa_block_admin_menu() { 81 add_menu_page( 'Block Country Settings', 'Block Country', 'manage_options', 'aa-block-country', 'aa_block_settings_page', 'dashicons-shield-alt');87 add_menu_page(__('Block Country Settings', 'aa-block-country'), __('Block Country', 'aa-block-country'), 'manage_options', 'aa-block-country', 'aa_block_settings_page', 'dashicons-shield-alt'); 82 88 } 83 89 add_action('admin_menu', 'aa_block_admin_menu'); 84 90 85 // ===== Admin: Settings page UI =====91 // Admin settings page UI 86 92 function aa_block_settings_page() { 87 93 ?> 88 94 <div class="wrap"> 89 <h1> Block Country Settings</h1>95 <h1><?php _e('Block Country Settings', 'aa-block-country'); ?></h1> 90 96 <form method="post" action="options.php"> 91 97 <?php … … 95 101 <table class="form-table"> 96 102 <tr> 97 <th scope="row"> Blocked Country Codes</th>103 <th scope="row"><?php _e('Blocked Country Codes', 'aa-block-country'); ?></th> 98 104 <td> 99 105 <input type="text" name="aa_block_countries" value="<?php echo esc_attr(get_option('aa_block_countries')); ?>" size="50" /> 100 <p class="description"> Comma-separated (e.g. <code>US, IN, CN</code>)</p>106 <p class="description"><?php _e('Comma-separated (e.g. US, IN, CN)', 'aa-block-country'); ?></p> 101 107 </td> 102 108 </tr> 103 109 <tr> 104 <th scope="row"> Custom Blocked Message</th>110 <th scope="row"><?php _e('Custom Blocked Message', 'aa-block-country'); ?></th> 105 111 <td> 106 112 <input type="text" name="aa_block_message" value="<?php echo esc_attr(get_option('aa_block_message')); ?>" size="70" /> … … 108 114 </tr> 109 115 <tr> 110 <th scope="row"> Require GDPR Consent</th>116 <th scope="row"><?php _e('Require GDPR Consent', 'aa-block-country'); ?></th> 111 117 <td> 112 118 <input type="checkbox" name="aa_block_consent_required" value="1" <?php checked(1, get_option('aa_block_consent_required', 0)); ?> /> 113 <label> Only block visitors after consent is given</label>119 <label><?php _e('Only block visitors after consent is given', 'aa-block-country'); ?></label> 114 120 </td> 115 121 </tr> … … 121 127 } 122 128 123 // ===== Frontend: GDPR consent banner =====129 // GDPR Consent banner 124 130 function aa_block_consent_banner() { 125 131 if (!is_admin() && get_option('aa_block_consent_required', false) && !isset($_COOKIE['aa_geo_consent'])) { … … 149 155 </style> 150 156 <div id="aa-gdpr-consent"> 151 This site uses geolocation to manage access. By continuing, you agree to our use of location data.152 <button onclick="aaConsentAccept()"> I Agree</button>157 <?php _e('This site uses geolocation to manage access. By continuing, you agree to our use of location data.', 'aa-block-country'); ?> 158 <button onclick="aaConsentAccept()"><?php _e('I Agree', 'aa-block-country'); ?></button> 153 159 </div> 154 160 <script> -
aa-block-country/tags/1.0.1/readme.txt
r3304397 r3304864 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 It's unique plugin from AA Production House and it is created to block visitors from any country :)11 It's unique plugin from AA Production House and it is created to block visitors from any country 12 12 13 ==Description== 14 It's unique plugin from AA Production House and it is created to block visitors from any country :) You can easily do that from settings option. 13 == Description == 14 15 It's unique plugin from AA Production House and it is created to block visitors from any country :) You can easily do that from settings option 15 16 16 17 = Features = 17 18 18 * Use settings options 19 <ol> 20 <li>Blocks visitors based on their country using IP detection.</li> 21 <li>Uses <code>ip-api.com</code> for geolocation with transient caching.</li> 22 <li>Custom block message support via admin settings.</li> 23 <li>Option to require GDPR consent before blocking.</li> 24 <li>Displays a GDPR consent banner on the frontend (mobile-friendly).</li> 25 <li>Admin panel with easy country code input and message editor.</li> 26 <li>Modern, clean, responsive admin UI.</li> 27 <li>Multilingual ready with <code>.pot</code> file support (text domain: <code>aa-block-country</code>).</li> 28 <li>Secure coding practices and follows latest WordPress standards.</li> 29 <li>Lightweight and optimized for performance.</li> 30 </ol> 19 31 20 32 = How to use it = 21 33 22 It is very easy to use. 34 <ol> 35 <li>Install and activate the <strong>AA Block Country</strong> plugin in your WordPress admin.</li> 36 <li>Go to <strong>Admin → Block Country</strong> from the dashboard menu.</li> 37 <li>Enter the country codes you want to block (e.g., <code>US, IN, CN</code>).</li> 38 <li>Customize the block message shown to restricted visitors.</li> 39 <li>(Optional) Enable the GDPR consent toggle if required by law.</li> 40 <li>Click <strong>Save</strong> to apply your settings.</li> 41 <li>Visitors from blocked countries will now be denied access with your custom message.</li> 42 </ol> 23 43 24 == Installation ==25 44 26 1. Install as regular WordPress plugin.<br /> 27 2. Go your plugin setting via WordPress Dashboard and find "<strong>AA Block country</strong>" activate it.<br /> 45 = Installation = 46 47 <ol> 48 <li>Download the <strong>AA Block Country</strong> plugin ZIP file.</li> 49 <li>Go to your WordPress dashboard → <strong>Plugins → Add New</strong>.</li> 50 <li>Click <strong>Upload Plugin</strong> and choose the ZIP file.</li> 51 <li>Click <strong>Install Now</strong>, then <strong>Activate</strong> the plugin.</li> 52 <li>The settings panel will appear under <strong>Block Country</strong> in the admin menu.</li> 53 </ol> 54 55 56 = Screenshots = 57 58 59 = Changelog = 60 61 <ol> 62 <li><strong>Version 1.0.1</strong> (2025-06-02) 63 <ol type="a"> 64 <li>Added multilingual support with text domain <code>aa-block-country</code>.</li> 65 <li>Improved admin settings UI with better mobile responsiveness.</li> 66 <li>Enhanced GDPR consent banner styling and accessibility.</li> 67 <li>Sanitized and validated all user inputs for better security.</li> 68 <li>Refactored code for compliance with latest WordPress coding standards.</li> 69 <li>Optimized transient caching for IP-based geolocation.</li> 70 </ol> 71 </li> 72 </ol> -
aa-block-country/trunk/aablockcountry.php
r3304395 r3304864 1 1 <?php 2 /* *3 *Plugin Name: AA Block Country4 *Plugin URI: https://wordpress.org/plugins/aa-block-country/5 *Description: Blocks visitors from selected countries using IP geolocation. GDPR-compliant with consent banner.6 *Version: 1.0.17 *Author: Syed Ashik Mahmud8 *Author URI: https://aaextensions.com9 *License: GPL210 *License URI: https://www.gnu.org/licenses/gpl-2.0.html11 *Text Domain: aa-block-country12 *Domain Path: /languages13 */2 /* 3 Plugin Name: AA Block Country 4 Plugin URI: https://wordpress.org/plugins/aa-block-country/ 5 Description: Blocks visitors from selected countries using IP geolocation. GDPR-compliant with consent banner. 6 Version: 1.0.1 7 Author: Syed Ashik Mahmud 8 Author URI: https://aaextensions.com 9 License: GPL2 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 Text Domain: aa-block-country 12 Domain Path: /languages 13 */ 14 14 15 if (!defined('ABSPATH')) exit; // Exit if accessed directly15 if (!defined('ABSPATH')) exit; 16 16 17 // ===== Helper: Get visitor IP ===== 17 // Load plugin textdomain 18 function aa_block_load_textdomain() { 19 load_plugin_textdomain('aa-block-country', false, dirname(plugin_basename(__FILE__)) . '/languages'); 20 } 21 add_action('plugins_loaded', 'aa_block_load_textdomain'); 22 23 // Get user IP 18 24 function aa_block_get_user_ip() { 19 25 $client = $_SERVER['HTTP_CLIENT_IP'] ?? ''; … … 26 32 } 27 33 28 // ===== Helper: Get geolocation with transient caching =====34 // Get user country code with caching 29 35 function aa_block_get_user_country_code($ip) { 30 36 $transient_key = 'aa_geo_' . md5($ip); … … 38 44 $body = wp_remote_retrieve_body($response); 39 45 $data = json_decode($body); 40 46 41 47 if (!empty($data->countryCode)) { 42 48 set_transient($transient_key, $data->countryCode, HOUR_IN_SECONDS * 24); … … 46 52 } 47 53 48 // ===== Main: Block user if needed =====54 // Block user based on country 49 55 function aa_block_country_check() { 50 56 if (is_admin()) return; … … 54 60 55 61 if ($require_consent && !isset($_COOKIE['aa_geo_consent'])) { 56 return; // Skip blocking until consent given62 return; 57 63 } 58 64 … … 61 67 62 68 $blocked_countries = array_map('trim', explode(',', get_option('aa_block_countries', ''))); 63 $blocked_message = get_option('aa_block_message', 'Access denied for your region.');69 $blocked_message = get_option('aa_block_message', __('Access denied for your region.', 'aa-block-country')); 64 70 65 71 if (in_array(strtoupper($user_country), $blocked_countries)) { … … 69 75 add_action('init', 'aa_block_country_check'); 70 76 71 // ===== Admin: Register settings =====77 // Register settings 72 78 function aa_block_register_settings() { 73 79 register_setting('aa_block_settings_group', 'aa_block_countries', ['type' => 'string', 'sanitize_callback' => 'sanitize_text_field']); … … 77 83 add_action('admin_init', 'aa_block_register_settings'); 78 84 79 // ===== Admin: Menu page =====85 // Add admin menu 80 86 function aa_block_admin_menu() { 81 add_menu_page( 'Block Country Settings', 'Block Country', 'manage_options', 'aa-block-country', 'aa_block_settings_page', 'dashicons-shield-alt');87 add_menu_page(__('Block Country Settings', 'aa-block-country'), __('Block Country', 'aa-block-country'), 'manage_options', 'aa-block-country', 'aa_block_settings_page', 'dashicons-shield-alt'); 82 88 } 83 89 add_action('admin_menu', 'aa_block_admin_menu'); 84 90 85 // ===== Admin: Settings page UI =====91 // Admin settings page UI 86 92 function aa_block_settings_page() { 87 93 ?> 88 94 <div class="wrap"> 89 <h1> Block Country Settings</h1>95 <h1><?php _e('Block Country Settings', 'aa-block-country'); ?></h1> 90 96 <form method="post" action="options.php"> 91 97 <?php … … 95 101 <table class="form-table"> 96 102 <tr> 97 <th scope="row"> Blocked Country Codes</th>103 <th scope="row"><?php _e('Blocked Country Codes', 'aa-block-country'); ?></th> 98 104 <td> 99 105 <input type="text" name="aa_block_countries" value="<?php echo esc_attr(get_option('aa_block_countries')); ?>" size="50" /> 100 <p class="description"> Comma-separated (e.g. <code>US, IN, CN</code>)</p>106 <p class="description"><?php _e('Comma-separated (e.g. US, IN, CN)', 'aa-block-country'); ?></p> 101 107 </td> 102 108 </tr> 103 109 <tr> 104 <th scope="row"> Custom Blocked Message</th>110 <th scope="row"><?php _e('Custom Blocked Message', 'aa-block-country'); ?></th> 105 111 <td> 106 112 <input type="text" name="aa_block_message" value="<?php echo esc_attr(get_option('aa_block_message')); ?>" size="70" /> … … 108 114 </tr> 109 115 <tr> 110 <th scope="row"> Require GDPR Consent</th>116 <th scope="row"><?php _e('Require GDPR Consent', 'aa-block-country'); ?></th> 111 117 <td> 112 118 <input type="checkbox" name="aa_block_consent_required" value="1" <?php checked(1, get_option('aa_block_consent_required', 0)); ?> /> 113 <label> Only block visitors after consent is given</label>119 <label><?php _e('Only block visitors after consent is given', 'aa-block-country'); ?></label> 114 120 </td> 115 121 </tr> … … 121 127 } 122 128 123 // ===== Frontend: GDPR consent banner =====129 // GDPR Consent banner 124 130 function aa_block_consent_banner() { 125 131 if (!is_admin() && get_option('aa_block_consent_required', false) && !isset($_COOKIE['aa_geo_consent'])) { … … 149 155 </style> 150 156 <div id="aa-gdpr-consent"> 151 This site uses geolocation to manage access. By continuing, you agree to our use of location data.152 <button onclick="aaConsentAccept()"> I Agree</button>157 <?php _e('This site uses geolocation to manage access. By continuing, you agree to our use of location data.', 'aa-block-country'); ?> 158 <button onclick="aaConsentAccept()"><?php _e('I Agree', 'aa-block-country'); ?></button> 153 159 </div> 154 160 <script> -
aa-block-country/trunk/readme.txt
r3304397 r3304864 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 10 11 It's unique plugin from AA Production House and it is created to block visitors from any country :)11 It's unique plugin from AA Production House and it is created to block visitors from any country 12 12 13 ==Description== 14 It's unique plugin from AA Production House and it is created to block visitors from any country :) You can easily do that from settings option. 13 == Description == 14 15 It's unique plugin from AA Production House and it is created to block visitors from any country :) You can easily do that from settings option 15 16 16 17 = Features = 17 18 18 * Use settings options 19 <ol> 20 <li>Blocks visitors based on their country using IP detection.</li> 21 <li>Uses <code>ip-api.com</code> for geolocation with transient caching.</li> 22 <li>Custom block message support via admin settings.</li> 23 <li>Option to require GDPR consent before blocking.</li> 24 <li>Displays a GDPR consent banner on the frontend (mobile-friendly).</li> 25 <li>Admin panel with easy country code input and message editor.</li> 26 <li>Modern, clean, responsive admin UI.</li> 27 <li>Multilingual ready with <code>.pot</code> file support (text domain: <code>aa-block-country</code>).</li> 28 <li>Secure coding practices and follows latest WordPress standards.</li> 29 <li>Lightweight and optimized for performance.</li> 30 </ol> 19 31 20 32 = How to use it = 21 33 22 It is very easy to use. 34 <ol> 35 <li>Install and activate the <strong>AA Block Country</strong> plugin in your WordPress admin.</li> 36 <li>Go to <strong>Admin → Block Country</strong> from the dashboard menu.</li> 37 <li>Enter the country codes you want to block (e.g., <code>US, IN, CN</code>).</li> 38 <li>Customize the block message shown to restricted visitors.</li> 39 <li>(Optional) Enable the GDPR consent toggle if required by law.</li> 40 <li>Click <strong>Save</strong> to apply your settings.</li> 41 <li>Visitors from blocked countries will now be denied access with your custom message.</li> 42 </ol> 23 43 24 == Installation ==25 44 26 1. Install as regular WordPress plugin.<br /> 27 2. Go your plugin setting via WordPress Dashboard and find "<strong>AA Block country</strong>" activate it.<br /> 45 = Installation = 46 47 <ol> 48 <li>Download the <strong>AA Block Country</strong> plugin ZIP file.</li> 49 <li>Go to your WordPress dashboard → <strong>Plugins → Add New</strong>.</li> 50 <li>Click <strong>Upload Plugin</strong> and choose the ZIP file.</li> 51 <li>Click <strong>Install Now</strong>, then <strong>Activate</strong> the plugin.</li> 52 <li>The settings panel will appear under <strong>Block Country</strong> in the admin menu.</li> 53 </ol> 54 55 56 = Screenshots = 57 58 59 = Changelog = 60 61 <ol> 62 <li><strong>Version 1.0.1</strong> (2025-06-02) 63 <ol type="a"> 64 <li>Added multilingual support with text domain <code>aa-block-country</code>.</li> 65 <li>Improved admin settings UI with better mobile responsiveness.</li> 66 <li>Enhanced GDPR consent banner styling and accessibility.</li> 67 <li>Sanitized and validated all user inputs for better security.</li> 68 <li>Refactored code for compliance with latest WordPress coding standards.</li> 69 <li>Optimized transient caching for IP-based geolocation.</li> 70 </ol> 71 </li> 72 </ol>
Note: See TracChangeset
for help on using the changeset viewer.