• Resolved Scholarty

    (@scholarty)


    Hi, I would like to first of thank you for this plugin as with more than 50,000 users will be joining soon, we as admins/moderators did not want to set users per groups manually.

    The question is that:

    1) What is the Meta Data for users to be able to select their own groups at Signup?

    2) We are looking for a solution for Users to chose only ONE group on sign up so maybe radio buttons or drop down would be great.

    3) We are using the Plugin UserPro to manage users which allows us to create a new registration requirement and lets new users choose their groups.

    Let me know if there is a solution to this.

    Thank You

    https://www.ads-software.com/plugins/bbp-private-groups/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Robin W

    (@robin-w)

    thanks for your question.

    1. the user meta is ‘private_group’
    2. The list of groups is held in wp_options under rpg_groups
    3. I don’t know that plugin or how you would code using that

    I hope that information helps, or if not do come back with how I can help further

    Thread Starter Scholarty

    (@scholarty)

    Hi Robin,

    You would not happen to know how to integrate this with WordPress Registration would you?

    For EG: When a user registers, or go into their profile, they can choose their group? But can only be applied once and stops people from jumping forums?

    Thanks

    Plugin Author Robin W

    (@robin-w)

    no easy way to do that – it would need some coding, but is doable.

    How into code are you?

    Thread Starter Scholarty

    (@scholarty)

    Hi Robin,

    I am an advanced coder but no expert. I will see about adding a call to the plugin and adding in the meta to tie into bbp Private Groups Database but I believe that might be going around it the wrong way.

    Thanks

    Plugin Author Robin W

    (@robin-w)

    ok, that’s great – I’m knee deep in setting up a website for a client, or I’d cut some code for you.

    I think the answer is to do it on registration, then they only do it once. Of course whatever method you choose will not stop someone having multiple usernames as long as they have an email address for each, but most will play the game.

    So I think you’ll need a combination of the following

    This code adds first and last name to the registration, so you should be able to alter it to be for adding the group

    /add code for adding first and last name to registration
    
    //1. Add a new form element...
        add_action('register_form','myplugin_register_form');
        function myplugin_register_form (){
            $first_name = ( isset( $_POST['first_name'] ) ) ? $_POST['first_name']: '';
    		$last_name = ( isset( $_POST['last_name'] ) ) ? $_POST['last_name']: '';
            ?>
    		<p>
    		<label for="first_name"><?php _e('First Name  as people call you eg Dave','mydomain') ?><br />
                    <input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr(stripslashes($first_name)); ?>" size="25" /></label>
            </p>
    		<p>
                <label for="last_name"><?php _e('Last Name','mydomain') ?><br />
                    <input type="text" name="last_name" id="last_name" class="input" value="<?php echo esc_attr(stripslashes($last_name)); ?>" size="25" /></label>
            </p>
            <?php
        }
    
        //2. Add validation. In this case, we make sure first_name is required.
        add_filter('registration_errors', 'myplugin_registration_errors', 10, 3);
        function myplugin_registration_errors ($errors, $sanitized_user_login, $user_email) {
    
            if ( empty( $_POST['first_name'] ) )
                $errors->add( 'first_name_error', __('<strong>ERROR</strong>: You must include a first name.','mydomain') );
    		if ( empty( $_POST['last_name'] ) )
                $errors->add( 'last_name_error', __('<strong>ERROR</strong>: You must include a last name.','mydomain') );
    
            return $errors;
        }
    
        //3. Finally, save our extra registration user meta.
        add_action('user_register', 'myplugin_user_register');
        function myplugin_user_register ($user_id) {
            if ( isset( $_POST['first_name'] ) )
                update_user_meta($user_id, 'first_name', $_POST['first_name']);
    		if ( isset( $_POST['last_name'] ) )
                update_user_meta($user_id, 'last_name', $_POST['last_name']);
        }

    This code is the dropdown list from settings, so bits of this is what you’ll need to put in 1. above

    global $rpg_groups ;
    
    	?>
    	 <table class="form-table">
    			<tbody>
    				<tr>
    					<th><label for="bbp-private-groups"><?php esc_html_e( 'Group', 'private-groups' ); ?></label></th>
    					<td>
    
    						<select name="bbp-private-groups" id="group">
    						<?php global $rpg_groups ;
    							if (empty( $rpg_groups ) ) : ?>
    
    							<option value=""><?php esc_html_e( '— No groups yet set up —', 'private-groups' ); ?></option>
    
    							<?php else : ?>
    							<?php $private_group = get_user_meta($user_id, 'private_group', true); ?>
    								<option value="" selected="selected"><?php esc_html_e( '— No group —', 'bbpress' ); ?></option>
    
    							<?php endif; ?>
    
    							<?php foreach ( $rpg_groups as $group => $details ) : ?>
    
    								<option <?php selected( $private_group, $group ); ?> value="<?php echo esc_attr( $group ); ?>"><?php echo $group.' '.$details ; ?></option>
    
    							<?php endforeach; ?>
    
    						</select>
    					</td>
    				</tr>
    
    			</tbody>
    		</table>
    		<?php
    
    		}

    Finally the save part that you’ll need to put in 3 above

    function bbp_edit_user_rpg( $user_id ) {
    	$private_group = ( $_POST['bbp-private-groups'] ) ;
    
    	// Update town user meta
    	if ( !empty( $private_group ) )
    		update_user_meta( $user_id, 'private_group', $private_group);
    
    	// Delete town user meta
    	else
    		delete_user_meta( $user_id, 'private_group' );

    So if you cobble together bits of that, you should be able to get it to work.

    If you do, can I ask a big favour, and that is that you paste the results here, it would be useful code for others.

    If you fail, come back to me in a week or so, and I’ll see if I can cut something for you

    Plugin Author Robin W

    (@robin-w)

    I don’t know if you cracked this, so I’ll mark it as resolved for the moment, but come back if you need further help

    Thread Starter Scholarty

    (@scholarty)

    Hi Robin,

    Sorry I have not replied to this is a while, had to reformat my computer. I was unsuccessful in producing this work around. Would you consider this as a new feature in your upcoming updates?

    Thank You

    edo.suzuki

    (@edosuzuki)

    Hello all. Just for further use, here is the code that Scholarty was talking about. It isn’t gorgeous, but it works! I am using the Name and Last name input fields, but if you doesn’t want them you can remove from 1. and 3. You just need to add it to the functions.php file on your theme. Thanks Scholarty!

    //add code for adding first and last name to registration
    
    //1. Add a new form element...
        add_action('register_form','myplugin_register_form');
        function myplugin_register_form (){
        	global $rpg_groups ;
    
            $first_name = ( isset( $_POST['first_name'] ) ) ? $_POST['first_name']: '';
    		$last_name = ( isset( $_POST['last_name'] ) ) ? $_POST['last_name']: '';
            ?>
    		<p>
    		<label for="first_name"><?php _e('Your name:','your-domain') ?><br />
                    <input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr(stripslashes($first_name)); ?>" size="25" /></label>
            </p>
    		<p>
                <label for="last_name"><?php _e('Last name:','your-domain') ?><br />
                    <input type="text" name="last_name" id="last_name" class="input" value="<?php echo esc_attr(stripslashes($last_name)); ?>" size="25" /></label>
            </p>
    
    	 	<table class="form-table">
    			<tbody>
    				<tr>
    					<th><label for="bbp-private-groups"><?php esc_html_e( 'Group', 'private-groups' ); ?></label></th>
    					<td>
    						<select name="bbp-private-groups" id="group">
    						<?php global $rpg_groups ;
    							if (empty( $rpg_groups ) ) : ?>
    
    							<option value=""><?php esc_html_e( '— No groups yet set up —', 'private-groups' ); ?></option>
    
    							<?php else : ?>
    							<?php $private_group = get_user_meta($user_id, 'private_group', true); ?>
    								<option value="" selected="selected"><?php esc_html_e( '— No group —', 'bbpress' ); ?></option>
    							<?php endif; ?>
    
    							<?php foreach ( $rpg_groups as $group => $details ) : ?>
    								<option <?php selected( $private_group, $group ); ?> value="<?php echo esc_attr( $group ); ?>"><?php echo $group.' '.$details ; ?></option>
    							<?php endforeach; ?>
    						</select>
    					</td>
    				</tr>
    			</tbody>
    		</table>
            <?php
        }
    
        //2. Add validation. In this case, we make sure first_name is required.
        add_filter('registration_errors', 'myplugin_registration_errors', 10, 3);
        function myplugin_registration_errors ($errors, $sanitized_user_login, $user_email) {
    
            if ( empty( $_POST['first_name'] ) )
                $errors->add( 'first_name_error', __('<strong>ERROR</strong>: You must include a first name.','mydomain') );
    		if ( empty( $_POST['last_name'] ) )
                $errors->add( 'last_name_error', __('<strong>ERROR</strong>: You must include a last name.','mydomain') );
    
            return $errors;
        }
    
        //3. Finally, save our extra registration user meta.
        add_action('user_register', 'myplugin_user_register');
        function myplugin_user_register ($user_id) {
            if ( isset( $_POST['first_name'] ) )
                update_user_meta($user_id, 'first_name', $_POST['first_name']);
    		if ( isset( $_POST['last_name'] ) )
                update_user_meta($user_id, 'last_name', $_POST['last_name']);
    
            $private_group = ( $_POST['bbp-private-groups'] ) ;
    		// Update town user meta
    		if ( !empty( $private_group ) )
    			update_user_meta( $user_id, 'private_group', $private_group);
    
    		// Delete town user meta
    		else
    			delete_user_meta( $user_id, 'private_group' );
    	}
    Plugin Author Robin W

    (@robin-w)

    Great – thanks for posting this !

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Let users Choose at Registration’ is closed to new replies.