Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function my_show_extra_profile_fields( $user ) { ?>
- <h3 style="margin-bottom:20px;">ваш аватар</h3>
- <div id="avatar">
- <img src="<?php if(esc_attr( get_the_author_meta( 'foto', $user->ID ) )!='')
- echo get_bloginfo('home').'/wp-content/uploads/avatars/'.esc_attr(get_the_author_meta('foto', $user->ID ));
- else
- echo get_bloginfo('home').'/wp-content/themes/j2/images/avatar.jpg'; ?>" width="100" alt="Аватар" style="float:left;margin-right:15px;">
- <input type="file" value="" name="foto" id="foto" /><br/>
- <span>Новый аватар должен иметь<br> размер 100x100px и быть не <br> больше 50kb, иначе он не <br>загрузится.</span>
- <br clear="all" />
- <input type="submit" class="avatar-save" value="Обновить аватар" name="submit" />
- </div>
- <?php }
- add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
- add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
- function my_add_form_enctype() {
- echo ' enctype="multipart/form-data"';
- }
- add_action('user_edit_form_tag', 'my_add_form_enctype');
- add_action('show_user_profile', 'my_show_extra_profile_fields');
- add_action('edit_user_profile', 'my_show_extra_profile_fields');
- function my_save_extra_profile_fields( $user_id ) {
- global $my_error_messages;
- if ( !current_user_can( 'edit_user', $user_id ) )
- return false;
- $image = $_FILES['foto']['tmp_name'];
- if ( empty($image) )
- return false;
- $image_info = GetImageSize($image);
- if ( ($_FILES["foto"]["size"] <= 50*1024) and ($image_info[0]<101) and ($image_info[1]<101) )
- {
- move_uploaded_file($image, ABSPATH . get_option('upload_path').'/avatars/'.md5($image));
- update_usermeta($user_id, 'foto', md5($image) );
- } else {
- $my_error_messages = array();
- if ( ($image_info[0]>100) or ($image_info[1]>10) )
- $my_error_messages[] = '<strong>ОШИБКА</strong>: Размер аватара превышает 100x100px!';
- if ( $_FILES["foto"]["size"] > 50*1024 )
- $my_error_messages[] = '<strong>ОШИБКА</strong>: Размер аватара превышает 50kb!';
- }
- }
- function my_update_errors($errors) {
- global $my_error_messages;
- foreach ( (array) $my_error_messages as $error_message )
- $errors->add( 'avatar', $error_message);
- return $errors;
- }
- add_action('user_profile_update_errors', 'my_update_errors');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement