diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index 5f366360..cb4bf730 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -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 ) ); } @@ -766,6 +766,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', @@ -1894,7 +1900,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 @@ -1904,7 +1910,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 @@ -1944,7 +1950,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 @@ -1954,7 +1960,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 diff --git a/includes/class-config.php b/includes/class-config.php index 28382baa..f36c0742 100644 --- a/includes/class-config.php +++ b/includes/class-config.php @@ -564,6 +564,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, diff --git a/includes/core/class-uploader.php b/includes/core/class-uploader.php index abc951c2..ff7eb13d 100644 --- a/includes/core/class-uploader.php +++ b/includes/core/class-uploader.php @@ -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 ); @@ -356,6 +357,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 + + */ + $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'] ); @@ -1164,6 +1189,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 *