Hello @skokolopoulos,
Thanks for contacting us,
I hope you are doing well, We have to check this and we will keep you updated on this.
Thanks & Regards
WP Experts Support Team
Hello @skokolopoulos,
We understand that you want to redirect the unapproved users to access the specific page so we are going to send a snippet of code where you should replace a few things there 1) ID of page the page which you do not want unapproved users to access and 2) page URL where you want to redirect the unapproved users. if you still have any issues so please let me know.
Here is the code:
if(class_exists('pw_new_user_approve')) {
$user_id = get_current_user_id();
if(!empty($user_id)) {
$status = pw_new_user_approve()->get_user_status( $user_id );
if($status == 'pending') {
add_action('template_redirect', 'NUA_redirect_users');
}
}
}
function NUA_redirect_users() {
$current_page_id = get_queried_object_id();
$page_id = 2; // You should replace the page ID with the IDs of the page that you do not want unapproved users to access
$page = get_post($page_id);
if ($current_page_id == 2) {
wp_redirect('https://www.google.com'); // you can use here the any url page where you want to redirect the unapproved user
exit;
}
}
If you have any questions, feel free to reach out. We’re here to assist you.
Thank you
Thank you very much,
Ι use the code and it works perfectly.
Because I wanted to check two posts, I changed the code a bit as you can see below.
Also, because for the connection of the members I use the registration via google account, it did not cover the case of denied access (they connected to the website even if I set them to deny), so I created a snippet to cover this case as well. Thanks again.
if(class_exists('pw_new_user_approve')) {
$user_id = get_current_user_id();
if(!empty($user_id)) {
$status = pw_new_user_approve()->get_user_status( $user_id );
if($status == 'pending') {
add_action('template_redirect', 'NUA_redirect_users');
}
}
}
function NUA_redirect_users() {
$current_page_id = get_queried_object_id();
$page_id_1 = 457; // You should replace the page ID with the IDs of the page that you do not want unapproved users to access
$page_id_2 = 322; // You should replace the page ID with the IDs of the page that you do not want unapproved users to access
$page = get_post($page_id);
if ($current_page_id == 457) {
wp_logout();
//if (($current_page_id == 457) || ($current_page_id == 322){
wp_redirect('https://mydomain/log-out-user/'); // you can use here the any url page where you want to redirect the unapproved user
exit;
}
$page = get_post($page_id_2);
if ($current_page_id == 322) {
wp_logout();
wp_redirect('https://mydomain/log-out-user/'); // you can use here the any url page where you want to redirect the unapproved user
exit;
}
}
denied users
if(class_exists('pw_new_user_approve')) {
$user_id = get_current_user_id();
if(!empty($user_id)) {
$status = pw_new_user_approve()->get_user_status( $user_id );
if($status == 'denied') {
add_action('template_redirect', 'NUA_redirect_denied_users');
}
}
}
function NUA_redirect_denied_users() {
$current_page_id = get_queried_object_id();
$page_id_1 = 457; // You should replace the page ID with the IDs of the page that you do not want unapproved users to access
$page_id_2 = 322; // You should replace the page ID with the IDs of the page that you do not want unapproved users to access
$page = get_post($page_id);
if ($current_page_id == 457) {
wp_logout();
//if (($current_page_id == 457) || ($current_page_id == 322){
wp_redirect('https://mydomain/denied-user/'); // you can use here the any url page where you want to redirect the unapproved user
exit;
}
$page = get_post($page_id_2);
if ($current_page_id == 322) {
wp_logout();
wp_redirect('https://mydomain/denied-user/'); // you can use here the any url page where you want to redirect the unapproved user
exit;
}
}
Hello @skokolopoulos,
Sure, If you have any questions, feel free to reach out. We’re here to assist you.
Thank you