Merge remote-tracking branch 'remotes/origin/feature/rotate_uploaded_image'

This commit is contained in:
nikitasinelnikov
2020-07-31 00:46:09 +03:00
3 changed files with 63 additions and 9 deletions
+15 -9
View File
@@ -177,8 +177,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
$wp_usermeta_option = get_option( 'um_usermeta_fields', array() );
$count = $wpdb->get_var(
"SELECT COUNT(*)
FROM {$wpdb->usermeta}
"SELECT COUNT(*)
FROM {$wpdb->usermeta}
WHERE meta_key IN ('" . implode( "','", $wp_usermeta_option ) . "')"
);
@@ -194,8 +194,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
global $wpdb;
$metadata = $wpdb->get_results( $wpdb->prepare(
"SELECT *
FROM {$wpdb->usermeta}
"SELECT *
FROM {$wpdb->usermeta}
WHERE meta_key IN ('" . implode( "','", $wp_usermeta_option ) . "')
LIMIT %d, %d",
( absint( $_POST['page'] ) - 1 ) * $per_page,
@@ -209,7 +209,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
if ( ! empty( $values ) ) {
$wpdb->query(
"INSERT INTO
"INSERT INTO
{$wpdb->prefix}um_metadata(user_id, um_key, um_value)
VALUES " . implode( ',', $values ) );
}
@@ -775,6 +775,12 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
'show_default_number' => 1,
),
array(
'id' => 'image_fix_orientation',
'type' => 'checkbox',
'label' => __( 'Fix image orientation','ultimate-member' ),
'tooltip' => __( 'Rotate image to fix orientation by the camera Exif data.','ultimate-member'),
),
array(
'id' => 'image_compression',
'type' => 'text',
@@ -1903,7 +1909,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
if ( ! empty( $_POST['um_options']['use_gravatars'] ) ) {
$results = $wpdb->get_col(
"SELECT u.ID FROM {$wpdb->users} AS u
"SELECT u.ID FROM {$wpdb->users} AS u
LEFT JOIN {$wpdb->usermeta} AS um ON ( um.user_id = u.ID AND um.meta_key = 'synced_gravatar_hashed_id' )
LEFT JOIN {$wpdb->usermeta} AS um2 ON ( um2.user_id = u.ID AND um2.meta_key = 'um_member_directory_data' )
WHERE um.meta_value != '' AND um.meta_value IS NOT NULL AND
@@ -1913,7 +1919,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
} else {
$results = $wpdb->get_col(
"SELECT u.ID FROM {$wpdb->users} AS u
"SELECT u.ID FROM {$wpdb->users} AS u
LEFT JOIN {$wpdb->usermeta} AS um ON ( um.user_id = u.ID AND ( um.meta_key = 'synced_profile_photo' || um.meta_key = 'profile_photo' ) )
LEFT JOIN {$wpdb->usermeta} AS um2 ON ( um2.user_id = u.ID AND um2.meta_key = 'um_member_directory_data' )
WHERE ( um.meta_value IS NULL OR um.meta_value = '' ) AND
@@ -1953,7 +1959,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
if ( $_POST['um_options']['account_hide_in_directory_default'] == 'No' ) {
$results = $wpdb->get_col(
"SELECT u.ID FROM {$wpdb->users} AS u
"SELECT u.ID FROM {$wpdb->users} AS u
LEFT JOIN {$wpdb->usermeta} AS um ON ( um.user_id = u.ID AND um.meta_key = 'hide_in_members' )
LEFT JOIN {$wpdb->usermeta} AS um2 ON ( um2.user_id = u.ID AND um2.meta_key = 'um_member_directory_data' )
WHERE um.meta_value IS NULL AND
@@ -1963,7 +1969,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) {
} else {
$results = $wpdb->get_col(
"SELECT u.ID FROM {$wpdb->users} AS u
"SELECT u.ID FROM {$wpdb->users} AS u
LEFT JOIN {$wpdb->usermeta} AS um ON ( um.user_id = u.ID AND um.meta_key = 'hide_in_members' )
LEFT JOIN {$wpdb->usermeta} AS um2 ON ( um2.user_id = u.ID AND um2.meta_key = 'um_member_directory_data' )
WHERE um.meta_value IS NULL AND
+1
View File
@@ -565,6 +565,7 @@ if ( ! class_exists( 'um\Config' ) ) {
'mail_from' => get_bloginfo('name'),
'mail_from_addr' => get_bloginfo('admin_email'),
'email_html' => 1,
'image_fix_orientation' => 1,
'image_compression' => 60,
'image_max_width' => 1000,
'cover_min_width' => 1000,
+47
View File
@@ -107,6 +107,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
add_filter( 'upload_dir', array( $this, 'set_upload_directory' ), 10, 1 );
add_filter( 'wp_handle_upload_prefilter', array( $this, 'validate_upload' ) );
add_filter( 'um_upload_image_result', array( $this, 'rotate_uploaded_image' ), 10, 1 );
add_filter( 'um_upload_image_process__profile_photo', array( $this, 'profile_photo' ), 10, 7 );
add_filter( 'um_upload_image_process__cover_photo', array( $this, 'cover_photo' ), 10, 7 );
add_action( 'um_upload_stream_image_process', array( $this, 'stream_photo' ), 10, 7 );
@@ -359,6 +360,30 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
$response['error'] = $movefile['error'];
} else {
/**
* UM hook
*
* @type filter
* @title um_upload_image_result
* @description Filter uploaded image data
* @input_vars [
* {"var":"$movefile", "type":"array", "desc":"Uploaded file info"},
* {"var":"$user_id", "type":"int", "desc":"User ID"},
* {"var":"$field_data", "type":"array", "desc":"Field data"}
* ]
* @change_log
* ["Since: 2.1.6"]
* @example
<?php
add_filter( 'um_upload_image_result', 'custom_um_upload_image_result', 10, 3 );
function custom_um_upload_image_result( $movefile, $user_id, $field_data ) {
// your code here
return $movefile;
}
?>
*/
$movefile = apply_filters( 'um_upload_image_result', $movefile, $user_id, $field_data );
$movefile['url'] = set_url_scheme( $movefile['url'] );
$movefile['file_info']['basename'] = wp_basename( $movefile['file'] );
@@ -1167,6 +1192,28 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
}
/**
* Fix image orientation
*
* @since 2.1.6
*
* @param array $movefile
* @return array
*/
public function rotate_uploaded_image( $movefile ) {
$image_fix_orientation = UM()->options()->get( 'image_fix_orientation' );
if ( $image_fix_orientation && $movefile['type'] == 'image/jpeg' ) {
$image = imagecreatefromjpeg( $movefile['file'] );
if ( $image ) {
$image = UM()->files()->fix_image_orientation( $image, $movefile['file'] );
$quality = UM()->options()->get( 'image_compression' );
imagejpeg( $image, $movefile['file'], $quality );
}
}
return $movefile;
}
/**
* Move temporary files
*