[英]Update User Meta after Registration
在wordpress中,用户注册后,我正在使用下面的功能创建两种不同自定义帖子类型的两个页面,然后需要在他们的用户数据中存储一个自定义元值,以帮助以后进行重定向。 我发现,如果我在注册过程中(在注册表格上)指定了自定义元值,以后可以使用以下方法检索这些值:
global $current_user;
get_currentuserinfo();
$theirRedirectKey = $current_user->rpr_redirect_key;
但是,在以下functions.php代码段中,我无法保存元值以供以后检索。
function after_registration($user_id){
// Get the Newly Created User ID
$the_user = get_userdata($user_id);
// Get the Newly Created User Name
$new_user_name = $the_user->user_login;
// Create a unique Tour Code Prefix from User ID
$tourPrefix = $the_user->ID;
// Check for Tour Code Key if entered into registration form
$enteredKey = $the_user->rpr_redirect_key;
if($enteredKey == ''){
//Create the first Tour Builder Page
$tourBuilder = array();
$tourBuilder['post_title'] = $new_user_name . '| Custom Educational Tour';
// Next line may not be important after hubpages are set up.
$tourBuilder['post_name'] = 'builder-' . $tourPrefix;
$tourBuilder['post_type'] = 'builder';
$tourBuilder['post_content'] = 'This is the content!';
$tourBuilder['post_author'] = $user_id;
$tourBuilder['post_status'] = 'publish';
$tour_id = wp_insert_post( $tourBuilder );
// Build hubpage
$hubpage = array();
$hubpage['post_title'] = $new_user_name . '\'s Hubpage';
// URL must be unique
$hubpage['post_name'] = $new_user_name;
$hubpage['post_type'] = 'hubpages';
$hubpage['post_author'] = $user_id;
$hubpage['post_status'] = 'publish';
$hub_id = wp_insert_post( $hubpage );
//Update User with proper redirect keys for some reason this line doesn't work.
add_user_meta($the_user, 'rpr_redirect_key', '/hubpage/' . $new_user_name, true);
}
}
add_action('user_register', 'after_registration');
帮助将不胜感激。
在行中
add_user_meta( $the_user, 'rpr_redirect_key', '/hubpage/' . $new_user_name, true);
$the_user
不是ID。 试试$the_user->ID
或$user_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.