Saving custom data for each user

Take a look at update_user_meta
you can save user data if they are registering or signed in, its just a matter of what user ID you pass to it.

say in your function to save the user data after he is logged in:

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'])
            }
        }
    } 
}

they to display there notes you can use get_user_meta

function 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;
    }
}

Hope this Helps

Leave a Comment