0

I'm using the Theme My Login plugin and trying to allow subscribers to change their profiles to one uploaded from their computer.

I've tried the following plugins:

  • Simple Local Avatars
  • User Avatar
  • WP User Avatar
  • Avatar manager

I can get the file upload form to appear, but when clicking upload or update profile, the avatar does not change.

Is there a way I can achieve this?

Here is the whole of my 'Theme my login' profile code with 'Simple Local Avatars'

<div class="login profile" id="theme-my-login<?php $template->the_instance(); ?>">
             <?php $template->the_action_template_message( 'profile' ); ?>
             <?php $template->the_errors(); ?>
             <form id="your-profile" action="<?php $template->the_action_url( 'profile' ); ?>" method="post" class="validate"<?php do_action( 'user_new_form_tag' );?>>
                <?php wp_nonce_field( 'update-user_' . $current_user->ID ); ?>
                <p>
                   <input type="hidden" name="from" value="profile" />
                   <input type="hidden" name="checkuser_id" value="<?php echo $current_user->ID; ?>" />
                </p>

                <?php if ( has_action( 'personal_options' ) ) : ?>

                <h3><?php _e( 'Personal Options' ); ?></h3>

                <table class="form-table">
                <?php do_action( 'personal_options', $profileuser ); ?>
                </table>

                <?php endif; ?>

                <?php do_action( 'profile_personal_options', $profileuser ); ?>

                <h3 class="nomargin"><?php _e( 'Name' ); ?></h3>

                <table class="form-table">
                <tr>
                   <th><label for="user_login"><?php _e( 'Username' ); ?></label></th>
                   <td><input type="text" name="user_login" id="user_login" value="<?php echo esc_attr( $profileuser->user_login ); ?>" disabled="disabled" class="regular-text" /> <span class="description"><?php _e( 'Your username cannot be changed.', 'theme-my-login' ); ?></span></td>
                </tr>

                <tr>
                   <th><label for="first_name"><?php _e( 'First Name' ); ?></label></th>
                   <td><input type="text" name="first_name" id="first_name" value="<?php echo esc_attr( $profileuser->first_name ); ?>" class="regular-text" /></td>
                </tr>

                <tr>
                   <th><label for="last_name"><?php _e( 'Last Name' ); ?></label></th>
                   <td><input type="text" name="last_name" id="last_name" value="<?php echo esc_attr( $profileuser->last_name ); ?>" class="regular-text" /></td>
                </tr>

                <tr>
                   <th><label for="nickname"><?php _e( 'Nickname' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
                   <td><input type="text" name="nickname" id="nickname" value="<?php echo esc_attr( $profileuser->nickname ); ?>" class="regular-text" /></td>
                </tr>

                <tr>
                   <th><label for="display_name"><?php _e( 'Display name publicly as' ); ?></label></th>
                   <td>
                      <select name="display_name" id="display_name">
                      <?php
                         $public_display = array();
                         $public_display['display_nickname']  = $profileuser->nickname;
                         $public_display['display_username']  = $profileuser->user_login;

                         if ( ! empty( $profileuser->first_name ) )
                            $public_display['display_firstname'] = $profileuser->first_name;

                         if ( ! empty( $profileuser->last_name ) )
                            $public_display['display_lastname'] = $profileuser->last_name;

                         if ( ! empty( $profileuser->first_name ) && ! empty( $profileuser->last_name ) ) {
                            $public_display['display_firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
                            $public_display['display_lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
                         }

                         if ( ! in_array( $profileuser->display_name, $public_display ) )// Only add this if it isn't duplicated elsewhere
                            $public_display = array( 'display_displayname' => $profileuser->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( $profileuser->display_name, $item ); ?>><?php echo $item; ?></option>
                      <?php
                         }
                      ?>
                      </select>
                   </td>
                </tr>
                </table>

                <h3 class="nomargin addmargintop20"><?php _e( 'Contact Info' ); ?></h3>

                <table class="form-table">
                <tr>
                   <th><label for="email"><?php _e( 'E-mail' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th>
                   <td><input type="text" name="email" id="email" value="<?php echo esc_attr( $profileuser->user_email ); ?>" class="regular-text" /></td>
                </tr>

                <tr>
                   <th><label for="url"><?php _e( 'Website' ); ?></label></th>
                   <td><input type="text" name="url" id="url" value="<?php echo esc_attr( $profileuser->user_url ); ?>" class="regular-text code" /></td>
                </tr>

                <?php
                   foreach ( _wp_get_user_contactmethods() as $name => $desc ) {
                ?>
                <tr>
                   <th><label for="<?php echo $name; ?>"><?php echo apply_filters( 'user_'.$name.'_label', $desc ); ?></label></th>
                   <td><input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr( $profileuser->$name ); ?>" class="regular-text" /></td>
                </tr>
                <?php
                   }
                ?>
                </table>

                <h3 class="nomargin addmargintop20"><?php _e( 'About Yourself' ); ?></h3>

                <table class="form-table">
                <tr>
                   <th><label for="description"><?php _e( 'Biographical Info' ); ?></label></th>
                   <td><textarea name="description" id="description" rows="5" cols="30"><?php echo esc_html( $profileuser->description ); ?></textarea><br />
                   <span class="description"><?php _e( 'Share a little biographical information to fill out your profile. This may be shown publicly.' ); ?></span></td>
                </tr>

                <?php
                $show_password_fields = apply_filters( 'show_password_fields', true, $profileuser );
                if ( $show_password_fields ) :
                ?>
                <tr id="password">
                   <th><label for="pass1"><?php _e( 'New Password' ); ?></label></th>
                   <td><input type="password" name="pass1" id="pass1" size="16" value="" autocomplete="off" /> <span class="description"><?php _e( 'If you would like to change the password type a new one. Otherwise leave this blank.' ); ?></span><br />
                      <input type="password" name="pass2" id="pass2" size="16" value="" autocomplete="off" /> <span class="description"><?php _e( 'Type your new password again.' ); ?></span><br />
                      <div id="pass-strength-result"><?php _e( 'Strength indicator', 'theme-my-login' ); ?></div>
                      <p class="description indicator-hint"><?php _e( 'Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).' ); ?></p>
                   </td>
                </tr>
                <?php endif; ?>
                </table>

               <?php
                 global $current_user;
                 get_currentuserinfo();
                 $myAv = new simple_local_avatars();
                 $myAv->edit_user_profile($current_user);
               ?>


                <p class="submit">
                   <input type="hidden" name="action" value="profile" />
                   <input type="hidden" name="instance" value="<?php $template->the_instance(); ?>" />
                   <input type="hidden" name="user_id" id="user_id" value="<?php echo esc_attr( $current_user->ID ); ?>" />
                   <input type="submit" class="button-primary kopa-button blue-button small-button" value="<?php esc_attr_e( 'Update Profile' ); ?>" name="submit" />
                </p>


             </form>

          </div>
  • Is there any particular reason you can't link to the gravatar upload page? – Tom J Nowell Sep 9 '14 at 15:41
  • Hi @TomJNowell I'm not sure what the gravatar upload page is? But I want the avatar change to happen on the profile page, without going anywhere else. I want to keep things simple and also mobile device compatible :) – Chris Sep 9 '14 at 15:46
2

I also use Simple Local Avatars with Theme my login . I have had the same problem. My solution is very simple .Check form in profile-form.php template directory. And add enctype attribute to form (enctype="multipart/form-data" )

0

Okay, I think I've got it working using the WP User Avatar plugin.

I added this to Theme My Login's profile-form.php, copied to the root of my theme folder.

<?php
   global $current_user;
   get_currentuserinfo();
   do_action('edit_user_avatar', $current_user);
?>

Then I added this to my functions.php file:

function my_avatar_filter() {
  // Remove from show_user_profile hook
  remove_action('show_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
  remove_action('show_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts'));

  // Remove from edit_user_profile hook
  remove_action('edit_user_profile', array('wp_user_avatar', 'wpua_action_show_user_profile'));
  remove_action('edit_user_profile', array('wp_user_avatar', 'wpua_media_upload_scripts'));

  // Add to edit_user_avatar hook
  add_action('edit_user_avatar', array('wp_user_avatar', 'wpua_action_show_user_profile'));
  add_action('edit_user_avatar', array('wp_user_avatar', 'wpua_media_upload_scripts'));
}

// Loads only outside of administration panel
if(!is_admin()) {
  add_action('init','my_avatar_filter');}

Everything seems to work as expected :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.