-
-
Save venturaEffect/49a4a607893f33c3e029dc8fdb0c52c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Template Name: User Profile | |
| * | |
| * Allow users to update their profiles from Frontend. | |
| * | |
| */ | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; // Exit if accessed directly. | |
| } | |
| /* ADDED code to create the profile form for channels */ | |
| /* Get user info. */ | |
| global $current_user, $wp_roles; | |
| //get_currentuserinfo(); //deprecated since 3.1 | |
| /* Load the registration file. */ | |
| //require_once( ABSPATH . WPINC . '/registration.php' ); //deprecated since 3.1 | |
| $error = array(); | |
| /* 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.', 'profile'); | |
| } | |
| /* Update user information. */ | |
| if ( !empty( $_POST['url'] ) ) | |
| wp_update_user( array( 'ID' => $current_user->ID, 'user_url' => esc_url( $_POST['url'] ) ) ); | |
| if ( !empty( $_POST['email'] ) ){ | |
| if (!is_email(esc_attr( $_POST['email'] ))) | |
| $error[] = __('The Email you entered is not valid. please try again.', 'profile'); | |
| elseif(email_exists(esc_attr( $_POST['email'] )) != $current_user->id ) | |
| $error[] = __('This email is already used by another user. try a different one.', 'profile'); | |
| else{ | |
| wp_update_user( array ('ID' => $current_user->ID, 'user_email' => esc_attr( $_POST['email'] ))); | |
| } | |
| } | |
| if ( !empty( $_POST['first-name'] ) ) | |
| update_user_meta( $current_user->ID, 'first_name', esc_attr( $_POST['first-name'] ) ); | |
| if ( !empty( $_POST['last-name'] ) ) | |
| update_user_meta($current_user->ID, 'last_name', esc_attr( $_POST['last-name'] ) ); | |
| if ( !empty( $_POST['description'] ) ) | |
| update_user_meta( $current_user->ID, 'description', esc_attr( $_POST['description'] ) ); | |
| if ( !empty( $_POST['channel_name'] ) ) | |
| update_user_meta( $current_user->ID, 'channel_name', esc_attr( $_POST['channel_name'] ) ); | |
| if ( !empty( $_POST['pic'] ) ) | |
| update_user_meta( $current_user->ID, 'pic', esc_attr( $_POST['pic'] ) ); | |
| if ( !empty( $_POST['description_channel'] ) ) | |
| update_user_meta( $current_user->ID, 'description_channel', esc_attr( $_POST['description_channel'] ) ); | |
| /* Redirect so the page will show updated info.*/ | |
| /*I am not Author of this Code- i dont know why but it worked for me after changing below line to if ( count($error) == 0 ){ */ | |
| if ( !$error ) { | |
| wp_redirect( get_permalink() .'?updated=true' ); | |
| exit; | |
| } | |
| } | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; // Exit if accessed directly. | |
| } | |
| /* UNTIL HERE */ | |
| get_header(); | |
| /* HERE AGAIN, ADDED code to create the profile form for channels */ | |
| if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> | |
| <div id="post-<?php the_ID(); ?>"> | |
| <div class="entry-content entry"> | |
| <?php the_content(); ?> | |
| <?php if ( !is_user_logged_in() ) : ?> | |
| <p class="warning"> | |
| <?php _e('You must log in <a href="https://stokednomads.com/login">here</a> to edit your profile.', 'profile'); ?> | |
| </p><!-- .warning --> | |
| <?php else : ?> | |
| <?php if ( count($error) > 0 ) echo '<p class="error">' . implode("<br />", $error) . '</p>'; ?> | |
| <form method="post" id="adduser" action="<?php the_permalink(); ?>"> | |
| <p class="form-email" style="display:none;"> | |
| <label for="email"><?php _e('E-mail *', 'profile'); ?></label> | |
| <input class="text-input" name="email" type="text" id="email" value="<?php the_author_meta( 'user_email', $current_user->ID ); ?>" /> | |
| </p><!-- .form-email --> | |
| <?php | |
| //action hook for plugin and extra fields | |
| do_action('edit_user_profile',$current_user); | |
| ?> | |
| <p class="form-submit"> | |
| <input name="updateuser" type="submit" id="updateuser" class="submit button" value="<?php _e('Update', 'profile'); ?>" /> | |
| <?php wp_nonce_field( 'update-user' ) ?> | |
| <input name="action" type="hidden" id="action" value="update-user" /> | |
| </p><!-- .form-submit --> | |
| </form><!-- #adduser --> | |
| <?php endif; ?> | |
| </div><!-- .entry-content --> | |
| </div><!-- .hentry .post --> | |
| <?php endwhile; ?> | |
| <?php else: ?> | |
| <p class="no-data"> | |
| <?php _e('Sorry, no page matched your criteria.', 'profile'); ?> | |
| </p><!-- .no-data --> | |
| <?php endif; ?> | |
| <?php get_footer(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment