WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to add functions which will add upload user image options (5 posts)

  1. Amit
    Member
    Posted 7 months ago #

    Hello,

    There are many plugins which are using for upload user photo / image. But I want to upload user photo, facebook url, google+ url and others fields in user profile area.

    I don't like too much plugins. So, Please give me suggestions how I will do it.

    Thanks in advance.

    Regards,
    Amit

  2. john
    Member
    Posted 7 months ago #

    Please add this snippet in your theme functions file...

    function fb_add_custom_user_profile_fields( $user ) {
    ?>
    	<h3><?php _e('Extra Profile Information', 'your_textdomain'); ?></h3>
    
    	<table class="form-table">
    		<tr>
    			<th>
    				<label for="address"><?php _e('Address', 'your_textdomain'); ?>
    			</label></th>
    			<td>
    				<input type="text" name="address" id="address" value="<?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>" class="regular-text" /><br />
    				<span class="description"><?php _e('Please enter your address.', 'your_textdomain'); ?></span>
    			</td>
    		</tr>
    	</table>
    <?php }
    
    function fb_save_custom_user_profile_fields( $user_id ) {
    
    	if ( !current_user_can( 'edit_user', $user_id ) )
    		return FALSE;
    
    	update_usermeta( $user_id, 'address', $_POST['address'] );
    }
    
    add_action( 'show_user_profile', 'fb_add_custom_user_profile_fields' );
    add_action( 'edit_user_profile', 'fb_add_custom_user_profile_fields' );
    
    add_action( 'personal_options_update', 'fb_save_custom_user_profile_fields' );
    add_action( 'edit_user_profile_update', 'fb_save_custom_user_profile_fields' );

    Happy coding!

  3. Amit
    Member
    Posted 7 months ago #

    Thanks John,

    I appreciate for your great help. But I can not show user photo and any others data on author.php page.

    Please can you send ma complete code which have functions.php and author.php scripts.

    I want author image, facebook url upload and show in author page.

    Happy coding!

  4. john
    Member
    Posted 7 months ago #

    Hey amit,

    It is quite simple.
    first put the code of last message in your theme functions file, now it will create a new address field in user profile area.
    how i have created there address field you may create multiple( i.e. -facebook, twitter, linkedin and many more...)

    Use following snippet to show address value for user.
    <?php echo esc_attr( get_the_author_meta( 'address', $user->ID ) ); ?>
    and follow same process for other fields.

    check the link for user avatar
    http://codex.wordpress.org/Function_Reference/get_avatar

    Thanks

  5. Amit
    Member
    Posted 7 months ago #

    Thanks John for your awesome help. I am very happy to do this job.

    Keep well.

Reply

You must log in to post.

About this Topic