看看update_user_meta如果用户正在注册或登录,您可以保存用户数据,这只是您传递给它的用户ID的问题。
在登录后保存用户数据的功能中说:
function save_user_data_7231(){
global $current_user;
if is_user_logged_in{ //check if user is logged in.
if (isset($_POST[\'Notes\'])){
// get current user info
get_currentuserinfo();
$old_notes = get_user_meta($current_user->ID, \'user_notes\', true);
if (isset($old_notes)&& is_array($old_notes)){
//if we saved already more the one notes
$old_notes[] = $_POST[\'Notes\'];
update_user_meta( $current_user->ID, \'user_notes\', $old_notes);
}
if (isset($old_notes)&& !is_array($old_notes)){
//if we saved only one note before
$new_notes = array($old_notes,$_POST[\'Notes\']);
update_user_meta( $current_user->ID, \'user_notes\', $new_notes)
}
if (!isset($old_notes)){
//first note we are saving fr this user
update_user_meta( $current_user->ID, \'user_notes\', $_POST[\'Notes\'])
}
}
}
}
它们将显示您可以使用的注释
get_user_metafunction get_user_notes_654(){
global $current_user;
if is_user_logged_in{ //check if user is logged in.
// get current user info
get_currentuserinfo();
$old_notes = get_user_meta($current_user->ID, \'user_notes\', true);
if (!isset($old_notes)){
$re = \'No Notes YET!\';
}
if (isset($old_notes)){//we have notes. Removed the extra ! here.
if (is_array($old_notes)){//more then one
foreach($old_notes as $note){
$re .= \'<strong>note:</strong>\' . $note . \'<br />\';
}
}else{//just one
$re = \'<strong>note:</strong>\' . $old_notes . \'<br />\';
}
}
re .=\'//add note form would come here\';
return $re;
}
}
希望这有帮助