php - WordPress - How can I update user meta data outside of the user's profile? I've provided the code I'm using to display -
using user meta data, running function hidden in user’s profile allows them have checklist. i’m using theme login , not including checklist on user’s profile page when edit/view profile.
i trying display checklist on it’s own page. can display can’t seem submit button work. can point me in right direction?
thanks!
code illustration in functions.php:
function my_show_extra_profile_fields( $user ) { ?> <div><input type="checkbox" name="checkbox1" id=" checkbox1 " value="yes" <?php if (esc_attr( get_the_author_meta( "checkbox1", $user->id )) == "yes") echo "checked"; ?> /> checkbox 1 </div> <button type="submit">save</button> <?php } ?> <?php add_action( 'personal_options_update', 'my_save_extra_profile_fields' ); add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' ); function my_save_extra_profile_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) homecoming false; update_usermeta( $user_id, checkbox1, $_post['checkbox1'] ); } ?> code illustration display profile field on page template:
<?php my_show_extra_profile_fields(); ?> edit: forgot '', added them in
you have $_post[checkbox1] should $_post['checkbox1']
assuming created field already, can utilize wp_update_user codex.
$user_id = wp_update_user( array( 'id' => $user_id, 'checkbox1' => $_post['checkbox1'] ) ); if ( is_wp_error( $user_id ) ) { // there error, user doesn't exist. } else { // success! } php wordpress
No comments:
Post a Comment