Ticket #16020: 16020.diff

File 16020.diff, 16.3 KB (added by cdog, 8 months ago)
  • wp-includes/user.php

     
    13161316                $last_name = ''; 
    13171317        $last_name = apply_filters('pre_user_last_name', $last_name); 
    13181318 
     1319        if ( empty( $avatar_type ) || $avatar_type != 'custom' ) 
     1320                $avatar_type = 'gravatar'; 
     1321 
     1322        if ( empty( $custom_avatar ) ) 
     1323                $custom_avatar = array(); 
     1324 
     1325        if ( empty( $custom_avatar_rating ) || ! in_array( $custom_avatar_rating, array( 'G', 'PG', 'R', 'X' ) ) ) 
     1326                $custom_avatar_rating = 'G'; 
     1327 
     1328        if ( empty( $has_custom_avatar ) ) 
     1329                $has_custom_avatar = false; 
     1330        $has_custom_avatar = (bool) $has_custom_avatar; 
     1331 
    13191332        if ( empty($description) ) 
    13201333                $description = ''; 
    13211334        $description = apply_filters('pre_user_description', $description); 
     
    14821495 * @return array 
    14831496 */ 
    14841497function _get_additional_user_keys( $user ) { 
    1485         $keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front' ); 
     1498        $keys = array( 'first_name', 'last_name', 'nickname', 'description', 'rich_editing', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front', 'avatar_type', 'custom_avatar', 'custom_avatar_rating', 'has_custom_avatar' ); 
    14861499        return array_merge( $keys, array_keys( _wp_get_user_contactmethods( $user ) ) ); 
    14871500} 
    14881501 
  • wp-includes/formatting.php

     
    27712771                                $value = absint( $value ); 
    27722772                        break; 
    27732773 
     2774                case 'avatar_size': 
     2775                        $value = absint( $value ); 
     2776                        if ( $value < 1 ) 
     2777                                $value = 1; 
     2778                        elseif ( $value > 512 ) 
     2779                                $value = 512; 
     2780                        break; 
     2781 
    27742782                case 'posts_per_page': 
    27752783                case 'posts_per_rss': 
    27762784                        $value = (int) $value; 
  • wp-includes/pluggable.php

     
    15791579 * @param int $size Size of the avatar image 
    15801580 * @param string $default URL to a default image to use if no avatar is available 
    15811581 * @param string $alt Alternate text to use in image tag. Defaults to blank 
     1582 * @param string $avatar_type Override user preference (Used in user-edit.php) 
    15821583 * @return string <img> tag for the user's avatar 
    15831584*/ 
    1584 function get_avatar( $id_or_email, $size = '96', $default = '', $alt = false ) { 
     1585function get_avatar( $id_or_email, $size = '', $default = '', $alt = false, $avatar_type = '' ) { 
    15851586        if ( ! get_option('show_avatars') ) 
    15861587                return false; 
    15871588 
     
    15901591        else 
    15911592                $safe_alt = esc_attr( $alt ); 
    15921593 
    1593         if ( !is_numeric($size) ) 
    1594                 $size = '96'; 
     1594        if ( empty( $size ) || ! is_numeric( $size ) ) { 
     1595                $size = get_option( 'avatar_size' ); 
     1596        } else { 
     1597                $size = absint( $size ); 
    15951598 
     1599                if ( $size < 1 ) 
     1600                        $size = 1; 
     1601                elseif ( $size > 512 ) 
     1602                        $size = 512; 
     1603        } 
     1604  
     1605        if ( ! empty( $avatar_type ) ) 
     1606                if ( $avatar_type != 'custom' ) 
     1607                        $avatar_type = 'gravatar'; 
     1608 
    15961609        $email = ''; 
    15971610        if ( is_numeric($id_or_email) ) { 
    15981611                $id = (int) $id_or_email; 
     
    16171630                $email = $id_or_email; 
    16181631        } 
    16191632 
     1633        if ( isset( $user ) ) { 
     1634                if ( empty( $avatar_type ) ) 
     1635                        $avatar_type = $user->avatar_type; 
     1636 
     1637                if ( ! $user->has_custom_avatar ) 
     1638                        $avatar_type = 'gravatar'; 
     1639        } else { 
     1640                $avatar_type = 'gravatar'; 
     1641        } 
     1642 
    16201643        if ( empty($default) ) { 
    16211644                $avatar_default = get_option('avatar_default'); 
    16221645                if ( empty($avatar_default) ) 
     
    16501673        elseif ( strpos($default, 'http://') === 0 ) 
    16511674                $default = add_query_arg( 's', $size, $default ); 
    16521675 
    1653         if ( !empty($email) ) { 
    1654                 $out = "$host/avatar/"; 
    1655                 $out .= $email_hash; 
    1656                 $out .= '?s='.$size; 
    1657                 $out .= '&amp;d=' . urlencode( $default ); 
     1676        $img = "<img alt='{$safe_alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />"; 
     1677  
     1678        if ( $avatar_type == 'custom' ) { 
     1679                $rating = get_option( 'avatar_rating' ); 
    16581680 
     1681                if ( ! in_array( $rating, array( 'G', 'PG', 'R', 'X' ) ) ) { 
     1682                        break; 
     1683                } else { 
     1684                        $ratings['G'] = 1; 
     1685                        $ratings['PG'] = 2; 
     1686                        $ratings['R'] = 3; 
     1687                        $ratings['X'] = 4; 
     1688 
     1689                        if ( $ratings[ $user->custom_avatar_rating ] <= $ratings[ $rating ] ) { 
     1690                                if ( empty( $user->custom_avatar[ $size ] ) ) { 
     1691                                        $upload_dir = wp_upload_dir(); 
     1692                                        $file = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $user->custom_avatar['full'] ); 
     1693                                        $file = image_resize( $file, $size, $size, true ); 
     1694 
     1695                                        if ( is_wp_error( $file ) ) { 
     1696                                                $src = $user->custom_avatar['full']; 
     1697                                        } else { 
     1698                                                $custom_avatar = $user->custom_avatar; 
     1699                                                $custom_avatar[ $size ] = str_replace( $upload_dir['basedir'], $upload_dir['baseurl'], $file ); 
     1700                                                $src = $custom_avatar[ $size ]; 
     1701 
     1702                                                update_user_meta( $user->ID, 'custom_avatar', $custom_avatar ); 
     1703                                        } 
     1704                                } else { 
     1705                                        $src = $user->custom_avatar[ $size ]; 
     1706                                } 
     1707 
     1708                                $img = "<img alt='{$safe_alt}' src='{$src}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />"; 
     1709                        } 
     1710                } 
     1711        } else if ( !empty($email) ) { 
     1712                $src = "$host/avatar/"; 
     1713                $src .= $email_hash; 
     1714                $src .= '?s='.$size; 
     1715                $src .= '&amp;d=' . urlencode( $default ); 
     1716 
    16591717                $rating = get_option('avatar_rating'); 
    16601718                if ( !empty( $rating ) ) 
    1661                         $out .= "&amp;r={$rating}"; 
     1719                        $src .= "&amp;r={$rating}"; 
    16621720 
    1663                 $avatar = "<img alt='{$safe_alt}' src='{$out}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />"; 
    1664         } else { 
    1665                 $avatar = "<img alt='{$safe_alt}' src='{$default}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />"; 
     1721                $img = "<img alt='{$safe_alt}' src='{$src}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />"; 
    16661722        } 
    16671723 
    1668         return apply_filters('get_avatar', $avatar, $id_or_email, $size, $default, $alt); 
     1724        return apply_filters('get_avatar', $img, $id_or_email, $size, $default, $alt, $avatar_type); 
    16691725} 
    16701726endif; 
    16711727 
  • wp-admin/includes/schema.php

     
    482482 
    483483        // 3.5 
    484484        'link_manager_enabled' => 0, 
     485        'avatar_size' => 96 
    485486        ); 
    486487 
    487488        // 3.3 
  • wp-admin/includes/user.php

     
    9494                $user->rich_editing = isset( $_POST['rich_editing'] ) && 'false' == $_POST['rich_editing'] ? 'false' : 'true'; 
    9595                $user->admin_color = isset( $_POST['admin_color'] ) ? sanitize_text_field( $_POST['admin_color'] ) : 'fresh'; 
    9696                $user->show_admin_bar_front = isset( $_POST['admin_bar_front'] ) ? 'true' : 'false'; 
     97                $user->avatar_type = isset( $_POST['avatar_type'] ) ? sanitize_text_field( $_POST['avatar_type'] ) : 'gravatar'; 
     98                $user->custom_avatar = $userdata->custom_avatar; 
     99                $user->has_custom_avatar = $userdata->has_custom_avatar; 
     100                $user->custom_avatar_rating = isset( $_POST['custom_avatar_rating'] ) ? sanitize_text_field( $_POST['custom_avatar_rating'] ) : 'G'; 
     101 
     102                if ( isset( $_POST['uploadavatar'] ) && $_POST['uploadavatar'] ) { 
     103                        $upload_dir = wp_upload_dir(); 
     104 
     105                        if ( is_array( $user->custom_avatar ) && $user->has_custom_avatar ) { 
     106                                foreach ( $user->custom_avatar as $custom_avatar ) { 
     107                                        $file = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $custom_avatar ); 
     108                                        @unlink( $file ); 
     109                                } 
     110                        } 
     111 
     112                        $mimes = array( 
     113                                'bmp'   =>  'image/bmp', 
     114                                'gif'   =>  'image/gif', 
     115                                'jpeg'  =>  'image/jpeg', 
     116                                'jpg'   =>  'image/jpeg', 
     117                                'jpe'   =>  'image/jpeg', 
     118                                'png'   =>  'image/png', 
     119                                'tiff'  =>  'image/tiff', 
     120                                'tif'   =>  'image/tiff' 
     121                        ); 
     122 
     123                        $overrides = array( 'mimes' => $mimes, 'test_form' => false ); 
     124                        $file = wp_handle_upload( $_FILES['import'], $overrides ); 
     125 
     126                        if ( isset( $file['error'] ) ) 
     127                                wp_die( $file['error'],  __( 'Image Upload Error' ) ); 
     128 
     129                        $user->avatar_type = 'custom'; 
     130                        $user->custom_avatar = array( 'full' => $file['url'] ); 
     131 
     132                        $size = get_option( 'avatar_size' ); 
     133                        $file = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $user->custom_avatar['full'] ); 
     134                        $file = image_resize( $file, $size, $size, true ); 
     135 
     136                        if ( ! is_wp_error( $file ) ) 
     137                                $user->custom_avatar[ $size ] = str_replace( $upload_dir['basedir'], $upload_dir['baseurl'], $file ); 
     138 
     139                        $user->custom_avatar_rating = 'G'; 
     140                        $user->has_custom_avatar = true; 
     141                } 
     142 
     143                if ( isset( $_POST['removeavatar'] ) && $_POST['removeavatar'] ) { 
     144                        if ( is_array( $user->custom_avatar ) ) { 
     145                                $upload_dir = wp_upload_dir(); 
     146 
     147                                foreach ( $user->custom_avatar as $custom_avatar ) { 
     148                                        $file = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $custom_avatar ); 
     149                                        @unlink( $file ); 
     150                                } 
     151                        } 
     152 
     153                        $user->avatar_type = 'gravatar'; 
     154                        $user->custom_avatar = array(); 
     155                        $user->custom_avatar_rating = 'G'; 
     156                        $user->has_custom_avatar = false; 
     157                } 
    97158        } 
    98159 
    99160        $user->comment_shortcuts = isset( $_POST['comment_shortcuts'] ) && 'true' == $_POST['comment_shortcuts'] ? 'true' : ''; 
  • wp-admin/options-discussion.php

     
    243243 
    244244</fieldset></td> 
    245245</tr> 
     246<tr valign="top"> 
     247        <th scope="row"><?php _e( 'Avatar Size' ) ?></th> 
     248        <td> 
     249                <fieldset> 
     250                        <legend class="screen-reader-text"><span><?php _e( 'Avatar Size' ); ?></span></legend> 
     251                        <label> 
     252                                <?php _e( 'Size of the avatar image' ); ?> 
     253                                <input name="avatar_size" type="number" step="1" min="0" value="<?php form_option( 'avatar_size' ); ?>" class="small-text" /> 
     254                        </label> 
     255                </fieldset> 
     256        </td> 
     257</tr> 
    246258<?php do_settings_fields('discussion', 'avatars'); ?> 
    247259</table> 
    248260 
  • wp-admin/options.php

     
    6060 
    6161$whitelist_options = array( 
    6262        'general' => array( 'blogname', 'blogdescription', 'gmt_offset', 'date_format', 'time_format', 'start_of_week', 'timezone_string' ), 
    63         'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration' ), 
     63        'discussion' => array( 'default_pingback_flag', 'default_ping_status', 'default_comment_status', 'comments_notify', 'moderation_notify', 'comment_moderation', 'require_name_email', 'comment_whitelist', 'comment_max_links', 'moderation_keys', 'blacklist_keys', 'show_avatars', 'avatar_rating', 'avatar_default', 'avatar_size', 'close_comments_for_old_posts', 'close_comments_days_old', 'thread_comments', 'thread_comments_depth', 'page_comments', 'comments_per_page', 'default_comments_page', 'comment_order', 'comment_registration' ), 
    6464        'media' => array( 'thumbnail_size_w', 'thumbnail_size_h', 'thumbnail_crop', 'medium_size_w', 'medium_size_h', 'large_size_w', 'large_size_h', 'image_default_size', 'image_default_align', 'image_default_link_type', 'embed_autourls', 'embed_size_w', 'embed_size_h' ), 
    6565        'reading' => array( 'posts_per_page', 'posts_per_rss', 'rss_use_excerpt', 'show_on_front', 'page_on_front', 'page_for_posts', 'blog_public' ), 
    6666        'writing' => array( 'default_post_edit_rows', 'use_smilies', 'default_category', 'default_email_category', 'use_balanceTags', 'default_link_category', 'default_post_format' ) 
  • wp-admin/user-edit.php

     
    189189} ?> 
    190190</h2> 
    191191 
    192 <form id="your-profile" action="<?php echo esc_url( self_admin_url( IS_PROFILE_PAGE ? 'profile.php' : 'user-edit.php' ) ); ?>" method="post"<?php do_action('user_edit_form_tag'); ?>> 
     192<form enctype="multipart/form-data" id="your-profile" action="<?php echo esc_url( self_admin_url( IS_PROFILE_PAGE ? 'profile.php' : 'user-edit.php' ) ); ?>" method="post"<?php do_action('user_edit_form_tag'); ?>> 
    193193<?php wp_nonce_field('update-user_' . $user_id) ?> 
    194194<?php if ( $wp_http_referer ) : ?> 
    195195        <input type="hidden" name="wp_http_referer" value="<?php echo esc_url($wp_http_referer); ?>" /> 
     
    362362?> 
    363363</table> 
    364364 
     365<h3><?php _e( 'Avatar' ); ?></h3> 
     366 
     367<?php 
     368$avatar_type = isset( $profileuser->avatar_type ) ? $profileuser->avatar_type : 'gravatar'; 
     369$custom_avatar_rating = isset( $profileuser->custom_avatar_rating ) ? $profileuser->custom_avatar_rating : 'G'; 
     370$has_custom_avatar = isset( $profileuser->has_custom_avatar ) ? $profileuser->has_custom_avatar : false; 
     371?> 
     372 
     373<table class="form-table"> 
     374<tr> 
     375        <th><?php _e( 'Display this avatar' ); ?></th> 
     376        <td class="avatar-picker"> 
     377                <fieldset> 
     378                        <legend class="screen-reader-text"><span><?php _e( 'Display this avatar' ); ?></span></legend> 
     379                        <label> 
     380                                <input <?php checked( $avatar_type, 'gravatar' ); ?> name="avatar_type" type="radio" value="gravatar" /> 
     381                                <?php echo get_avatar( $profileuser->ID, 32, '', false, 'gravatar' ); ?> 
     382                                <?php _e( 'Gravatar' ); ?> 
     383                                <span class="description"><?php _e( '<a href="http://codex.wordpress.org/How_to_Use_Gravatars_in_WordPress" target="_blank">More information</a>' ); ?></span> 
     384                        </label> 
     385                        <?php if ( $has_custom_avatar ) : ?> 
     386                        <br /> 
     387                        <label> 
     388                                <input <?php checked( $avatar_type, 'custom' ); ?> name="avatar_type" type="radio" value="custom" /> 
     389                                <?php echo get_avatar( $profileuser->ID, 32, '', false, 'custom' ); ?> 
     390                                <?php _e( 'Custom' ); ?> 
     391                        </label> 
     392                        <?php endif; ?> 
     393                </fieldset> 
     394        </td> 
     395</tr> 
     396<tr> 
     397        <th><?php _e( 'Select Image' ); ?></th> 
     398        <td> 
     399                <fieldset> 
     400                        <legend class="screen-reader-text"><span><?php _e( 'Select Image' ); ?></span></legend> 
     401                        <label class="description" for="upload">Choose an image from your computer:</label><br /> 
     402                        <input name="import" type="file" /> 
     403                        <?php submit_button( __( 'Upload' ), 'button', 'uploadavatar', false ); ?> 
     404                </fieldset> 
     405        </td> 
     406</tr> 
     407<?php if ( $has_custom_avatar ) : ?> 
     408<tr> 
     409        <th><?php _e( 'Avatar Rating' ); ?></th> 
     410        <td> 
     411                <fieldset> 
     412                        <legend class="screen-reader-text"><span><?php _e( 'Avatar Rating' ); ?></span></legend> 
     413                        <?php 
     414                        $ratings = array( 
     415                                /* translators: Content suitability rating: http://bit.ly/89QxZA */ 
     416                                'G' => __( 'G &#8212; Suitable for all audiences' ), 
     417                                /* translators: Content suitability rating: http://bit.ly/89QxZA */ 
     418                                'PG' => __( 'PG &#8212; Possibly offensive, usually for audiences 13 and above' ), 
     419                                /* translators: Content suitability rating: http://bit.ly/89QxZA */ 
     420                                'R' => __( 'R &#8212; Intended for adult audiences above 17' ), 
     421                                /* translators: Content suitability rating: http://bit.ly/89QxZA */ 
     422                                'X' => __( 'X &#8212; Even more mature than above' ) 
     423                        ); 
     424 
     425                        foreach ( $ratings as $key => $rating ) { 
     426                                $selected = ( $custom_avatar_rating == $key ) ? 'checked="checked"' : ''; 
     427                                echo '<label><input ' . $selected . ' name="custom_avatar_rating" type="radio" value="' . esc_attr( $key ) . '" /> ' . $rating . '</label><br />'; 
     428                        }; 
     429                        ?> 
     430                        <span class="description"><?php _e( 'Choose a rating for your custom avatar.' ); ?></span> 
     431                </fieldset> 
     432        </td> 
     433</tr> 
     434<tr> 
     435        <th><?php _e( 'Remove Image' ); ?></th> 
     436        <td> 
     437                <legend class="screen-reader-text"><span><?php _e( 'Remove Image' ); ?></span></legend> 
     438                <?php submit_button( __( 'Remove Avatar Image' ), 'button', 'removeavatar', false ); ?> 
     439                <span class="description"><?php _e( 'This will remove the avatar image. You will not be able to restore any customizations.' ); ?></span> 
     440        </td> 
     441</tr> 
     442<?php endif; ?> 
     443</table> 
     444 
    365445<h3><?php IS_PROFILE_PAGE ? _e('About Yourself') : _e('About the user'); ?></h3> 
    366446 
    367447<table class="form-table"> 
  • wp-admin/css/wp-admin.css

     
    47864786        width: 15em; 
    47874787} 
    47884788 
     4789#profile-page .avatar-picker img { 
     4790        margin: 2px 0; 
     4791        vertical-align: middle; 
     4792} 
     4793 
    47894794#createuser .form-field input { 
    47904795        width: 25em; 
    47914796}