Ticket #16020: 16020.7.diff
File 16020.7.diff, 15.4 KB (added by , 4 years ago) |
---|
-
src/js/_enqueues/admin/user-profile.js
4 4 5 5 /* global ajaxurl, pwsL10n, userProfileL10n */ 6 6 (function($) { 7 var updateLock = false,7 var frame, 8 8 9 updateLock = false, 10 9 11 $pass1Row, 10 12 $pass1, 11 13 $pass2, … … 16 18 $submitButton, 17 19 currentPass; 18 20 21 function calculateImageSelectOptions(attachment, controller) { 22 var control = controller.get( 'control' ), 23 flexWidth = !! parseInt( control.params.flex_width, 10 ), 24 flexHeight = !! parseInt( control.params.flex_height, 10 ), 25 realWidth = attachment.get( 'width' ), 26 realHeight = attachment.get( 'height' ), 27 xInit = parseInt( control.params.width, 10 ), 28 yInit = parseInt( control.params.height, 10 ), 29 ratio = xInit / yInit, 30 xImg = xInit, 31 yImg = yInit, 32 x1, y1, imgSelectOptions; 33 34 controller.set( 'canSkipCrop', false ); 35 36 if ( realWidth / realHeight > ratio ) { 37 yInit = realHeight; 38 xInit = yInit * ratio; 39 } else { 40 xInit = realWidth; 41 yInit = xInit / ratio; 42 } 43 44 x1 = ( realWidth - xInit ) / 2; 45 y1 = ( realHeight - yInit ) / 2; 46 47 imgSelectOptions = { 48 handles: true, 49 keys: true, 50 instance: true, 51 persistent: true, 52 imageWidth: realWidth, 53 imageHeight: realHeight, 54 minWidth: xImg > xInit ? xInit : xImg, 55 minHeight: yImg > yInit ? yInit : yImg, 56 x1: x1, 57 y1: y1, 58 x2: xInit + x1, 59 y2: yInit + y1 60 }; 61 62 if ( flexHeight === false && flexWidth === false ) { 63 imgSelectOptions.aspectRatio = xInit + ':' + yInit; 64 } 65 66 if ( true === flexHeight ) { 67 delete imgSelectOptions.minHeight; 68 imgSelectOptions.maxWidth = realWidth; 69 } 70 71 if ( true === flexWidth ) { 72 delete imgSelectOptions.minWidth; 73 imgSelectOptions.maxHeight = realHeight; 74 } 75 76 return imgSelectOptions; 77 } 78 79 $( function() { 80 /** 81 * Opens the 'choose from library' frame and creates it if it doesn't exist. 82 * 83 * @since 3.5.0 84 * @deprecated 4.1.0 85 * 86 * @return {void} 87 */ 88 $('#choose-from-library-link').click( function( event ) { 89 var $el = $(this); 90 event.preventDefault(); 91 92 var cropControl = { 93 id: "control-id", 94 params : { 95 flex_width : false, 96 flex_height : false, 97 width : 640, 98 height : 640 99 } 100 }; 101 102 // If the media frame already exists, reopen it. 103 if ( frame ) { 104 frame.open(); 105 return; 106 } 107 108 // Create the media frame. 109 frame = wp.media.frames.profilePicture = wp.media({ 110 // Set the title of the modal. 111 title: $el.data('choose'), 112 113 // Tell the modal to show only images. 114 library: { 115 type: 'image' 116 }, 117 118 // Customize the submit button. 119 button: { 120 // Set the text of the button. 121 text: $el.data('update'), 122 // Tell the button not to close the modal, since we're 123 // going to refresh the page when the image is selected. 124 close: false 125 }, 126 127 states: [ 128 new wp.media.controller.Library({ 129 title: $el.data( 'choose' ), 130 library: wp.media.query({ type: 'image' }), 131 multiple: false, 132 date: false, 133 priority: 20, 134 // suggestedWidth: 200, 135 // suggestedHeight: 200 136 }), 137 new wp.media.controller.CustomizeImageCropper({ 138 imgSelectOptions: calculateImageSelectOptions, 139 control: cropControl 140 }) 141 ] 142 }); 143 144 frame.on('cropped', function(croppedImage) { 145 var link = $el.data('updateLink'); 146 147 // Tell the browser to navigate to the crop step. 148 window.location = link + '&file=' + croppedImage.id; 149 }); 150 151 /** 152 * Updates the window location to include the selected attachment. 153 * 154 * @since 3.5.0 155 * @deprecated 4.1.0 156 * 157 * @return {void} 158 */ 159 frame.on( 'select', function() { 160 // Grab the selected attachment. 161 var attachment = frame.state().get('selection').first(); 162 163 frame.setState( 'cropper' ); 164 }); 165 166 frame.open(); 167 }); 168 }); 169 19 170 function generatePassword() { 20 171 if ( typeof zxcvbn !== 'function' ) { 21 172 setTimeout( generatePassword, 50 ); -
src/wp-admin/includes/misc.php
1011 1011 } 1012 1012 1013 1013 /** 1014 * Cleanup a custom avatar 1015 * 1016 * @since 3.5.1 1017 * @param int $attachment_id An attachment ID 1018 */ 1019 function unlink_profile_picture( $attachment_id ) { 1020 $upload_dir = wp_upload_dir(); 1021 $profile_picture = get_post_meta( $attachment_id, '_wp_attachment_profile_picture', true ); 1022 1023 if ( is_array( $profile_picture ) ) { 1024 foreach ( $profile_picture as $file ) { 1025 if ( ! $file['is_reserved'] ) { 1026 $file = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $file['url'] ); 1027 @unlink( $file ); 1028 } 1029 } 1030 } 1031 1032 delete_post_meta( $attachment_id, '_wp_attachment_profile_picture' ); 1033 delete_post_meta( $attachment_id, '_wp_attachment_is_profile_picture' ); 1034 } 1035 1036 /** 1037 * Delete a custom avatar 1038 * 1039 * @since 3.5.1 1040 * @param int $attachment_id An attachment ID 1041 */ 1042 function delete_profile_picture( $attachment_id ) { 1043 $is_profile_picture = get_post_meta( $attachment_id, '_wp_attachment_is_profile_picture', true ); 1044 1045 if ( ! $is_profile_picture ) { 1046 return; 1047 } 1048 1049 unlink_profile_picture( $attachment_id ); 1050 1051 $args = array( 1052 'meta_key' => 'profile_picture', 1053 'meta_value' => $attachment_id 1054 ); 1055 1056 $users = get_users( $args ); 1057 1058 foreach ( $users as $user ) { 1059 delete_user_meta( $user->ID, 'profile_picture' ); 1060 } 1061 } 1062 1063 add_action( 'delete_attachment', 'delete_profile_picture' ); 1064 1065 /** 1014 1066 * @since 3.3.0 1015 1067 */ 1016 1068 function _ipad_meta() { -
src/wp-admin/includes/template.php
2252 2252 $media_states[] = __( 'Logo' ); 2253 2253 } 2254 2254 2255 if ( ! empty( get_post_meta( $post->ID, '_wp_attachment_is_profile_picture', true ) ) ) { 2256 $media_states[] = __( 'Profile Picture' ); 2257 } 2258 2255 2259 /** 2256 2260 * Filters the default media display states for items in the Media list table. 2257 2261 * -
src/wp-admin/user-edit.php
25 25 wp_die( __( 'Invalid user ID.' ) ); 26 26 } 27 27 28 wp_enqueue_media(); 28 29 wp_enqueue_script( 'user-profile' ); 29 30 30 31 if ( IS_PROFILE_PAGE ) { … … 173 174 exit; 174 175 } 175 176 176 // Intentional fall-through to display $errors. 177 case 'set-avatar': 178 check_admin_referer( 'update-user_' . $user_id ); 179 180 if ( ! current_user_can( 'edit_user', $user_id ) ) { 181 wp_die( __( 'Sorry, you are not allowed to edit this user.' ) ); 182 } 183 184 if ( isset( $_GET['file'] ) ) { 185 $attachment_id = absint( $_GET['file'] ); 186 187 $meta_avatar = get_post_meta( $attachment_id, '_wp_attachment_is_profile_picture', true ); 188 189 if ( empty( $meta_avatar ) ) { 190 $profile_picture = array(); 191 192 update_post_meta( $attachment_id, '_wp_attachment_profile_picture', $profile_picture ); 193 update_post_meta( $attachment_id, '_wp_attachment_is_profile_picture', true ); 194 } 195 196 $profile_picture = get_user_meta( $user_id, 'profile_picture', true ); 197 198 if ( ! empty( $profile_picture ) && $profile_picture != $attachment_id ) { 199 delete_profile_picture( $profile_picture ); 200 } 201 202 update_user_meta( $user_id, 'profile_picture', $attachment_id ); 203 } 204 205 $redirect = add_query_arg( 'updated', true, get_edit_user_link( $user_id ) ); 206 207 if ( $wp_http_referer ) { 208 $redirect = add_query_arg( 'wp_http_referer', urlencode( $wp_http_referer ), $redirect); 209 } 210 211 wp_redirect( $redirect ); 212 exit; 213 214 case 'remove-avatar': 215 check_admin_referer( 'update-user_' . $user_id ); 216 217 if ( ! current_user_can( 'edit_user', $user_id ) ) { 218 wp_die( __( 'Sorry, you are not allowed to edit this user.' ) ); 219 } 220 221 $attachment_id = get_user_meta( $user_id, 'profile_picture', true ); 222 223 unlink_profile_picture( $attachment_id ); 224 delete_user_meta( $user_id, 'profile_picture' ); 225 226 $redirect = add_query_arg( 'updated', true, get_edit_user_link( $user_id ) ); 227 228 if ( $wp_http_referer ) { 229 $redirect = add_query_arg( 'wp_http_referer', urlencode( $wp_http_referer ), $redirect); 230 } 231 232 wp_redirect( $redirect ); 233 exit; 234 235 // Intentional fall-through to display $errors. 177 236 default: 178 237 $profileuser = get_user_to_edit( $user_id ); 179 238 … … 577 636 <tr class="user-profile-picture"> 578 637 <th><?php _e( 'Profile Picture' ); ?></th> 579 638 <td> 580 639 <?php echo get_avatar( $user_id ); ?> 581 640 <p class="description"> 582 641 <?php 642 $has_profile_picture = isset( $profileuser->profile_picture ) 643 ? get_post_meta( $profileuser->profile_picture, '_wp_attachment_is_profile_picture', true ) 644 : false; 645 583 646 if ( IS_PROFILE_PAGE ) { 584 $description = sprintf( 585 /* translators: %s: Gravatar URL. */ 586 __( '<a href="%s">You can change your profile picture on Gravatar</a>.' ), 587 __( 'https://en.gravatar.com/' ) 588 ); 647 if ( current_user_can( 'upload_files' ) ) { 648 if ( $has_profile_picture ) { 649 $modal_update_href = esc_attr( add_query_arg( array( 650 'action' => 'set-avatar', 651 'user_id' => $profileuser->ID 652 ), self_admin_url( IS_PROFILE_PAGE ? 'profile.php' : 'user-edit.php' ) ) ); 653 654 $href = esc_attr( add_query_arg( array( 655 'action' => 'remove-avatar', 656 'user_id' => $profileuser->ID 657 ), self_admin_url( IS_PROFILE_PAGE ? 'profile.php' : 'user-edit.php' ) ) ); 658 659 $description = sprintf( 660 __('<a href="#" data-choose="%s" data-update="%s" data-update-link="%s" id="%s">Change profile picture</a>, or <a href="%s" onclick="%s">remove image</a>'), 661 __( 'Select image' ), 662 __( 'Set as profile picture' ), 663 wp_nonce_url( $modal_update_href, 'update-user_' . $profileuser->ID ), 664 'choose-from-library-link', 665 wp_nonce_url( $href, 'update-user_' . $user_id ), 666 'return showNotice.warn();' 667 ); 668 } else { 669 $modal_update_href = esc_attr( add_query_arg( array( 670 'action' => 'set-avatar', 671 'user_id' => $profileuser->ID 672 ), self_admin_url( IS_PROFILE_PAGE ? 'profile.php' : 'user-edit.php' ) ) ); 673 674 $description = sprintf( 675 /* translators: %s: Gravatar URL. */ 676 __( 'You can change your profile picture on <a href="%s" target="_blank">Gravatar</a>, or <a href="#" data-choose="%s" data-update="%s" data-update-link="%s" id="%s">select an image</a>.' ), 677 __( 'https://en.gravatar.com/' ), 678 __( 'Select image' ), 679 __( 'Set as profile picture' ), 680 wp_nonce_url( $modal_update_href, 'update-user_' . $profileuser->ID ), 681 'choose-from-library-link' 682 ); 683 } 684 } else { 685 $description = sprintf( 686 /* translators: %s: Gravatar URL. */ 687 __( '<a href="%s">You can change your profile picture on Gravatar</a>.' ), 688 __( 'https://en.gravatar.com/' ) 689 ); 690 } 589 691 } else { 590 $description = ''; 692 if ( current_user_can( 'upload_files' ) ) { 693 $description = sprintf( 694 '<a href="#">%s</a>', 695 __( 'Upload profile picture' ) 696 ); 697 } else { 698 $description = ''; 699 } 591 700 } 592 701 593 702 /** -
src/wp-includes/link-template.php
4209 4209 } 4210 4210 } 4211 4211 4212 if ( ! $user ) { 4213 if ( $email ) { 4214 $user = get_user_by( 'email', $email ); 4215 } 4216 } 4217 if ( $user ) { 4218 $profile_picture = get_post_meta( $user->profile_picture, '_wp_attachment_profile_picture', true ); 4219 4220 if ( is_array( $profile_picture ) ) { 4221 if ( empty( $profile_picture[ $args['size'] ] ) ) { 4222 $src = wp_get_attachment_image_src( $user->profile_picture, 'full' ); 4223 4224 $profile_picture[ $args['size'] ] = resize_profile_picture( $src[0], $args['size'] ); 4225 4226 update_post_meta( $user->profile_picture, '_wp_attachment_profile_picture', $profile_picture ); 4227 } 4228 4229 $url = $profile_picture[ $args['size'] ]['url']; 4230 4231 /** This filter is documented in wp-includes/link-template.php */ 4232 $args['url'] = apply_filters( 'get_avatar_url', $url, $id_or_email, $args ); 4233 4234 /** This filter is documented in wp-includes/link-template.php */ 4235 return apply_filters( 'get_avatar_data', $args, $id_or_email ); 4236 } 4237 } 4238 4212 4239 if ( ! $email_hash ) { 4213 4240 if ( $user ) { 4214 4241 $email = $user->user_email; -
src/wp-includes/media.php
1768 1768 } 1769 1769 1770 1770 /** 1771 * Resize a custom avatar 1772 * 1773 * @since 3.5.1 1774 * @param string URL to an avatar image to resize 1775 * @param int Size of the new avatar image 1776 * @return array Array with the URL of the new avatar image 1777 */ 1778 function resize_profile_picture( $url, $size ) { 1779 $upload_dir = wp_upload_dir(); 1780 $file = str_replace( $upload_dir['baseurl'], $upload_dir['basedir'], $url ); 1781 $info = pathinfo( $file ); 1782 $dir = $info['dirname']; 1783 $ext = $info['extension']; 1784 $name = wp_basename( $file, ".$ext" ); 1785 $suffix = "{$size}x{$size}"; 1786 $destfilename = "{$dir}/{$name}-{$suffix}.{$ext}"; 1787 $profile_picture = array(); 1788 1789 if ( file_exists( $destfilename ) ) { 1790 $profile_picture['url'] = str_replace( $upload_dir['basedir'], $upload_dir['baseurl'], $destfilename ); 1791 $profile_picture['is_reserved'] = true; 1792 } else { 1793 $file = image_resize( $file, $size, $size, true ); 1794 1795 if ( ! is_wp_error( $file ) ) { 1796 $profile_picture['url'] = str_replace( $upload_dir['basedir'], $upload_dir['baseurl'], $file ); 1797 $profile_picture['is_reserved'] = false; 1798 } 1799 } 1800 1801 return $profile_picture; 1802 } 1803 1804 /** 1771 1805 * Adds a 'wp-post-image' class to post thumbnails. Internal use only. 1772 1806 * 1773 1807 * Uses the {@see 'begin_fetch_post_thumbnail_html'} and {@see 'end_fetch_post_thumbnail_html'} -
src/wp-includes/user.php
1757 1757 */ 1758 1758 $meta['description'] = apply_filters( 'pre_user_description', $description ); 1759 1759 1760 $meta['profile_picture'] = empty( $userdata['profile_picture'] ) ? '' : $userdata['profile_picture']; 1761 1760 1762 $meta['rich_editing'] = empty( $userdata['rich_editing'] ) ? 'true' : $userdata['rich_editing']; 1761 1763 1762 1764 $meta['syntax_highlighting'] = empty( $userdata['syntax_highlighting'] ) ? 'true' : $userdata['syntax_highlighting']; … … 2193 2195 * @return string[] List of user keys to be populated in wp_update_user(). 2194 2196 */ 2195 2197 function _get_additional_user_keys( $user ) { 2196 $keys = array( 'first_name', 'last_name', 'nickname', 'description', ' rich_editing', 'syntax_highlighting', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front', 'locale' );2198 $keys = array( 'first_name', 'last_name', 'nickname', 'description', 'profile_picture', 'rich_editing', 'syntax_highlighting', 'comment_shortcuts', 'admin_color', 'use_ssl', 'show_admin_bar_front', 'locale' ); 2197 2199 return array_merge( $keys, array_keys( wp_get_user_contact_methods( $user ) ) ); 2198 2200 } 2199 2201