I want to make custom edit profile template without plugin
-
i am try to coding custom profile edit template but it is not updating meta value i can’t find out where is error please help me
page-profile.php
<?php /** * Template Name: Edit Profile Page * */ /* Get user info. */ global $current_user, $wp_roles; get_currentuserinfo(); /* Load the registration file. */ require_once( ABSPATH . WPINC . '/registration.php' ); require_once( ABSPATH . 'wp-admin/includes' . '/template.php' ); // this is only for the selected() function /* If profile was saved, update profile. */ if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == 'update-user' ) { /* Update user password. */ if ( !empty($_POST['pass1'] ) && !empty( $_POST['pass2'] ) ) { if ( $_POST['pass1'] == $_POST['pass2'] ) wp_update_user( array( 'ID' => $current_user->id, 'user_pass' => esc_attr( $_POST['pass1'] ) ) ); else $error = __('The passwords you entered do not match. Your password was not updated.', 'mytheme'); } /* Update user information. */ update_usermeta( $current_user->id, 'first_name', esc_attr( $_POST['first_name'] ) ); update_usermeta( $current_user->id, 'last_name', esc_attr( $_POST['last_name'] ) ); if ( !empty( $_POST['email'] ) ) update_usermeta( $current_user->id, 'user_email', esc_attr( $_POST['email'] ) ); update_usermeta( $user_id, 'gender', $_POST['gender'] ); update_usermeta( $user_id, 'height', $_POST['height'] ); update_usermeta( $user_id, 'weight', $_POST['weight'] ); update_usermeta( $user_id, 'coach_name', $_POST['coach_name'] ); update_usermeta( $user_id, 'coach_phone', $_POST['coach_phone'] ); if ( !$error ) { wp_redirect( get_permalink() ); exit; } } // calling the header.php get_header(); ?> <div class="container content"> <?php if ( !is_user_logged_in() ) : ?> <p class="warning"> <?php _e('You must be logged in to edit your profile.', 'mytheme'); ?> </p><!-- .warning --> <?php else : ?> <?php if ( $error ) echo '<p class="error">' . $error . '</p>'; ?> <form method="post" id="edituser" class="sky-form" action="<?php the_permalink(); ?>"> <header>Athlete Bio</header> <fieldset> <section> <label class="label" for="first_name"><?php _e('First Name', $current_user->id ); ?></label> <label class="input"> <input type="text" name="first_name" id="first_name" value="<?php the_author_meta( 'first_name', $current_user->id ); ?>" > </label> </section> <!-- first name --> <section> <label class="label" for="height">Last name</label> <label class="input"> <input type="text" name="last_name" type="text" id="last_name" value="<?php the_author_meta( 'last_name', $current_user->id ); ?>" > </label> </section> <!-- last name --> <section> <label class="label" for="gender">Gender</label> <div class="inline-group"> <label class="radio"><input type="radio" name="radio-inline" <?php if ($gender == 'Male' ) { ?>checked="checked"<?php }?> value="Male"><i></i>Male</label> <label class="radio"><input type="radio" name="radio-inline" <?php if ($gender == 'Female' ) { ?>checked="checked"<?php }?> value="Female"><i></i>Female</label> </div> </section> <!-- sex --> <section> <label class="label" for="height">Height</label> <label class="input"> <input type="text" name="height" id="height" value="<?php the_author_meta( 'height', $current_user->id ); ?>"> </label> </section> <!-- Height --> <section> <label class="label" for="weight">Weight</label> <label class="input"> <input type="text" name="weight" id="weight" value="<?php the_author_meta( 'weight', $current_user->id ); ?>"> </label> </section> <!-- Weight --> <section> <label class="label" for="coach_name">Coach Name</label> <label class="input"> <input type="text" name="coach_name" id="coach_name" value="<?php the_author_meta( 'coach_name', $current_user->id ); ?>"> </label> </section> <!-- Coach Name --> <section> <label class="label" for="coach_phone">Coach’s Phone</label> <label class="input"> <input type="text" name="coach_phone" id="coach_phone" value="<?php the_author_meta( 'coach_phone', $current_user->id ); ?>"> </label> </section> <!-- Coach’s Phone --> </fieldset> <footer> <?php echo $referer; ?> <input name="updateuser" type="submit" id="updateuser" class="submit button" value="<?php _e('Update', 'mytheme'); ?>" /> <?php wp_nonce_field( 'update-user' ', $current_user->id ); ?> <input name="action" type="hidden" id="action" value="update-user" /> <input type="hidden" name="action" value="update" /> <input type="hidden" name="user_id" id="user_id" value="<?php the_author_meta( 'user_id); ?>" /> </footer> </form> <?php endif; ?> <div class="clearfix"></div> </div> <?php get_footer(); ?>
functions.php
<?php add_action( 'show_user_profile', 'show_extra_profile_fields', 10 ); add_action( 'edit_user_profile', 'show_extra_profile_fields', 10 ); function show_extra_profile_fields( $user ) { ?> <header>Athlete Bio</header> <fieldset> <section> <label class="label" for="gender">Gender</label> <div class="inline-group"> <label class="radio"><input type="radio" name="radio-inline" <?php if ($gender == 'Male' ) { ?>checked="checked"<?php }?> value="Male"><i></i>Male</label> <label class="radio"><input type="radio" name="radio-inline" <?php if ($gender == 'Female' ) { ?>checked="checked"<?php }?> value="Female"><i></i>Female</label> </div> </section> <!-- sex --> <section> <label class="label" for="height">Height</label> <label class="input"> <input type="text" name="height" id="height" value="<?php get_the_author_meta( 'height', $current_user->ID ); ?>"> </label> </section> <!-- Height --> <section> <label class="label" for="weight">Weight</label> <label class="input"> <input type="text" name="weight" id="weight" value="<?php get_the_author_meta( 'weight', $current_user->ID ); ?>"> </label> </section> <!-- Weight --> <section> <label class="label" for="coach_name">Coach Name</label> <label class="input"> <input type="text" name="coach_name" id="coach_name" value="<?php get_the_author_meta( 'coach_name', $current_user->ID ); ?>"> </label> </section> <!-- Coach Name --> <section> <label class="label" for="coach_phone">Coach’s Phone</label> <label class="input"> <input type="text" name="coach_phone" id="coach_phone" value="<?php get_the_author_meta( 'coach_phone', $current_user->ID ); ?>"> </label> </section> <!-- Coach’s Phone --> </fieldset> <?php } add_action( 'personal_options_update', 'save_extra_profile_fields' ); add_action( 'edit_user_profile_update', 'save_extra_profile_fields' ); function save_extra_profile_fields( $user_id ) { if ( !current_user_can( 'edit_user', $user_id ) ) return false; update_usermeta( $user_id, 'gender', $_POST['gender'] ); update_usermeta( $user_id, 'height', $_POST['height'] ); update_usermeta( $user_id, 'weight', $_POST['weight'] ); update_usermeta( $user_id, 'coach_name', $_POST['coach_name'] ); update_usermeta( $user_id, 'coach_phone', $_POST['coach_phone'] ); }
- The topic ‘I want to make custom edit profile template without plugin’ is closed to new replies.