Created
October 15, 2019 10:32
-
-
Save polevaultweb/caefbec5eaaa9e5f032427adb27251a2 to your computer and use it in GitHub Desktop.
WP User Manager - Resize avatar uploads to a specific size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'wpum_upload_file_pre_upload', 'wpum_resize_avatar_images', 10, 2 ); | |
function wpum_resize_avatar_images( $file, $args ) { | |
if ( ! isset( $args['file_key'] ) || 'user_avatar' !== $args['file_key'] ) { | |
return $file; | |
} | |
$editor = wp_get_image_editor( $file['tmp_name'] ); | |
if ( is_wp_error( $editor ) ) { | |
return $file; | |
} | |
$editor->set_quality( 90 ); | |
$editor->resize( 100, 100 ); // (int) max width, (int) max height[, (bool) crop] | |
$tmp_file = $file['tmp_name']; | |
$file_data = $editor->save( $tmp_file ); | |
rename( $file_data['path'], $tmp_file ); | |
return $file; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alter line 15 to change the dimensions