Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WP User Manager - Resize avatar uploads to a specific size
<?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;
}
@polevaultweb
Copy link
Author

polevaultweb commented Oct 15, 2019

Alter line 15 to change the dimensions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment