bbPress Plugin Browser »

Approve User Registration (0.3)

Download

Version: 0.3

Other Versions

Last Updated: 2008-5-21

Requires bbPress Version: 0.9.0.2 or higher

Compatible up to: 0.9.0.2

Author Homepage »

Plugin Homepage »

Donate to this plugin »

Average Rating

5 stars
4 stars
3 stars
2 stars
1 star
(8)

Your Rating

Author: Aditya Naik


  1. This is a greatly needed plugin as I would like to stop spammers right at the front door as they try to register. However, I could not get it to work on either RC-3 or the bbPress 1.0 final.

    It has the admin User Registration Queue menu and a new user can fill out the registration form. However, after a user tries to register, the user does not get the email and the admin panel freezes up with the following error message:

    Fatal error: Class 'BB_User' not found in /home/mysite/mysite.org/board/my-plugins/approve-user-registration/approve-user-registration.php on line 58

    I do see that it is stated to be only compatible up to 0.9.0.2, however an updated version would be highly regarded.

    Posted: 2 years ago #
  2. here's an updated version of the plugin. Works in bbPress 1.0:

    <?php
    /*
    Plugin Name: Approve User Registration
    Plugin URI: http://www.adityanaik.com/projects/plugins/approve-user-registration/
    Description: Holds user registration for approval from the administration
    Author: Various.
    Author URI: http://www.adityanaik.com/
    Version: 0.4.2
    
    Originally composed by Aditya Naik (http://www.adityanaik.com/), then fixed by _ck_ (http://bbpress.org/forums/profile/_ck_) to work with bbPress version 1.0, and various edits made by Tom de Bruin (www.deadlyhifi.com). What a wonderful sharing world.
    
    v-0.4:
    - ammended emails sent out.
    - added column on approve page stating how long ago they registered.
    0.4.1:
    - updated bb_new_user function to return correct error messages.
    - Set correct display name upon registration.
    0.4.2:
    - check registration offset by hours rather than seconds.
    - auto checkbox if registered over 15 hours ago.
    */
    if (!function_exists('bb_new_user')) :
    function bb_new_user( $user_login, $user_email, $user_url, $user_status = 0 ) {
    	global $wp_users_object, $bbdb;
    
    	// is_email check + dns
    	if ( !$user_email = bb_verify_email( $user_email ) )
    		return new WP_Error( 'user_email', __( 'Invalid email address' ), $user_email );
    
    	if ( !$user_login = sanitize_user( $user_login, true ) )
    		return new WP_Error( 'user_login', __( 'Invalid username' ), $user_login );
    
    	// user_status = 1 means the user has not yet been verified
    	$user_status = is_numeric($user_status) ? (int) $user_status : 0;
    
    	$user_nicename = $_user_nicename = bb_user_nicename_sanitize( $user_login );
    	if ( strlen( $_user_nicename ) < 1 )
    		return new WP_Error( 'user_login', __( 'Invalid username' ), $user_login );
    
    	while ( is_numeric($user_nicename) || $existing_user = bb_get_user_by_nicename( $user_nicename ) )
    		$user_nicename = bb_slug_increment($_user_nicename, $existing_user->user_nicename, 50);
    
    	$user_url = bb_fix_link( $user_url );
    	$user_registered = bb_current_time('mysql');
    	$password = wp_generate_password();
    	$user_pass = wp_hash_password( $password );
    
    	$user = $wp_users_object->new_user( compact( 'user_login', 'user_email', 'user_url', 'user_nicename', 'user_status', 'user_pass' ) );
    
    	if ( is_wp_error($user) ) {
    		if ( 'user_nicename' == $user->get_error_code() )
    			return new WP_Error( 'user_login', $user->get_error_message() );
    		return $user;
    	}
    
    	$user_id = $bbdb->insert_id;
    	$options = bb_get_option('approve_user_registration_options');
    		bb_update_usermeta( $user_id, $bbdb->prefix . 'capabilities', array('waitingapproval' => true, 'member' => true) );
    		approve_user_registration_send_pass( $user_id, $password );
    
    	do_action('bb_new_user', $user['ID'], $user['plain_pass']);
    	return $user['ID'];
    }
    endif;
    
    if (!function_exists('bb_check_login')) :
    function bb_check_login($user, $pass, $already_md5 = false) {
    	global $bbdb;
    	$user = sanitize_user( $user );
    	if ($user == '') {
    		return false;
    	}
    	$user = bb_get_user_by_name( $user );
    
    	$test_user = defined('BACKPRESS_PATH') ? new BP_User($user->ID) : new BB_User($user->ID);
    
    	if ($test_user->has_cap('waitingapproval')) return false;
    
    	if ( !wp_check_password($pass, $user->user_pass, $user->ID) ) {
    		return false;
    	}
    
    	return $user;
    }
    endif;
    
    function approve_user_registration_send_pass( $user, $pass ) {
    	if ( !$user = bb_get_user( $user ) )
    		return false;
    	$options = bb_get_option('approve_user_registration_options');
    	$passtext = ($options['send_password_with'] != 'A') ? sprintf("\nYour password is: %1\$s ",$pass) : '';
    	$message = __("Your username is: %1\$s $passtext\n\nYour registration is being held for approval. Once it is approved you can log on here: %2\$s");
    
    	return bb_mail(
    		bb_get_user_email( $user->ID ),
    		bb_get_option('name') . ': ' . __('User Registration'),
    		sprintf( $message, $user->user_login, bb_get_option('uri') )
    	);
    }
    
    if (!BB_IS_ADMIN) {
    	return;
    }
    
    add_action( 'bb_admin_menu_generator', 'approve_user_registration_add_admin_page' );
    function approve_user_registration_add_admin_page() {
    	bb_admin_add_submenu(__('Registration Queue'), 'moderate', 'approve_user_registration_admin_page', 'users.php');
    	bb_admin_add_submenu(__('Registration Settings'), 'moderate', 'approve_user_registration_settings_page', 'options-general.php');
    }
    
    function approve_user_registration_settings_page() {
    	$options = bb_get_option('approve_user_registration_options');
    	?>
    	<h2>Registration Settings</h2>
    	<form class="options" method="post">
    		<fieldset>
    			<label for="">
    				Send password with
    			</label>
    			<div>
    				Registration Mail <input <?php if($options['send_password_with'] != 'A') echo ' checked="checked" ' ?> type="radio" name="approve_user_registration[send_password_with]" id="send_password_with_registration" value="R"/>
    				Approval Mail <input <?php if($options['send_password_with'] == 'A') echo ' checked="checked" ' ?> type="radio" name="approve_user_registration[send_password_with]" id="send_password_with_approval" value="A"/>
    			</div>
    	       	<p class="submit">
    	          <input type="submit" name="approve_user_registration_button_options" value="Update Options" />
    	        </p>
    	        </fieldset>
    	</form>
    	<?php
    }
    
    add_action('approve_user_registration_settings_page_pre_head','approve_user_registration_settings_page_process');
    function approve_user_registration_settings_page_process() {
    
    	if (isset($_POST['approve_user_registration'])) {
    		$options = ($_POST['approve_user_registration']) ? $_POST['approve_user_registration'] : array() ;
    		bb_update_option('approve_user_registration_options',$options);
    	}
    }
    
    add_action('approve_user_registration_admin_page_pre_head','approve_user_registration_admin_page_process');
    function approve_user_registration_admin_page_process() {
    	class BB_Users_Waiting_Approval extends BB_Users_By_Role {
    		var $role = '';
    		var $title = '';
    
    		function BB_Users_Waiting_Approval($page = '') { // constructor
    			$this->role = 'waitingapproval';
    			$this->raw_page = ( '' == $page ) ? false : (int) $page;
    			$this->page = (int) ( '' == $page ) ? 1 : $page;
    
    			$this->prepare_query();
    			$this->query();
    			$this->do_paging();
    		}
    
    		function display( $show_search = true, $show_email = false ) {
    			global $bb_roles;
    			$r = '';
    			$now = date('Y-m-d H:i:s');
    
    			// Make the user objects
    			foreach ( $this->get_results() as $user_id ) {
    				$tmp_user = defined('BACKPRESS_PATH') ? new BP_User($user_id) : new BB_User($user_id);
    				$roles = $tmp_user->roles;
    				$role = array_shift($roles);
    				$roleclasses[$role][$tmp_user->data->user_login] = $tmp_user;
    			}
    
    			if ( isset($this->title) )
    				$title = $this->title;
    			elseif ( $this->is_search() )
    				$title = sprintf(__('Users Matching "%s" by Role'), wp_specialchars( $this->search_term ));
    			else
    				$title = __('User List by Role');
    			$r .= "<h2>$title</h2>\n";
    
    			if ( $show_search ) {
    				$r .= "<form action='' method='get' id='search'>\n\t<p>";
    				$r .= "\t\t<input type='text' name='usersearch' id='usersearch' value='" . wp_specialchars( $this->search_term, 1) . "' />\n";
    				$r .= "\t\t<input type='submit' value='" . __('Search for users &raquo;') . "' />\n\t</p>\n";
    				$r .= "</form>\n\n";
    			}
    
    			if ( $this->get_results() ) {
    				if ( $this->is_search() )
    					$r .= "<p>\n\t<a href='users.php'>" . __('&laquo; Back to All Users') . "</a>\n</p>\n\n";
    
    				$r .= '<h3>' . sprintf(__('%1$s – %2$s of %3$s shown below'), $this->first_user + 1, min($this->first_user + $this->users_per_page, $this->total_users_for_query), $this->total_users_for_query) . "</h3>\n";
    
    				if ( $this->results_are_paged() )
    					$r .= "<div class='user-paging-text'>\n" . $this->paging_text . "</div>\n\n";
    
    				foreach($roleclasses as $role => $roleclass) {
    					ksort($roleclass);
    					if ( !empty($role) )
    						$r .= "<h3>{$bb_roles->role_names[$role]}<br /><span style=\"text-align: right; color: #ccc; font-size: small; font-style: normal;\">Registered: Red: < 15 hours ago. Blue: > 15 hours ago. Green: > 24 hours ago.</span></h3>\n";
    					else
    						$r .= "<h3><em>" . __('Users with no role in these forums') . "</em></h3>\n";
    
    					$r .= "<table class='widefat'>\n";
    					$r .= "<thead>\n";
    					$r .= "\t<tr>\n";
    					$r .= "\t\t<th>&nbsp;</th>\n";
    					if ( $show_email ) {
    						$r .= "\t\t<th style='width:30%;'>" . __('Username') . "</th>\n";
    						$r .= "\t\t<th style='width:30%;'>" . __('Email') . "</th>\n";
    					} else {
    						$r .= "\t\t<th style='width:40%;'>" . __('Username') . "</th>\n";
    					}
    					$r .= "\t\t<th>" . __('Registered At') . "</th>\n";
    					$r .= "\t\t<th>" . __('Elapsed') . "</th>\n";
    					$r .= "\t</tr>\n";
    					$r .= "</thead>\n\n";
    
    					$r .= "<tbody id='role-$role'>\n";
    					foreach ( (array) $roleclass as $user_object ) {
    						//$r .= bb_user_row($user_object->ID, $role, $show_email);
    						$user = bb_get_user( $user_object->ID );
    						$registered = date( 'Y-m-d H:i:s', bb_offset_time( bb_gmtstrtotime( $user->user_registered ) ) );
    						$date_eng = date( 'H:i:s / d-m-Y', bb_offset_time( bb_gmtstrtotime( $user->user_registered ) ) );
    						$difference = (strtotime($now) - strtotime($registered));
    						$hours_ago = number_format( ( $difference / 60 ) / 60 , 0 );
    
    						if ( $hours_ago < '15') {
    							$reg_compare = '"color: red"';
    							$checked = '';
    						}
    						if ( $hours_ago >= '15' && $hours_ago < '24' ) {
    							$reg_compare = '"color: blue"';
    							$checked = 'checked';
    						}
    						if ( $hours_ago >= '24' ) {
    							$reg_compare = '"color: green"';
    							$checked = 'checked';
    						}
    
    						$r .= "\t<tr id='user-$user->ID'" . get_alt_class("user-$role") . ">\n";
    						$r .= "\t\t<td><input type='checkbox' value='$user->ID' name='userids[]' $checked/></td>\n";
    						$r .= "\t\t<td><a href='" . get_user_profile_link( $user->ID ) . "' style=" . $reg_compare . ">" . get_user_name( $user->ID ) . "</a></span></td>\n";
    						if ( $show_email ) {
    							$email = bb_get_user_email( $user->ID );
    							$r .= "\t\t<td><a href='mailto:$email'>$email</a></td>\n";
    						}
    						$r .= "\t\t<td><span style=" . $reg_compare . ">" . $date_eng . "</span></td>\n";
    						$r .= "\t\t<td>" . $hours_ago . " hours</td>\n";
    						$r .= "\n\t</tr>";
    					}
    					$r .= "</tbody>\n";
    					$r .= "</table>\n";
    
    				}
    
    			 	if ( $this->results_are_paged() )
    					$r .= "<div class='user-paging-text'>\n" . $this->paging_text . "</div>\n\n";
    			}
    			?>
    			<form method="post" name="approve_user_registration_form">
    			<?php
    			echo $r;
    			if ($roleclass) {
    			?>
    	       <p class="submit">
    	          <input type="submit" name="approve_user_registration_button_approve" value="Approve" />
    	          <input type="submit" name="approve_user_registration_button_reject" value="Reject" />
    	        </p>
    	        </form>
    			<?php
    			}
    		}
    	}
    
    	if (isset($_POST['approve_user_registration_button_approve'])) {
    		$users = $_POST['userids'];
    		if ($users)
    		foreach($users as $user) {
    			approve_user_registration_approve_user($user);
    		}
    	} elseif (isset($_POST['approve_user_registration_button_reject'])) {
    		$users = $_POST['userids'];
    		if ($users)
    		foreach($users as $user) {
    			approve_user_registration_reject_user($user);
    		}
    	}
    
    }
    
    function approve_user_registration_admin_page() {
    	$bb_waiting_users = new BB_Users_Waiting_Approval( $_GET['userspage'] );
    
    	$bb_waiting_users->title = __('These users are waiting for their account to be approved');
    	$bb_waiting_users->display( false, bb_current_user_can( 'edit_users' ) );
    }
    
    function approve_user_registration_approve_user($user_id) {
    	global $bbdb; 
    
    	$user = defined('BACKPRESS_PATH') ? new BP_User($user_id) : new BB_User($user_id);
    	$user->remove_cap('waitingapproval');
    
    	$options = bb_get_option('approve_user_registration_options');
    
    	$user = bb_get_user($user_id);
    
    	if ($options['send_password_with'] == 'A') {
    
    	$password = wp_generate_password();
    	$user_pass = wp_hash_password( $password );
    
    	$bbdb->update( $bbdb->users,
    		compact( 'user_pass'),
    		array('ID' => $user->ID)
    	);
    	$passtext = sprintf("\nYour password is: %1\$s ",$password);
    	} else {$passtext="";}
    
    	$message = __("Your account has been approved.\n\nYour username is: %1\$s $passtext\n\nYou can now log on: %2\$s \n\nYou can change your password by visiting your user profile edit page.");
    
    	return bb_mail(
    		bb_get_user_email( $user->ID ),
    		bb_get_option('name') . ': ' . __('User Approved'),
    		sprintf( $message, $user->user_login, bb_get_option('uri') )
    	);
    }
    
    function approve_user_registration_reject_user($user_id) {
    	global $bbdb; 
    
    	$user = defined('BACKPRESS_PATH') ? new BP_User($user_id) : new BB_User($user_id);
    	$user->remove_cap('waitingapproval');
    	$user->remove_cap('member');
    	$user->add_cap('blocked');
    
    	$user = bb_get_user($user_id);
    
    	$message = __("Your user %1\$s has been rejected by the administrator.");
    
    	return bb_mail(
    		bb_get_user_email( $user->ID ),
    		bb_get_option('name') . ': ' . __('User Rejected'),
    		sprintf( $message, $user->user_login )
    	);
    }
    
    add_action('bb_admin-footer.php','approve_user_registration_dashboard');
    function approve_user_registration_dashboard() {
    	global $page,$bb_current_menu;
    	$waiting_user = new BB_Users_By_Role( 'waitingapproval' );
    	if($bb_current_menu[0] == 'Dashboard' && $waiting_user->total_users_for_query > 0 ) :
    		?>
    		<div class="wrap"><div class="dashboard left">
    		<h3><?php _e('Users waiting for approval'); ?></h3>
    			<ul>
    		 		<li><a href="<?php echo bb_get_option('path') . 'bb-admin/' . bb_get_admin_tab_link('approve_user_registration_admin_page') ; ?>"><?php echo $waiting_user->total_users_for_query . (($waiting_user->total_users_for_query == 1) ? ' user' : ' users') . ' waiting for approval'; ?></a> </li>
    			</ul>
    		</div></div>
    		<div style="clear: both;"></div>
    		<?php
    	endif;
    }
    ?>
    Posted: 2 years ago #
  3. Thank you for the update tomdebruin. I'm still not getting it to work completely, but it is a lot closer.

    The admin menu does not crash and the Registration Settings page shows up now.

    A user can register and receives the email. However when I go into the Registration Queue page it shows one line with a checkbox to approve the user, but it contains no user information. Here is the HTML source:

    <tbody id='role-'>
    	<tr id='user-'>
    		<td><input type='checkbox' value='' name='userids[]' checked/></td>
    		<td><a href='http://www.brazosvalleygamers.org/board/profile/' style="color: green"></a></span></td>
    		<td><a href='mailto:'></a></td>
    		<td><span style="color: green">12:59:59 / 31-12-1969</span></td>
    
    		<td>346,395 hours</td>
    
    	</tr></tbody>

    In the Admin Users page, it shows the user and it shows the user role as member.

    I tried poking around in the code, but am not familiar enough to figure what's going on other than the user variables are not being populated in this section:

    $r .= "\t<tr id='user-$user->ID'" . get_alt_class("user-$role") . ">\n";
    $r .= "\t\t<td><input type='checkbox' value='$user->ID' name='userids[]' $checked/></td>\n";
    $r .= "\t\t<td><a href='" . get_user_profile_link( $user->ID ) . "' style=" . $reg_compare . ">" . get_user_name( $user->ID ) . "</a></span></td>\n";
    if ( $show_email ) {
    	$email = bb_get_user_email( $user->ID );
    	$r .= "\t\t<td><a href='mailto:$email'>$email</a></td>\n";
    }
    
    $r .= "\t\t<td><span style=" . $reg_compare . ">" . $date_eng . "</span></td>\n";
    $r .= "\t\t<td>" . $hours_ago . " hours</td>\n";
    $r .= "\n\t</tr>";

    Thanks again for your help.

    Posted: 2 years ago #
  4. sorry, there is an error in the updated plugin above.

    I have just fixed it, but I need to do a little bit more work on it to get the styling right.

    Will post it up in the next few days.

    Posted: 2 years ago #
  5. I've updated it. I think it's working OK, but it's been a long day. Let me know how you get on with it.

    http://www.deadlyhifi.com/downloads/approve-user-registration.zip

    and I can't get the paging to butt up to the table nicely, but that's such a big deal.

    Posted: 2 years ago #
  6. @tomdebruin

    Works like a charm! Thanks for your help and all the hours you put into it.

    As a bonus, it appears to be compatible with Human-Test.

    We'll have a three-prong defense against spambots: Human-Test should throttle spambot registrations to a manageable level, Approve User Registration will make sure we look at a new user's profile before they can post, and Akismet will be the last line of defense.

    Of course, this only works for a board that doesn't get a massive amount of legitimate new users on a regular basis.

    Posted: 2 years ago #
  7. I've made it clear in the email that gets sent out that their application will be manually reviewed before their application is successful, and that it should take no more than 24 hours.

    You can change the working that get sent out in the email by changing the text in $message = .

    Every morning first thing I approve my users. After 15 hours they'll be auto ticked so you can just hit 'approve'. It's what works best on our forums. We get an average of 55 subscribers a day and if they've been banned for a while it keeps them in line by them knowing there's no point in quickly subscribing again and them carrying on their trolling, or whatever it is they've been banned for.

    Posted: 2 years ago #
  8. @tomdebruin

    i can't download the plugin from the site you posted above, can you upload it somewhere else, or in some public place :)

    tnx in advance and can't wait to test the plugin :)

    Posted: 2 years ago #
  9. that place is public, what's the issue?
    Anyway, it's also on sendspace for the moment.
    http://www.sendspace.com/pro/dl/ni0atz

    Posted: 2 years ago #
  10. Great work all! Thanks.

    One feature request (that I can't seem to make work with my baby-hack... where can I find bb_mail documentation?):

    An option to send the admin an email when a user requests registration?

    We get so few requests (yet) I'm afraid they'll be missed.

    Cheers!

    Posted: 2 years ago #
  11. citizenkeith

    Member

    Driftless1: Here's what you need:
    http://bbpress.org/plugins/topic/new-user-notification/

    Posted: 2 years ago #
  12. tomdebruin works perfect, tnx man :)

    Posted: 2 years ago #
  13. Great update. Tried this plug in before and it didn't work. The updates are wonderful

    Is there a way I can create lines of text on the "waiting for approval" email it sends out? I changed the wording to fit better, but I want a few more lines of text than one long one.

    Otherwise, its a great plug in.

    Posted: 2 years ago #
  14. bergahmeister

    Member

    I'm having problems with the latest version of this plug-in:

    When a new user registers, the password that is sent initially does not work when they try to log-in. If they submit a "reset password" request, the new password works just fine. This problem doesn't exist when this plug-in is deactivated.

    I'm using 1.0.2.

    http://www.speedweightlossbook.com/club

    Any thoughts? Thanks in advance.

    Posted: 2 years ago #
  15. Shane Pitman

    Member

    bergahmeister: Settings > Registration Settings > change the option to Approval Mail. Now the system won't send the password when the user registers, but will when an admin approves them. That password will work.

    Posted: 2 years ago #
  16. adh11576

    Member

    Has anyone figured out how to prevent users I reject to not appear in the members list? Is there a way to make it so the user is deleted once they are rejected? thanks.

    Posted: 2 years ago #
  17. bergahmeister

    Member

    Thank you Shane!

    Posted: 2 years ago #
  18. dni777

    5 stars
    4 stars
    3 stars
    2 stars
    1 star

    Member

    thank you for updating it
    why don't you post that as the most recent version?

    FYI i also went in and changed the text in this file to reflect the waiting period.

    /kakumai/register-success.php

    "Your registration as xxxxxx was successful. Within a few minutes you should receive an email with your password."

    is there a way for the moderators to get notified that someone is waiting to be approved?

    Posted: 2 years ago #
  19. surfeuse

    Member

    Great plug-in. Thanks!

    Posted: 2 years ago #
  20. I tried this plugin but, if it's active, all users will be registered as Key Master: a big issue!
    Is there something I didn't made correctly during installation or is the bug real?

    Posted: 2 years ago #

RSS feed for this topic

Add a Comment »

You must log in to post.