WordPress/BuddyPress添加用户类型
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WordPress/BuddyPress添加用户类型相关的知识,希望对你有一定的参考价值。
I used this plugin to create new roles/capabilities: http://wordpress.org/extend/plugins/capsman/
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 ); ?>
以上是关于WordPress/BuddyPress添加用户类型的主要内容,如果未能解决你的问题,请参考以下文章
wordpress buddypress 2.6.1.1 激活邮件修改