/ Published in: PHP
I used this plugin to create new roles/capabilities: http://wordpress.org/extend/plugins/capsman/
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Put this in the BuddyPress theme /registration/register.php file: <label>Account Type:</label> <select> <option value="optiona">Option A</option> <option value="optionb">Option B</option> <option value="optionc">Option C</option> </select> Put the following code in your theme's functions.php <?php /* Add sign-up field to BuddyPress sign-up array*/ function bp_custom_user_signup_field( $usermeta ) { $usermeta['signup_type'] = $_POST['signup_type']; return $usermeta; } add_filter( 'bp_signup_usermeta', 'bp_custom_user_signup_field' ); /* Add field_name from sign-up to usermeta on activation */ function bp_user_activate_field( $signup ) { update_usermeta( $signup['user_id'], 'signup_type', $signup['meta']['signup_type'] ); return $signup; } add_filter( 'bp_core_activate_account', 'bp_user_activate_field' ); function synchro_wp_usermeta($user_id, $password, $meta) { global $bp, $wpdb; $type = $meta[signup_type]; update_usermeta( $user_id, 'signup_type', $type ); } add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3); function synchro_wp_usermeta_blog($blog_id, $user_id, $domain, $path, $site_id, $meta) { global $bp, $wpdb; $type = $meta[signup_type]; update_usermeta( $user_id, 'signup_type', $type ); } add_action( 'wpmu_new_blog', 'synchro_wp_usermeta_blog', 10, 6 ); // change user role on registration function register_role($user_id, $password, $meta) { global $bp, $wpdb; $userdata['ID'] = $user_id; $userdata['role'] = $meta['signup_type']; //only allow if user role is my_role if ($userdata['role'] == 'optiona' || $userdata['role'] == 'optionb' || $userdata['role'] == 'optionc' ){ wp_update_user($userdata); } } add_action('wpmu_activate_user', 'register_role', 10, 3); function register_role_blog($blog_id, $user_id, $domain, $path, $site_id, $meta) { global $bp, $wpdb; $userdata['ID'] = $user_id; $userdata['role'] = $meta['signup_type']; //only allow if user role is my_role if ($userdata['role'] == 'optiona' || $userdata['role'] == 'optionb' || $userdata['role'] == 'optionc' ){ wp_update_user($userdata); } } add_action( 'wpmu_new_blog', 'register_role_blog', 101, 6 ); ?>