PHP WordPress / BuddyPress添加用户类型
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP WordPress / BuddyPress添加用户类型相关的知识,希望对你有一定的参考价值。
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 );
?>
以上是关于PHP WordPress / BuddyPress添加用户类型的主要内容,如果未能解决你的问题,请参考以下文章
php Wordpress Backdoor添加用户#wordpress #php
php [WORDPRESS] - 脚注中的Wordpress动态版权日期#wp #footer #wordpress#functions.php
php [Wordpress]禁用wordpress评论
php [摘录限制] Poner un limite al extracto en wordpress #wordpress #php
如何安装wordpress?
链接到 archive.php - WordPress