Hi @digiblogger and all,
While I’m now dedicating to design and implement codes, I’ll show the other solution here.
The use case is slightly different from the proposal.
USE CASE
- White list of Country Code is “
JP
“
- Additional Country Code which you want to give permission for login is “
US
“
Here is the codes in your functions.php
.
/**
* The whitelist of country code which is only permitted to login/logout.
*
*/
$my_login_whitelist = array(
'US', // should be upper case
);
add_filter( 'ip-geo-block-login', 'my_permit_login' );
add_filter( 'ip-geo-block-admin', 'my_permit_logged_in' );
add_filter( 'ip-geo-block-comment', 'my_permit_logged_in' );
/**
* Permit only 'login' and 'logout' with specific whitelist of country codes.
*
* The following condition doesn't permit 'register', 'resetpass', 'lostpassword'.
* |--------------------------------|-----------------------------------------|
* | Condition | Examples of requested URI |
* |================================|=========================================|
* |empty( $_REQUEST['action'] ) |wp-login.php, wp-login.php?loggedout=true|
* |--------------------------------|-----------------------------------------|
* |'login' === $_REQUEST['action'] |wp-login.php?action=login |
* |--------------------------------|-----------------------------------------|
* |'logout' === $_REQUEST['action']|wp-login.php?action=logout |
* |--------------------------------|-----------------------------------------|
*/
function my_permit_login( $validate ) {
global $my_login_whitelist;
if ( in_array( $validate['code'], $my_login_whitelist ) ) {
if ( empty( $_REQUEST['action'] ) ||
'login' === $_REQUEST['action'] ||
'logout' === $_REQUEST['action'] ) {
$validate['result'] = 'passed';
}
}
return $validate; // 'result' should be empty to be validated by country code
}
/**
* Permit only logged in user with specific whitelist of country codes.
*
*/
function my_permit_logged_in( $validate ) {
global $my_login_whitelist;
if ( in_array( $validate['code'], $my_login_whitelist ) && $validate['auth'] ) {
$validate['result'] = 'passed';
}
return $validate; // 'result' should be empty to be validated by country code
}
Enjoy!!