Skip to content

Instantly share code, notes, and snippets.

@polevaultweb
Created October 15, 2019 10:32
Show Gist options
  • Save polevaultweb/caefbec5eaaa9e5f032427adb27251a2 to your computer and use it in GitHub Desktop.
Save polevaultweb/caefbec5eaaa9e5f032427adb27251a2 to your computer and use it in GitHub Desktop.
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

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