2013-05-06 58 views
0

在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'); 

帮助将不胜感激。

回答

0

在线路

add_user_meta($the_user, 'rpr_redirect_key', '/hubpage/' . $new_user_name, true); 

$the_user不是ID。请尝试$the_user->ID$user_id而不是