L
L
ligisayan2016-04-01 10:22:14
HTML
ligisayan, 2016-04-01 10:22:14

How to add the ability to upload an avatar when registering a user on a wordpress site?

Good afternoon. In the topic , I posted an answer on how to add additional registration fields in the installed plugin Theme My Login . Now I'm thinking about the possibility of adding and saving a user's avatar. With the addition, the issue was resolved as follows:

<h3>Загрузка аватарки</h3>
        <?php echo get_simple_local_avatar( $profileuser->ID ); ?>
        <?php
          if ( ! $upload_rights = current_user_can('upload_files') )
            $upload_rights = empty( $this->options['caps'] );
        
          if ( $upload_rights ) {
            do_action( 'simple_local_avatar_notices' ); 
            wp_nonce_field( 'simple_local_avatar_nonce', '_simple_local_avatar_nonce', false );
        ?>

        <p>
          <input type="file" name="simple-local-avatar" id="upload_hidden" onchange="document.getElementById('upload_visible').value = this.value;" />
          <button type="button" id="review" onclick="document.getElementById('upload_hidden').click();">Выбрать</button>
        </p>

            <p>
              <?php if ( current_user_can( 'upload_files' ) && did_action( 'wp_enqueue_media' ) ) : ?><a href="#" class="button hide-if-no-js" id="simple-local-avatar-media"><?php _e( 'Choose from Media Library', 'simple-local-avatars' ); ?></a> &nbsp;<?php endif; ?>

            </p>
        <?php
          } else {
            if ( empty( $profileuser->simple_local_avatar ) )
              echo '<span class="description">' . __('No local avatar is set. Set up your avatar at Gravatar.com.','simple-local-avatars') . '</span>';
            else 
              echo '<span class="description">' . __('You do not have media management permissions. To change your local avatar, contact the blog administrator.','simple-local-avatars') . '</span>';
          }
        ?>

How to save it now?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Ninja Mate, 2016-04-02
@ligisayan

Here is my code, I hope you understand and make your own version.
Paste at once the floor of your piece of code.

<?php }
add_action( 'show_user_profile', 'show_profile_fields' );
add_action( 'edit_user_profile', 'show_profile_fields' );
//Save User Team option
function save_profile_fields( $user_id ) {
    if (!current_user_can('edit_user', $user_id ))
        return false;
    update_user_meta( $user_id, 'squad', $_POST['squad'] );
    update_user_meta( $user_id, 'facility', $_POST['facility'] );
}

add_action( 'personal_options_update', 'save_profile_fields' );
add_action( 'edit_user_profile_update', 'save_profile_fields' );

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question