• Resolved skokolopoulos

    (@skokolopoulos)


    I want users who have registered but have not been approved by the administrator to be redirected to another page. Not when he registers but if they try to connect again before the approval. I have used the code below and it works but only when you register and the next time you log in to the website

    add_action( ‘user_register’,function( $user_id ){
    $user_status=get_user_meta( $user_id, ‘pw_user_status’,true );
    if(“pending”==$user_status)
    {
    wp_logout();
    $url=’https://www.support-informatics.eu’;
    //wp_redirect(home_url());
    wp_redirect($url);
    exit;
    }
    },99999999999999);

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Mirza Hamza

    (@hamza1010)

    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

    Plugin Support Mirza Hamza

    (@hamza1010)

    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

    Thread Starter skokolopoulos

    (@skokolopoulos)

    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;
        }
    }
    • This reply was modified 8 months, 3 weeks ago by skokolopoulos.
    Thread Starter skokolopoulos

    (@skokolopoulos)

    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;
        }
    }
    • This reply was modified 8 months, 3 weeks ago by skokolopoulos.
    Plugin Support Mirza Hamza

    (@hamza1010)

    Hello @skokolopoulos,

    Sure, If you have any questions, feel free to reach out. We’re here to assist you.

    Thank you

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Redirect a user until approved’ is closed to new replies.