Return to Snippet

Revision: 29241
at October 8, 2010 05:30 by seafae


Updated Code
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 = array();
   	$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 = array();
   	$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 );
?>

Revision: 29240
at September 16, 2010 06:41 by seafae


Updated Code
Put this in the BuddyPress theme /registration/register.php file:
<label>Account Type:</label>
<select>
    <option value="student">Student</option>
    <option value="employer">Employer</option>
    <option value="group">Group</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);

// change user role on registration

function register_role($user_id, $password, $meta) {

	global $bp, $wpdb;

   	$userdata = array();
   	$userdata['ID'] = $user_id;
   	$userdata['role'] = $meta[signup_type];

   	//only allow if user role is my_role

   	if ($userdata['role'] == 'student' || $userdata['role'] == 'employer' || $userdata['role'] == 'group' ){
      	wp_update_user($userdata);
   	}
}

add_action('wpmu_activate_user', 'register_role', 10, 3);
?>

Revision: 29239
at July 27, 2010 03:56 by seafae


Updated Code
Put this in the BuddyPress theme /registration/register.php file:
<label>Account Type:</label>
<select>
    <option>Student</option>
    <option>Employer</option>
    <option>Group</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);

// change user role on registration

function register_role($user_id, $password, $meta) {

	global $bp, $wpdb;

   	$userdata = array();
   	$userdata['ID'] = $user_id;
   	$userdata['role'] = $meta[signup_type];

   	//only allow if user role is my_role

   	if ($userdata['role'] == 'student' || $userdata['role'] == 'employer' || $userdata['role'] == 'group' ){
      	wp_update_user($userdata);
   	}
}

add_action('wpmu_activate_user', 'register_role', 10, 3);
?>

Revision: 29238
at July 27, 2010 03:55 by seafae


Updated Code
Put in the BuddyPress theme /registration/register.php file:
<label>Account Type:</label>
<select>
    <option>Student</option>
    <option>Employer</option>
    <option>Group</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);

// change user role on registration

function register_role($user_id, $password, $meta) {

	global $bp, $wpdb;

   	$userdata = array();
   	$userdata['ID'] = $user_id;
   	$userdata['role'] = $meta[signup_type];

   	//only allow if user role is my_role

   	if ($userdata['role'] == 'student' || $userdata['role'] == 'employer' || $userdata['role'] == 'group' ){
      	wp_update_user($userdata);
   	}
}

add_action('wpmu_activate_user', 'register_role', 10, 3);
?>

Revision: 29237
at July 27, 2010 03:52 by seafae


Updated Code
<?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);

// change user role on registration

function register_role($user_id, $password, $meta) {

	global $bp, $wpdb;

   	$userdata = array();
   	$userdata['ID'] = $user_id;
   	$userdata['role'] = $meta[signup_type];

   	//only allow if user role is my_role

   	if ($userdata['role'] == 'student' || $userdata['role'] == 'employer' || $userdata['role'] == 'group' ){
      	wp_update_user($userdata);
   	}
}

add_action('wpmu_activate_user', 'register_role', 10, 3);
?>

Revision: 29236
at July 24, 2010 03:35 by seafae


Initial Code
<?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' );

add_action('wpmu_activate_user', 'register_role');

function register_role($user_id, $password="", $meta=array()) {

   $userdata = array();
   $userdata['ID'] = $user_id;
   $userdata['role'] = $_POST['signup_type'];

   //only allow if user role is my_role

   if ($userdata['role'] == 'student' || $userdata['role'] == 'employer' || $userdata['role'] == 'group' ){
      wp_update_user($userdata);
   }
}

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);
?>

Initial URL

                                

Initial Description
I used this plugin to create new roles/capabilities: http://wordpress.org/extend/plugins/capsman/

Initial Title
WordPress/BuddyPress Add User Types

Initial Tags
wordpress

Initial Language
PHP