Viewing 11 replies - 1 through 11 (of 11 total)
  • Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not with ours, our plugin is limited to prevent access to public buddypress areas, except for their profile editor screen.

    Thread Starter AJ

    (@permaculturetreegeek)

    What sort of access token does the plugin create for that?

    Is it a user meta value that I could check for and then use to display or hide other parts of the site?

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    the access token is just whatever BuddyPress itself uses. We use a user status column from the db to check if a user is approved or not, but that’s done after registration and activation is done.

    Thread Starter AJ

    (@permaculturetreegeek)

    I looked in the database and an approved user status=0, a pending verification status=2, and pending admin approval=69.

    I found a bit of code also in bp-registration-options – core.php:

    $user = get_userdata( $user_ID );
    				if ( 69 == $user->user_status ) {
    					wp_redirect( $bp->loggedin_user->domain );
    					exit();
    				}

    I’ll see if I can use that to lockdown some other areas of the site while the user is awaiting admin approval.

    Cheers.

    Thread Starter AJ

    (@permaculturetreegeek)

    In case anyone else needs to do this, here’s a starting point:

    // hide or show stuff depening on bp-register-options user status.
    add_action( 'init', 'bp_registration_status_unapproved' );
    function bp_registration_status_unapproved() {
    if ( is_user_logged_in() ) {
    $user_ID = get_current_user_id();
    $user = get_userdata( $user_ID );
    	if ( 69 == $user->user_status ) {
    		//just to test
    		echo "Hello, you are not approved";
    		//add stuff for unapproved users
    	}
        }
    }

    Thanks for the code, I had just figured out a similar way to do this, but this is a much simpler method.

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    Heads up, this snippet won’t end up working any more, as is, once 4.2 is released because of planned changes to use user meta instead of user status.

    Will need to edit the inner if statement to check for “true” or “false” AS STRINGS paired with get_user_meta() and the _bprwg_is_moderated meta key.

    Hoping to release 4.2 BETA 2 later today.

    Thanks for the heads up. I’m checking the 4.2 BETA 2 version, everything is working well so far, I haven’t found any issues.

    In case anyone needs it, the updated code from above is:

    function bp_registration_status_unapproved() {
    	if ( is_user_logged_in() ) {
    		$user_ID = get_current_user_id();
    		$key = '_bprwg_is_moderated';
    		$single = 'true';
    		$test = get_user_meta($user_ID, $key, $single);
    			if ( $test == 'true' ) {
    				return true;
    				//add stuff for unapproved users
    			}
    	}
    }
    Jasper

    (@garyhamptonmcp)

    Where does this go? I just put it in at the end of core.php in BP registrations and it’s not working… I guess I must of put it in the wrong place? thanks

    There may be an easier way to use it, but I used it in my theme page templates, so

    <?php if (bp_registration_status_unapproved()){
    	echo "Hello, please wait until an admin activates your account.<br />";}
    	else if (have_posts()) : while (have_posts()) : the_post(); ?>

    instead of something like

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    Michael Beckwith

    (@tw2113)

    The BenchPresser

    sasdts, a quick note on your updated code version. Having the return true line after your 2nd if statement would exit out and anything in the “add stuff for unapproved users” line wouldn’t get executed. The return line would be best at the end of the if statement.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Stop user from logging in until account is approved.’ is closed to new replies.