Cimy Extra Fields Not Able to Update User Picture From Front End
-
Hi guys,
I m newbie in WordPress. I wanted custom fields during user registration and for that i have used cimy extra field plugin. Now i want to edit user field from front end. I m successfully updating users extra text fields but i m unable to update users picture field(basically change profile custom picture)
Following is my form which i m using in front end
<form method="post" id="your-profile" action="<?php the_permalink(); ?>" enctype="multipart/form-data"> <table> <tr> <td><label for="first-name"><?php _e('First Name', 'profile'); ?></label></td> <td><input class="text-input" name="first-name" type="text" id="first-name" value="<?php the_author_meta('first_name', $current_user->ID); ?>" /></td> </tr> <tr> <td><label for="last-name"><?php _e('Last Name', 'profile'); ?></label></td> <td><input class="text-input" name="last-name" type="text" id="last-name" value="<?php the_author_meta('last_name', $current_user->ID); ?>" /></td> </tr> <tr> <td><label for="email"><?php _e('Email', 'profile'); ?></label></td> <td><input class="text-input" name="email" type="text" id="email" value="<?php the_author_meta('user_email', $current_user->ID); ?>" /></td> </tr> <tr> <td><label for="url"><?php _e('Website', 'profile'); ?></label></td> <td><input class="text-input" name="url" type="text" id="url" value="<?php the_author_meta('user_url', $current_user->ID); ?>" /></td> </tr> <tr> <td><label for="pass1"><?php _e('Password *', 'profile'); ?> </label></td> <td><input class="text-input" name="pass1" type="password" id="pass1" /></td> </tr> <tr> <td><label for="pass2"><?php _e('Repeat Password *', 'profile'); ?></label></td> <td><input class="text-input" name="pass2" type="password" id="pass2" /></td> </tr> <tr> <td><label for="description"><?php _e('Biographical Information', 'profile') ?></label></td> <td><textarea name="description" id="description" rows="3" cols="50"><?php the_author_meta('description', $current_user->ID); ?></textarea></td> </tr> </table> <?php //action hook for plugin and extra fields do_action('edit_user_profile', $current_user); ?> <p class="form-submit"> <?php // echo $referer; ?> <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>
Below is my code to update user’s data
if (!(function_exists('get_user_to_edit'))) { require_once(ABSPATH . '/wp-includes/user.php'); require_once(ABSPATH . '/wp-admin/includes/user.php'); } $allFields = get_cimyFields(); $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'])); } /* Redirect so the page will show updated info. */ if (count($error) == 0) { //action hook for plugins and extra fields saving do_action('personal_options_update', $current_user->ID); do_action('profile_update', $current_user->ID); foreach ($allFields as $field) { $result = set_cimyFieldValue($current_user->ID, $field["NAME"], $_POST['cimy_uef_' . $field['NAME']]); } do_action('edit_user_profile_update', $current_user->ID); wp_redirect(get_permalink()); exit; } }
- The topic ‘Cimy Extra Fields Not Able to Update User Picture From Front End’ is closed to new replies.