mardi 24 février 2015

update_user_meta not working


I'm trying to add additional profile pages and then allow users to submit custom profile data through the pages. I want this data to be unique to each user and only viewable by that user. The code is below. I have little experience trying to build a plugin like this. When I reload the page, a new data table is created with a blank value. What am I doing wrong?



// Add the admin page
function wpse66004_add_users_page()
{
$user_id = $GLOBALS['wpuserid'];
$user_info = get_userdata($user_id);
$username = $user_info->user_login;
$this_username = $username . 'page1';
add_users_page(
// $page_title
'Your data'
// $menu_title
,'Private Page'
// $capability
,'read'
// $menu_slug
,$this_username
,'my_show_extra_profile_fields'
);
}
add_action( 'admin_menu', 'wpse66004_add_users_page' );

// Render the users private admin page
function my_show_extra_profile_fields( $user_id ) {

$user_id = $GLOBALS['wpuserid'];
$user_info = get_userdata($user_id);
$username = $user_info->user_login;
$this_username = $username . 'page1';
$student_address_up = add_user_meta( $user_id, 'up_address', $_POST['student_address'] );
$student_address_down = get_user_meta( $user_id, 'up_address', true );
?>
<form action="/wp-admin/profile.php?page=<?php echo $this_username ?>" method="post">
<h3>Extra profile information</h3>

<table class="form-table">

<tr>
<th><label for="address">Address</label></th>

<td>
<input type="text" name="address" id="address" value="<?php echo esc_attr( $student_address_up ); ?>" class="regular-text" /><br />
<span class="description">Please enter your address.</span>
</td>
</tr>

</table>
<p>
<input type="submit" name="formSubmit" value="Submit" class="button-primary"/>
</p>
</form>
<?php
if($_POST['formSubmit'] === "Submit")
{
$student_address_up = update_user_meta( $user_id, 'up_address', $_POST['student_address'] );
}
}




Aucun commentaire:

Enregistrer un commentaire