Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @package
- *
- * SUBSCRIBER FORM
- * (https://wordpress.stackexchange.com/a/9786/86024)
- *
- */
- /* Get user info. */
- global $current_user, $wp_roles;
- $current_user = wp_get_current_user();
- //get_currentuserinfo(); //deprecated since 3.1
- $wp_http_referer = remove_query_arg(array('update', 'delete_count', 'user_id'), $wp_http_referer);
- /* 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['display_name'])) {
- update_user_meta($current_user->ID, 'display_name', esc_attr($_POST['display_name']));
- }
- }
- ?>
- <?php
- if (!is_user_logged_in()) {
- wp_redirect(get_bloginfo('url'));
- exit;
- }
- ?>
- <div class="logged-in-form text-center px-0 px-md-3">
- <div class="container-fluid mb-3">
- <div class="row">
- <div class="col-3">
- <!-- Subscriber Avatar -->
- <img class="rounded-circle img-thumbnail mb-2" src="<?php echo get_wp_user_avatar_src(get_the_author_meta('ID')); ?>" alt="" />
- </div>
- <div class="col-9 text-left">
- <!-- Subscriber Name -->
- <small class="d-block font-weight-bold">Hello</small>
- <h3 class="text-uppercase text-secondary mt-0 mb-2 font-weight-bolder"><?php echo $current_user->first_name ?></h3>
- <small class="mt-2 d-block font-weight-bold">Email: <?php echo esc_attr($current_user->user_email); ?></small>
- </div>
- </div>
- </div>
- <form id="your-profile" action="<?php echo admin_url() . 'user-edit.php'; ?>" method="post" novalidate="novalidate"
- <?php do_action('user_edit_form_tag'); ?>
- >
- <?php wp_nonce_field('update-user_' . $user_id); ?>
- <?php if ($wp_http_referer) : ?>
- <input type="hidden" name="wp_http_referer" value="<?php echo esc_url($wp_http_referer); ?>" />
- <?php endif; ?>
- <p>
- <input type="hidden" name="from" value="profile" />
- <input type="hidden" name="checkuser_id" value="<?php echo get_current_user_id(); ?>" />
- </p>
- <div class="container-fluid">
- <div class="row">
- <!-- FISRT NAME -->
- <div class="col-12 mb-2">
- <label class="sr-only" for="first-name">First Name</label>
- <div class="input-group mb-2 mr-sm-2">
- <div class="input-group-prepend">
- <div class="input-group-text bg-light font-weight-bold">First Name</div>
- </div>
- <input id="first-name" class="form-control font-weight-bolder px-2" name="first-name" type="text" value="<?php the_author_meta('first_name', $current_user->ID); ?>" disabled="disabled"/>
- </div>
- </div>
- <!-- LAST NAME -->
- <div class="col-12 mb-2">
- <label class="sr-only" for="last-name">Last Name</label>
- <div class="input-group mb-2 mr-sm-2">
- <div class="input-group-prepend">
- <div class="input-group-text bg-light font-weight-bold">Last Name</div>
- </div>
- <input id="last-name" class="form-control font-weight-bolder px-2" name="first-name" type="text" value="<?php the_author_meta('last_name', $current_user->ID); ?>" disabled="disabled"/>
- </div>
- </div>
- <!-- DISPLAY NAME -->
- <div class="col-12 mb-2">
- <label class="sr-only" for="last-name">Display Name</label>
- <div class="input-group mb-2 mr-sm-2">
- <div class="input-group-prepend">
- <div class="input-group-text bg-light font-weight-bold">Nicename </div>
- </div>
- <select id="display_name" class="custom-select font-weight-bolder" name="display_name">
- <?php
- $public_display = array();
- $public_display['display_nickname'] = $current_user->nickname;
- $public_display['display_username'] = $current_user->user_login;
- if (!empty($current_user->first_name)) {
- $public_display['display_firstname'] = $current_user->first_name;
- }
- if (!empty($current_user->last_name)) {
- $public_display['display_lastname'] = $current_user->last_name;
- }
- if (!empty($current_user->first_name) && !empty($current_user->last_name)) {
- $public_display['display_firstlast'] = $current_user->first_name . ' ' . $current_user->last_name;
- $public_display['display_lastfirst'] = $current_user->last_name . ' ' . $current_user->first_name;
- }
- if (!in_array($current_user->display_name, $public_display, true)) { // Only add this if it isn't duplicated elsewhere.
- $public_display = array('display_displayname' => $current_user->display_name) + $public_display;
- }
- $public_display = array_map('trim', $public_display);
- $public_display = array_unique($public_display);
- foreach ($public_display as $id => $item) {
- ?>
- <option <?php selected($current_user->display_name, $item); ?>><?php echo $item; ?></option>
- <?php
- }
- ?>
- </select>
- </div>
- </div>
- </div>
- </div>
- <?php
- // action hook for plugin, custom and extra fields
- // do_action('edit_user_profile', $current_user);
- ?>
- <div class="d-flex justify-content-center mt-2">
- <button id="updateuser" name="updateuser" type="submit" class="btn btn-outline-primary font-weight-bold mr-2"/><?php _e('Update Profile', 'text_domain'); ?></button>
- <?php wp_nonce_field('update-user') ?>
- <a href="<?php echo wp_logout_url("index.php"); ?>"type="button" class="btn btn-outline-secondary font-weight-bold ml-2">Log Out</a>
- </div>
- <input type="hidden" name="action" value="update" />
- <input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr($current_user->ID); ?>" />
- </form><!-- #adduser -->
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement