mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-11 18:56:10 +09:00
- fixed issue with avatars/cover photos upload without crop;
This commit is contained in:
Vendored
+1
-1
@@ -1 +1 @@
|
||||
var um_dropdown_triggers={};function um_init_new_dropdown(){jQuery(".um-new-dropdown").each(function(){var r=jQuery(this);if(!r.data("um-dropdown-inited")){var e=r.data("element"),u=r.data("trigger");r.data("um-dropdown-inited",!0),-1===jQuery.inArray(e,um_dropdown_triggers[u])&&(jQuery(document.body).on(u,e,function(d){var n=jQuery(this);if(!0===n.data("um-new-dropdown-show"))n.data("um-new-dropdown-show",!1),n.find(".um-new-dropdown").hide();else{if(jQuery(".um-new-dropdown").hide(),jQuery(".um-new-dropdown").parent().data("um-new-dropdown-show",!1),n.find(".um-new-dropdown").length)n.find(".um-new-dropdown").show();else{var o=r.clone();n.append(o),n.trigger("fmwp_dropdown_render",{dropdown_layout:o,trigger:u,element:e,obj:n}),o.show()}n.data("um-new-dropdown-show",!0),jQuery(document.body).bind("click",function(d){0===jQuery(".um-new-dropdown").find("."+jQuery(d.target).attr("class").replace(" ",".")).length&&"."+jQuery(d.target).parent().attr("class")!==e&&(jQuery(".um-new-dropdown").hide(),jQuery(".um-new-dropdown").parent().data("um-new-dropdown-show",!1),jQuery(document.body).unbind(d))})}}),void 0===um_dropdown_triggers[u]&&(um_dropdown_triggers[u]=[]),um_dropdown_triggers[u].push(e))}})}jQuery(document).ready(function(d){um_init_new_dropdown(),jQuery(document.body).on("click",".um-new-dropdown a",function(d){jQuery(this).parents(".um-new-dropdown").hide(),jQuery(this).parents(".um-new-dropdown").parent().data("um-new-dropdown-show",!1),jQuery("body").trigger("click"),d.stopPropagation()})});
|
||||
var um_dropdown_triggers={};function um_init_new_dropdown(){jQuery(".um-new-dropdown").each(function(){var r=jQuery(this);if(!r.data("um-dropdown-inited")){var e=r.data("element"),t=r.data("trigger");r.data("um-dropdown-inited",!0),-1===jQuery.inArray(e,um_dropdown_triggers[t])&&(jQuery(document.body).on(t,e,function(d){var n=jQuery(this);if(!0===n.data("um-new-dropdown-show"))n.data("um-new-dropdown-show",!1),n.find(".um-new-dropdown").hide();else{if(jQuery(".um-new-dropdown").hide(),jQuery(".um-new-dropdown").parent().data("um-new-dropdown-show",!1),n.find(".um-new-dropdown").length)n.find(".um-new-dropdown").show();else{var o=r.clone();n.append(o),n.trigger("fmwp_dropdown_render",{dropdown_layout:o,trigger:t,element:e,obj:n}),o.show()}n.data("um-new-dropdown-show",!0),jQuery(document.body).bind("click",function(d){0===jQuery(".um-new-dropdown").find("."+jQuery(d.target).attr("class").trim().replace(" ",".")).length&&"."+jQuery(d.target).parent().attr("class").trim()!==e&&(jQuery(".um-new-dropdown").hide(),jQuery(".um-new-dropdown").parent().data("um-new-dropdown-show",!1),jQuery(document.body).unbind(d))})}}),void 0===um_dropdown_triggers[t]&&(um_dropdown_triggers[t]=[]),um_dropdown_triggers[t].push(e))}})}jQuery(document).ready(function(d){um_init_new_dropdown(),jQuery(document.body).on("click",".um-new-dropdown a",function(d){jQuery(this).parents(".um-new-dropdown").hide(),jQuery(this).parents(".um-new-dropdown").parent().data("um-new-dropdown-show",!1),jQuery("body").trigger("click"),d.stopPropagation()})});
|
||||
@@ -663,7 +663,7 @@ function um_modal_responsive() {
|
||||
|
||||
}
|
||||
|
||||
function um_remove_modal(){
|
||||
function um_remove_modal() {
|
||||
jQuery('img.cropper-hidden').cropper('destroy');
|
||||
|
||||
jQuery('body,html,textarea').css("overflow", "auto");
|
||||
|
||||
+16
-18
@@ -6,7 +6,6 @@ jQuery(document).ready(function() {
|
||||
});
|
||||
|
||||
jQuery(document).on('click', '.um-modal-overlay, a[data-action="um_remove_modal"]', function(){
|
||||
|
||||
um_remove_modal();
|
||||
});
|
||||
|
||||
@@ -44,22 +43,22 @@ jQuery(document).ready(function() {
|
||||
|
||||
jQuery(document).on('click', '.um-modal .um-single-image-preview a.cancel', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
|
||||
var parent = jQuery(this).parents('.um-modal-body');
|
||||
var src = jQuery(this).parents('.um-modal-body').find('.um-single-image-preview img').attr('src');
|
||||
|
||||
|
||||
jQuery('img.cropper-hidden').cropper('destroy');
|
||||
|
||||
|
||||
parent.find('.um-single-image-preview img').attr('src', '');
|
||||
|
||||
|
||||
parent.find('.um-single-image-preview').hide();
|
||||
|
||||
|
||||
parent.find('.ajax-upload-dragdrop').show();
|
||||
|
||||
|
||||
parent.find('.um-modal-btn.um-finish-upload').addClass('disabled');
|
||||
|
||||
|
||||
um_modal_responsive();
|
||||
|
||||
|
||||
jQuery.ajax({
|
||||
url: wp.ajax.settings.url,
|
||||
type: 'post',
|
||||
@@ -120,17 +119,15 @@ jQuery(document).ready(function() {
|
||||
key: key,
|
||||
nonce: um_scripts.nonce
|
||||
},
|
||||
success: function( response ){
|
||||
success: function( response ) {
|
||||
|
||||
if( response.success == true ){
|
||||
if ( response.success ) {
|
||||
|
||||
d = new Date();
|
||||
|
||||
if ( key == 'profile_photo') {
|
||||
if ( key === 'profile_photo' ) {
|
||||
jQuery('.um-profile-photo-img img').attr('src', response.data.image.source_url + "?"+d.getTime());
|
||||
}
|
||||
|
||||
if ( key == 'cover_photo') {
|
||||
} else if ( key === 'cover_photo' ) {
|
||||
jQuery('.um-cover-e').empty().html('<img src="' + response.data.image.source_url + "?"+d.getTime() + '" alt="" />');
|
||||
if ( jQuery('.um').hasClass('um-editing') ) {
|
||||
jQuery('.um-cover-overlay').show();
|
||||
@@ -138,13 +135,14 @@ jQuery(document).ready(function() {
|
||||
}
|
||||
|
||||
jQuery('.um-single-image-preview[data-key='+key+']').fadeIn().find('img').attr('src', response.data.image.source_url + "?"+d.getTime());
|
||||
|
||||
|
||||
um_remove_modal();
|
||||
|
||||
|
||||
jQuery('img.cropper-invisible').remove();
|
||||
|
||||
jQuery('.um-single-image-preview[data-key='+key+']').parents('.um-field').find('.um-btn-auto-width').html( elem.attr('data-change') );
|
||||
|
||||
jQuery('.um-single-image-preview[data-key='+key+']').parents('.um-field').find('input[type="hidden"]').val( response.data.image.filename );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
jQuery(document).ready(function(){jQuery(document).on("click",".um-popup-overlay",function(){remove_Modal()}),jQuery(document).on("click",'.um-modal-overlay, a[data-action="um_remove_modal"]',function(){um_remove_modal()}),jQuery(document).on("click",'a[data-modal^="um_"], span[data-modal^="um_"], .um-modal a',function(e){return e.preventDefault(),!1}),jQuery(document).on("click",".um-modal .um-single-file-preview a.cancel",function(e){e.preventDefault();var a=jQuery(this).parents(".um-modal-body"),t=jQuery(this).parents(".um-modal-body").find(".um-single-fileinfo a").attr("href");return a.find(".um-single-file-preview").hide(),a.find(".ajax-upload-dragdrop").show(),a.find(".um-modal-btn.um-finish-upload").addClass("disabled"),um_modal_responsive(),jQuery.ajax({url:wp.ajax.settings.url,type:"post",data:{action:"um_remove_file",src:t,nonce:um_scripts.nonce}}),!1}),jQuery(document).on("click",".um-modal .um-single-image-preview a.cancel",function(e){e.preventDefault();var a=jQuery(this).parents(".um-modal-body"),t=jQuery(this).parents(".um-modal-body").find(".um-single-image-preview img").attr("src");return jQuery("img.cropper-hidden").cropper("destroy"),a.find(".um-single-image-preview img").attr("src",""),a.find(".um-single-image-preview").hide(),a.find(".ajax-upload-dragdrop").show(),a.find(".um-modal-btn.um-finish-upload").addClass("disabled"),um_modal_responsive(),jQuery.ajax({url:wp.ajax.settings.url,type:"post",data:{action:"um_remove_file",src:t,nonce:um_scripts.nonce}}),!1}),jQuery(document).on("click",".um-finish-upload.file:not(.disabled)",function(){var e=jQuery(this).attr("data-key"),a=jQuery(this).parents(".um-modal-body").find(".um-single-file-preview").html();um_remove_modal(),jQuery(".um-single-file-preview[data-key="+e+"]").fadeIn().html(a);var t=jQuery(".um-field[data-key="+e+"]").find(".um-single-fileinfo a").data("file");jQuery(".um-single-file-preview[data-key="+e+"]").parents(".um-field").find(".um-btn-auto-width").html(jQuery(this).attr("data-change")),jQuery(".um-single-file-preview[data-key="+e+"]").parents(".um-field").find('input[type="hidden"]').val(t)}),jQuery(document).on("click",".um-finish-upload.image:not(.disabled)",function(){var a=jQuery(this),t=jQuery(this).attr("data-key"),e=jQuery(this).parents(".um-modal-body").find(".um-single-image-preview"),i=e.find("img").attr("src"),r=e.attr("data-coord"),u=e.find("img").data("file"),n=0;jQuery(this).parents("#um_upload_single").data("user_id")&&(n=jQuery(this).parents("#um_upload_single").data("user_id")),r?(jQuery(this).html(jQuery(this).attr("data-processing")).addClass("disabled"),jQuery.ajax({url:wp.ajax.settings.url,type:"POST",dataType:"json",data:{action:"um_resize_image",src:i,coord:r,user_id:n,key:t,nonce:um_scripts.nonce},success:function(e){1==e.success&&(d=new Date,"profile_photo"==t&&jQuery(".um-profile-photo-img img").attr("src",e.data.image.source_url+"?"+d.getTime()),"cover_photo"==t&&(jQuery(".um-cover-e").empty().html('<img src="'+e.data.image.source_url+"?"+d.getTime()+'" alt="" />'),jQuery(".um").hasClass("um-editing")&&jQuery(".um-cover-overlay").show()),jQuery(".um-single-image-preview[data-key="+t+"]").fadeIn().find("img").attr("src",e.data.image.source_url+"?"+d.getTime()),um_remove_modal(),jQuery(".um-single-image-preview[data-key="+t+"]").parents(".um-field").find(".um-btn-auto-width").html(a.attr("data-change")),jQuery(".um-single-image-preview[data-key="+t+"]").parents(".um-field").find('input[type="hidden"]').val(e.data.image.filename))}})):(d=new Date,jQuery(".um-single-image-preview[data-key="+t+"]").fadeIn().find("img").attr("src",i+"?"+d.getTime()),um_remove_modal(),jQuery(".um-single-image-preview[data-key="+t+"]").parents(".um-field").find(".um-btn-auto-width").html(a.attr("data-change")),jQuery(".um-single-image-preview[data-key="+t+"]").parents(".um-field").find("input[type=hidden]").val(u))}),jQuery(document.body).on("click",'a[data-modal^="um_"], span[data-modal^="um_"]',function(e){var a=jQuery(this).attr("data-modal"),t="normal";if(jQuery(this).data("modal-size"))t=jQuery(this).data("modal-size");jQuery(this).data("modal-copy")&&(jQuery("#"+a).html(jQuery(this).parents(".um-field").find(".um-modal-hidden-content").html()),jQuery(this).parents(".um-profile-photo").attr("data-user_id")&&jQuery("#"+a).attr("data-user_id",jQuery(this).parents(".um-profile-photo").attr("data-user_id")),jQuery(this).parents(".um-cover").attr("data-ratio")&&jQuery("#"+a).attr("data-ratio",jQuery(this).parents(".um-cover").attr("data-ratio")),jQuery(this).parents(".um-cover").attr("data-user_id")&&jQuery("#"+a).attr("data-user_id",jQuery(this).parents(".um-cover").attr("data-user_id")),0<jQuery("input[type=hidden][name='user_id']").length&&jQuery("#"+a).attr("data-user_id",jQuery("input[type=hidden][name='user_id']").val())),um_new_modal(a,t)})});
|
||||
jQuery(document).ready(function(){jQuery(document).on("click",".um-popup-overlay",function(){remove_Modal()}),jQuery(document).on("click",'.um-modal-overlay, a[data-action="um_remove_modal"]',function(){um_remove_modal()}),jQuery(document).on("click",'a[data-modal^="um_"], span[data-modal^="um_"], .um-modal a',function(e){return e.preventDefault(),!1}),jQuery(document).on("click",".um-modal .um-single-file-preview a.cancel",function(e){e.preventDefault();var a=jQuery(this).parents(".um-modal-body"),t=jQuery(this).parents(".um-modal-body").find(".um-single-fileinfo a").attr("href");return a.find(".um-single-file-preview").hide(),a.find(".ajax-upload-dragdrop").show(),a.find(".um-modal-btn.um-finish-upload").addClass("disabled"),um_modal_responsive(),jQuery.ajax({url:wp.ajax.settings.url,type:"post",data:{action:"um_remove_file",src:t,nonce:um_scripts.nonce}}),!1}),jQuery(document).on("click",".um-modal .um-single-image-preview a.cancel",function(e){e.preventDefault();var a=jQuery(this).parents(".um-modal-body"),t=jQuery(this).parents(".um-modal-body").find(".um-single-image-preview img").attr("src");return jQuery("img.cropper-hidden").cropper("destroy"),a.find(".um-single-image-preview img").attr("src",""),a.find(".um-single-image-preview").hide(),a.find(".ajax-upload-dragdrop").show(),a.find(".um-modal-btn.um-finish-upload").addClass("disabled"),um_modal_responsive(),jQuery.ajax({url:wp.ajax.settings.url,type:"post",data:{action:"um_remove_file",src:t,nonce:um_scripts.nonce}}),!1}),jQuery(document).on("click",".um-finish-upload.file:not(.disabled)",function(){var e=jQuery(this).attr("data-key"),a=jQuery(this).parents(".um-modal-body").find(".um-single-file-preview").html();um_remove_modal(),jQuery(".um-single-file-preview[data-key="+e+"]").fadeIn().html(a);var t=jQuery(".um-field[data-key="+e+"]").find(".um-single-fileinfo a").data("file");jQuery(".um-single-file-preview[data-key="+e+"]").parents(".um-field").find(".um-btn-auto-width").html(jQuery(this).attr("data-change")),jQuery(".um-single-file-preview[data-key="+e+"]").parents(".um-field").find('input[type="hidden"]').val(t)}),jQuery(document).on("click",".um-finish-upload.image:not(.disabled)",function(){var a=jQuery(this),t=jQuery(this).attr("data-key"),e=jQuery(this).parents(".um-modal-body").find(".um-single-image-preview"),i=e.find("img").attr("src"),r=e.attr("data-coord"),u=e.find("img").data("file"),n=0;jQuery(this).parents("#um_upload_single").data("user_id")&&(n=jQuery(this).parents("#um_upload_single").data("user_id")),r?(jQuery(this).html(jQuery(this).attr("data-processing")).addClass("disabled"),jQuery.ajax({url:wp.ajax.settings.url,type:"POST",dataType:"json",data:{action:"um_resize_image",src:i,coord:r,user_id:n,key:t,nonce:um_scripts.nonce},success:function(e){e.success&&(d=new Date,"profile_photo"===t?jQuery(".um-profile-photo-img img").attr("src",e.data.image.source_url+"?"+d.getTime()):"cover_photo"===t&&(jQuery(".um-cover-e").empty().html('<img src="'+e.data.image.source_url+"?"+d.getTime()+'" alt="" />'),jQuery(".um").hasClass("um-editing")&&jQuery(".um-cover-overlay").show()),jQuery(".um-single-image-preview[data-key="+t+"]").fadeIn().find("img").attr("src",e.data.image.source_url+"?"+d.getTime()),um_remove_modal(),jQuery("img.cropper-invisible").remove(),jQuery(".um-single-image-preview[data-key="+t+"]").parents(".um-field").find(".um-btn-auto-width").html(a.attr("data-change")),jQuery(".um-single-image-preview[data-key="+t+"]").parents(".um-field").find('input[type="hidden"]').val(e.data.image.filename))}})):(d=new Date,jQuery(".um-single-image-preview[data-key="+t+"]").fadeIn().find("img").attr("src",i+"?"+d.getTime()),um_remove_modal(),jQuery(".um-single-image-preview[data-key="+t+"]").parents(".um-field").find(".um-btn-auto-width").html(a.attr("data-change")),jQuery(".um-single-image-preview[data-key="+t+"]").parents(".um-field").find("input[type=hidden]").val(u))}),jQuery(document.body).on("click",'a[data-modal^="um_"], span[data-modal^="um_"]',function(e){var a=jQuery(this).attr("data-modal"),t="normal";if(jQuery(this).data("modal-size"))t=jQuery(this).data("modal-size");jQuery(this).data("modal-copy")&&(jQuery("#"+a).html(jQuery(this).parents(".um-field").find(".um-modal-hidden-content").html()),jQuery(this).parents(".um-profile-photo").attr("data-user_id")&&jQuery("#"+a).attr("data-user_id",jQuery(this).parents(".um-profile-photo").attr("data-user_id")),jQuery(this).parents(".um-cover").attr("data-ratio")&&jQuery("#"+a).attr("data-ratio",jQuery(this).parents(".um-cover").attr("data-ratio")),jQuery(this).parents(".um-cover").attr("data-user_id")&&jQuery("#"+a).attr("data-user_id",jQuery(this).parents(".um-cover").attr("data-user_id")),0<jQuery("input[type=hidden][name='user_id']").length&&jQuery("#"+a).attr("data-user_id",jQuery("input[type=hidden][name='user_id']").val())),um_new_modal(a,t)})});
|
||||
@@ -23,7 +23,7 @@ function um_admin_new_modal( id, ajax, size ) {
|
||||
jQuery('#' + id).show();
|
||||
jQuery('.um-admin-modal').show();
|
||||
|
||||
jQuery('.um-admin-modal-head').append('<a href="#" data-action="UM_remove_modal" class="um-admin-modal-close"><i class="um-faicon-times"></i></a>');
|
||||
jQuery('.um-admin-modal-head').append('<a href="javascript:void(0);" data-action="UM_remove_modal" class="um-admin-modal-close"><i class="um-faicon-times"></i></a>');
|
||||
|
||||
if ( ajax == true ) {
|
||||
um_admin_modal_size( size );
|
||||
|
||||
@@ -2479,7 +2479,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
$set_mode = '';
|
||||
}
|
||||
$nonce = wp_create_nonce( 'um_upload_nonce-' . $this->timestamp );
|
||||
$output .= '<div class="um-single-image-preview ' . $crop_class . '" data-crop="' . $crop_data . '" data-ratio="' . $ratio . '" data-min_width="' . $min_width . '" data-min_height="' . $min_height . '" data-coord=""><a href="#" class="cancel"><i class="um-icon-close"></i></a><img src="" alt="" /><div class="um-clear"></div></div><div class="um-clear"></div>';
|
||||
$output .= '<div class="um-single-image-preview ' . $crop_class . '" data-crop="' . $crop_data . '" data-ratio="' . $ratio . '" data-min_width="' . $min_width . '" data-min_height="' . $min_height . '" data-coord=""><a href="javascript:void(0);" class="cancel"><i class="um-icon-close"></i></a><img src="" alt="" /><div class="um-clear"></div></div><div class="um-clear"></div>';
|
||||
$output .= '<div class="um-single-image-upload" data-user_id="' . esc_attr( $_um_profile_id ) . '" data-nonce="' . $nonce . '" data-timestamp="' . esc_attr( $this->timestamp ) . '" data-icon="' . esc_attr( $icon ) . '" data-set_id="' . esc_attr( $set_id ) . '" data-set_mode="' . esc_attr( $set_mode ) . '" data-type="' . esc_attr( $type ) . '" data-key="' . esc_attr( $key ) . '" data-max_size="' . esc_attr( $max_size ) . '" data-max_size_error="' . esc_attr( $max_size_error ) . '" data-min_size_error="' . esc_attr( $min_size_error ) . '" data-extension_error="' . esc_attr( $extension_error ) . '" data-allowed_types="' . esc_attr( $allowed_types ) . '" data-upload_text="' . esc_attr( $upload_text ) . '" data-max_files_error="' . esc_attr( $max_files_error ) . '" data-upload_help_text="' . esc_attr( $upload_help_text ) . '">' . $button_text . '</div>';
|
||||
$output .= '<div class="um-modal-footer">
|
||||
<div class="um-modal-right">
|
||||
|
||||
@@ -302,9 +302,10 @@ if ( ! class_exists( 'um\core\Files' ) ) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Image upload by AJAX
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
function ajax_image_upload() {
|
||||
$ret['error'] = null;
|
||||
@@ -339,7 +340,7 @@ if ( ! class_exists( 'um\core\Files' ) ) {
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$um_image_upload_nonce = apply_filters( "um_image_upload_nonce", true );
|
||||
$um_image_upload_nonce = apply_filters( 'um_image_upload_nonce', true );
|
||||
|
||||
if ( $um_image_upload_nonce ) {
|
||||
if ( ! wp_verify_nonce( $nonce, "um_upload_nonce-{$timestamp}" ) && is_user_logged_in() ) {
|
||||
@@ -356,11 +357,10 @@ if ( ! class_exists( 'um\core\Files' ) ) {
|
||||
UM()->uploader()->replace_upload_dir = true;
|
||||
$uploaded = UM()->uploader()->upload_image( $_FILES[ $id ], $user_id, $id );
|
||||
UM()->uploader()->replace_upload_dir = false;
|
||||
if ( isset( $uploaded['error'] ) ){
|
||||
if ( isset( $uploaded['error'] ) ) {
|
||||
$ret['error'] = $uploaded['error'];
|
||||
} else {
|
||||
$ts = current_time( 'timestamp' );
|
||||
$ret[ ] = $uploaded['handle_upload'];
|
||||
$ret[] = $uploaded['handle_upload'];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1118,250 +1118,13 @@ if ( ! class_exists( 'um\core\Files' ) ) {
|
||||
* @param $source
|
||||
* @param $key
|
||||
*
|
||||
* @deprecated 2.1.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function new_user_upload( $user_id, $source, $key ) {
|
||||
|
||||
if( ! is_numeric( $user_id ) ){
|
||||
wp_die( __("Invalid user ID: ".json_encode( $user_id )." ",'ultimate-member') );
|
||||
}
|
||||
|
||||
$user_id = trim( $user_id );
|
||||
|
||||
// if he does not have uploads dir yet
|
||||
$this->new_user( $user_id );
|
||||
|
||||
if ( is_user_logged_in() && ( get_current_user_id() != $user_id ) && ! UM()->roles()->um_user_can( 'can_edit_everyone' ) ) {
|
||||
wp_die( __( 'Unauthorized to do this attempt.', 'ultimate-member' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_allow_frontend_image_uploads
|
||||
* @description Allow Fronend Image uploads
|
||||
* @input_vars
|
||||
* [{"var":"$allow","type":"bool","desc":"Allow"},
|
||||
* {"var":"$user_id","type":"int","desc":"User ID"},
|
||||
* {"var":"$key","type":"string","desc":"Field Key"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage add_filter( 'um_allow_frontend_image_uploads', 'function_name', 10, 3 );
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_allow_frontend_image_uploads', 'my_allow_frontend_image_uploads', 10, 3 );
|
||||
* function my_allow_frontend_image_uploads( $data ) {
|
||||
* // your code here
|
||||
* return $data;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$allow_frontend_image_uploads = apply_filters( 'um_allow_frontend_image_uploads', false, $user_id, $key );
|
||||
|
||||
if ( $allow_frontend_image_uploads == false && ! is_user_logged_in() && ( $key == 'profile_photo' || $key == 'cover_photo' ) ) {
|
||||
wp_die( __('Unauthorized to do this attempt.','ultimate-member') );
|
||||
}
|
||||
|
||||
$ext = '.' . pathinfo($source, PATHINFO_EXTENSION);
|
||||
|
||||
// copy & overwrite file
|
||||
|
||||
if( in_array( $key , array('profile_photo','cover_photo') ) ){
|
||||
$filename = $key . $ext;
|
||||
$name = $key;
|
||||
}else{
|
||||
$filename = basename( $source );
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ( file_exists( $this->upload_basedir . $user_id . '/' . $filename ) ) {
|
||||
unlink( $this->upload_basedir . $user_id . '/' . $filename );
|
||||
}
|
||||
copy( $source, $this->upload_basedir . $user_id . '/' . $filename );
|
||||
|
||||
$info = @getimagesize( $source );
|
||||
|
||||
// thumbs
|
||||
if ( $key == 'profile_photo' ) {
|
||||
|
||||
list($w, $h) = @getimagesize( $source );
|
||||
|
||||
|
||||
$sizes = UM()->options()->get( 'photo_thumb_sizes' );
|
||||
foreach( $sizes as $size ) {
|
||||
|
||||
$ratio = round( $w / $h, 2 );
|
||||
$height = round( $size / $ratio, 2 );
|
||||
|
||||
if ( file_exists( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext ) ) {
|
||||
unlink( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
|
||||
}
|
||||
|
||||
if ( $size < $w ) {
|
||||
|
||||
if ( $info['mime'] == 'image/jpeg' ){
|
||||
$thumb_s = imagecreatefromjpeg( $source );
|
||||
$thumb = imagecreatetruecolor( $size, $size );
|
||||
imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h );
|
||||
imagejpeg( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext, 100);
|
||||
imagejpeg( $thumb, $this->upload_basedir . $user_id . '/' . $name . $ext, 100);
|
||||
}else if ( $info['mime'] == 'image/png' ){
|
||||
$thumb_s = imagecreatefrompng( $source );
|
||||
$thumb = imagecreatetruecolor( $size, $size );
|
||||
imagealphablending( $thumb, false);
|
||||
imagesavealpha( $thumb, true);
|
||||
imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h );
|
||||
imagepng( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
|
||||
}else if ( $info['mime'] == 'image/gif' ){
|
||||
$thumb_s = imagecreatefromgif( $source );
|
||||
$thumb = imagecreatetruecolor( $size, $size );
|
||||
imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $size, $w, $h );
|
||||
imagegif( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext);
|
||||
imagegif( $thumb, $this->upload_basedir . $user_id . '/' . $name . $ext);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// removes a synced profile photo
|
||||
delete_user_meta( $user_id, 'synced_profile_photo' );
|
||||
|
||||
} else if ( $key == 'cover_photo' ) {
|
||||
|
||||
list($w, $h) = @getimagesize( $source );
|
||||
|
||||
$sizes = UM()->options()->get( 'cover_thumb_sizes' );
|
||||
foreach ( $sizes as $size ) {
|
||||
|
||||
$ratio = round( $w / $h, 2 );
|
||||
$height = round( $size / $ratio, 2 );
|
||||
|
||||
if ( file_exists( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext ) ) {
|
||||
unlink( $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
|
||||
}
|
||||
|
||||
if ( $size < $w ) {
|
||||
|
||||
if ( $info['mime'] == 'image/jpeg' ){
|
||||
$thumb = imagecreatetruecolor( $size, $height );
|
||||
$thumb_s = imagecreatefromjpeg( $source );
|
||||
imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h );
|
||||
imagejpeg( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext, 100);
|
||||
}else if ( $info['mime'] == 'image/png' ){
|
||||
$thumb_s = imagecreatefrompng( $source );
|
||||
$thumb = imagecreatetruecolor( $size, $height );
|
||||
imagealphablending( $thumb, false);
|
||||
imagesavealpha( $thumb, true);
|
||||
imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h );
|
||||
imagepng( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext );
|
||||
}else if ( $info['mime'] == 'image/gif' ){
|
||||
$thumb = imagecreatetruecolor( $size, $height );
|
||||
$thumb_s = imagecreatefromgif( $source );
|
||||
imagecopyresampled( $thumb, $thumb_s, 0, 0, 0, 0, $size, $height, $w, $h );
|
||||
imagegif( $thumb, $this->upload_basedir . $user_id . '/' . $name . '-' . $size . $ext);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// clean up temp
|
||||
$dir = dirname( $source );
|
||||
unlink( $source );
|
||||
rmdir( $dir );
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type action
|
||||
* @title um_before_upload_db_meta
|
||||
* @description Update user's meta before upload
|
||||
* @input_vars
|
||||
* [{"var":"$user_id","type":"int","desc":"User ID"},
|
||||
* {"var":"$key","type":"string","desc":"Meta key"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage add_action( 'um_before_upload_db_meta', 'function_name', 10, 2 );
|
||||
* @example
|
||||
* <?php
|
||||
* add_action( 'um_before_upload_db_meta', 'my_before_upload_db_meta', 10, 2 );
|
||||
* function my_before_upload_db_meta( $user_id, $key ) {
|
||||
* // your code here
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
do_action( 'um_before_upload_db_meta', $user_id, $key );
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type action
|
||||
* @title um_before_upload_db_meta_{$key}
|
||||
* @description Update user's meta before upload
|
||||
* @input_vars
|
||||
* [{"var":"$user_id","type":"int","desc":"User ID"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage add_action( 'um_before_upload_db_meta_{$key}', 'function_name', 10, 1 );
|
||||
* @example
|
||||
* <?php
|
||||
* add_action( 'um_before_upload_db_meta_{$key}', 'my_before_upload_db_meta', 10, 1 );
|
||||
* function my_before_upload_db_meta( $user_id ) {
|
||||
* // your code here
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
do_action( "um_before_upload_db_meta_{$key}", $user_id );
|
||||
|
||||
update_user_meta( $user_id, $key, $filename );
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type action
|
||||
* @title um_after_upload_db_meta
|
||||
* @description Update user's meta before upload
|
||||
* @input_vars
|
||||
* [{"var":"$user_id","type":"int","desc":"User ID"},
|
||||
* {"var":"$key","type":"string","desc":"Meta key"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage add_action( 'um_after_upload_db_meta', 'function_name', 10, 2 );
|
||||
* @example
|
||||
* <?php
|
||||
* add_action( 'um_after_upload_db_meta', 'my_after_upload_db_meta', 10, 2 );
|
||||
* function my_after_upload_db_meta( $user_id, $key ) {
|
||||
* // your code here
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
do_action( 'um_after_upload_db_meta', $user_id, $key );
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type action
|
||||
* @title um_after_upload_db_meta_{$key}
|
||||
* @description Update user's meta after upload
|
||||
* @input_vars
|
||||
* [{"var":"$user_id","type":"int","desc":"User ID"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage add_action( 'um_after_upload_db_meta_{$key}', 'function_name', 10, 1 );
|
||||
* @example
|
||||
* <?php
|
||||
* add_action( 'um_after_upload_db_meta_{$key}', 'my_after_upload_db_meta', 10, 1 );
|
||||
* function my_after_upload_db_meta( $user_id ) {
|
||||
* // your code here
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
do_action( "um_after_upload_db_meta_{$key}", $user_id );
|
||||
|
||||
// the url of upload
|
||||
return $this->upload_baseurl . $user_id . '/' . $filename;
|
||||
|
||||
um_deprecated_function( 'new_user_upload', '2.1.0', '' );
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -98,20 +98,20 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
* Uploader constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->core_upload_dir = DIRECTORY_SEPARATOR . "ultimatemember" . DIRECTORY_SEPARATOR;
|
||||
$this->core_upload_url = "/ultimatemember/";
|
||||
$this->core_upload_dir = DIRECTORY_SEPARATOR . 'ultimatemember' . DIRECTORY_SEPARATOR;
|
||||
$this->core_upload_url = '/ultimatemember/';
|
||||
$this->upload_image_type = 'stream_photo';
|
||||
$this->wp_upload_dir = wp_upload_dir();
|
||||
$this->temp_upload_dir = "temp";
|
||||
$this->temp_upload_dir = 'temp';
|
||||
|
||||
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_process__profile_photo", array( $this, "profile_photo" ), 10, 6 );
|
||||
add_filter( "um_upload_image_process__cover_photo", array( $this, "cover_photo" ), 10, 6 );
|
||||
add_filter( "um_upload_stream_image_process", array( $this, "stream_photo" ), 10, 6 );
|
||||
add_filter( "um_custom_image_handle_wall_img_upload", array( $this, "stream_photo_data"), 10, 1 );
|
||||
add_filter( 'upload_dir', array( $this, 'set_upload_directory' ), 10, 1 );
|
||||
add_filter( 'wp_handle_upload_prefilter', array( $this, 'validate_upload' ) );
|
||||
|
||||
add_action( "init", array( $this, "init" ) );
|
||||
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 );
|
||||
|
||||
add_action( 'init', array( $this, 'init' ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
|
||||
/**
|
||||
* Upload Image files
|
||||
* Upload Image files
|
||||
*
|
||||
* @param array $uploadedfile
|
||||
* @param int|null $user_id
|
||||
@@ -296,6 +296,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
* @since 2.0.22
|
||||
*
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function upload_image( $uploadedfile, $user_id = null, $field_key = '', $upload_type = 'stream_photo' ) {
|
||||
$response = array();
|
||||
@@ -305,7 +306,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
}
|
||||
|
||||
if ( empty( $field_key ) ) {
|
||||
$field_key = "custom_field";
|
||||
$field_key = 'custom_field';
|
||||
}
|
||||
|
||||
$this->field_key = $field_key;
|
||||
@@ -318,16 +319,16 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
$this->user_id = $user_id;
|
||||
}
|
||||
|
||||
if ( in_array( $field_key, array( 'profile_photo','cover_photo' ) ) ) {
|
||||
if ( in_array( $field_key, array( 'profile_photo', 'cover_photo' ) ) ) {
|
||||
$this->upload_image_type = $field_key;
|
||||
}
|
||||
|
||||
$field_data = UM()->fields()->get_field( $field_key );
|
||||
|
||||
if ( isset( $field_data['allowed_types'] ) && ! empty( $field_data['allowed_types'] ) ) {
|
||||
$field_allowed_file_types = explode(",", $field_data['allowed_types'] );
|
||||
if ( ! empty( $field_data['allowed_types'] ) ) {
|
||||
$field_allowed_file_types = explode( ',', $field_data['allowed_types'] );
|
||||
} else {
|
||||
$field_allowed_file_types = apply_filters("um_uploader_image_default_filetypes", array('JPG','JPEG','PNG','GIF') );
|
||||
$field_allowed_file_types = apply_filters( 'um_uploader_image_default_filetypes', array( 'JPG', 'JPEG', 'PNG', 'GIF' ) );
|
||||
}
|
||||
|
||||
$allowed_image_mimes = array();
|
||||
@@ -337,12 +338,10 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
$allowed_image_mimes[ $atype['ext'] ] = $atype['type'];
|
||||
}
|
||||
|
||||
$image_compression = UM()->options()->get( 'image_compression' );
|
||||
|
||||
$upload_overrides = array(
|
||||
'test_form' => false,
|
||||
'mimes' => apply_filters( "um_uploader_allowed_image_mimes", $allowed_image_mimes ),
|
||||
'unique_filename_callback' => array( $this, "unique_filename"),
|
||||
'test_form' => false,
|
||||
'mimes' => apply_filters( 'um_uploader_allowed_image_mimes', $allowed_image_mimes ),
|
||||
'unique_filename_callback' => array( $this, 'unique_filename' ),
|
||||
);
|
||||
|
||||
$upload_overrides = apply_filters( "um_image_upload_handler_overrides__{$field_key}", $upload_overrides );
|
||||
@@ -456,10 +455,6 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
*/
|
||||
do_action( "um_after_upload_db_meta_{$field_key}", $this->user_id );
|
||||
|
||||
if ( 'stream_photo' !== $this->upload_image_type ) {
|
||||
update_user_meta( $this->user_id, $field_key, wp_basename( $movefile['url'] ) );
|
||||
}
|
||||
|
||||
$filename = wp_basename( $movefile['url'] );
|
||||
|
||||
$transient = set_transient( "um_{$filename}", $movefile['file_info'], 2 * HOUR_IN_SECONDS );
|
||||
@@ -515,9 +510,9 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
}
|
||||
|
||||
$upload_overrides = array(
|
||||
'test_form' => false,
|
||||
'mimes' => apply_filters( "um_uploader_allowed_file_mimes", $allowed_file_mimes ),
|
||||
'unique_filename_callback' => array( $this, "unique_filename"),
|
||||
'test_form' => false,
|
||||
'mimes' => apply_filters( 'um_uploader_allowed_file_mimes', $allowed_file_mimes ),
|
||||
'unique_filename_callback' => array( $this, 'unique_filename' ),
|
||||
);
|
||||
|
||||
$upload_overrides = apply_filters( "um_file_upload_handler_overrides__{$field_key}", $upload_overrides );
|
||||
@@ -874,6 +869,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
/**
|
||||
* Make unique filename
|
||||
*
|
||||
* @param string $dir
|
||||
* @param string $filename
|
||||
* @param string $ext
|
||||
@@ -886,8 +882,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
if ( empty( $ext ) ) {
|
||||
$image_type = wp_check_filetype( $filename );
|
||||
$ext = strtolower( trim( $image_type['ext'], ' \/.' ) );
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$ext = strtolower( trim( $ext, ' \/.' ) );
|
||||
}
|
||||
|
||||
@@ -896,25 +891,23 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
switch ( $this->upload_image_type ) {
|
||||
|
||||
case 'stream_photo':
|
||||
$hashed = hash('ripemd160', time(). mt_rand(10,1000) );
|
||||
$hashed = hash('ripemd160', time() . mt_rand( 10, 1000 ) );
|
||||
$filename = "stream_photo_{$hashed}.{$ext}";
|
||||
break;
|
||||
break;
|
||||
|
||||
case 'profile_photo':
|
||||
$filename = "profile_photo.{$ext}";
|
||||
break;
|
||||
|
||||
case 'cover_photo':
|
||||
$filename = "cover_photo.{$ext}";
|
||||
break;
|
||||
$filename = "{$this->upload_image_type}_temp.{$ext}";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
} elseif ( 'file' == $this->upload_type ) {
|
||||
$hashed = hash('ripemd160', time(). mt_rand(10,1000) );
|
||||
$hashed = hash('ripemd160', time() . mt_rand( 10, 1000 ) );
|
||||
$filename = "file_{$hashed}.{$ext}";
|
||||
}
|
||||
|
||||
$this->delete_existing_file( $filename, $ext, $dir );
|
||||
$this->delete_existing_file( $filename, $ext, $dir );
|
||||
|
||||
return $filename;
|
||||
}
|
||||
@@ -929,28 +922,38 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
* @since 2.0.22
|
||||
*/
|
||||
public function delete_existing_file( $filename, $ext = '', $dir = '' ) {
|
||||
if( file_exists( $this->upload_user_basedir . DIRECTORY_SEPARATOR . $filename ) && ! empty( $filename ) ) {
|
||||
unlink( $this->upload_user_basedir . DIRECTORY_SEPARATOR . $filename );
|
||||
if ( file_exists( $this->upload_user_basedir . DIRECTORY_SEPARATOR . $filename ) && ! empty( $filename ) ) {
|
||||
unlink( $this->upload_user_basedir . DIRECTORY_SEPARATOR . $filename );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Profile photo image process
|
||||
*
|
||||
* @param array $response
|
||||
* @param string $image_path
|
||||
* @param string $src
|
||||
* @param string $key
|
||||
* @param integer $user_id
|
||||
* @param string $coord
|
||||
* @param array $crop
|
||||
*
|
||||
* @since 2.0.22
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function profile_photo( $image_path, $src, $key, $user_id, $coord, $crop ) {
|
||||
public function profile_photo( $response, $image_path, $src, $key, $user_id, $coord, $crop ) {
|
||||
$sizes = UM()->options()->get( 'photo_thumb_sizes' );
|
||||
|
||||
$quality = UM()->options()->get( 'image_compression' );
|
||||
|
||||
$image = wp_get_image_editor( $image_path ); // Return an implementation that extends WP_Image_Editor
|
||||
|
||||
$temp_image_path = $image_path;
|
||||
//refresh image_path to make temporary image permanently after upload
|
||||
$image_path = pathinfo( $image_path, PATHINFO_DIRNAME ) . DIRECTORY_SEPARATOR . $key . '.' . pathinfo( $image_path, PATHINFO_EXTENSION );
|
||||
|
||||
if ( ! is_wp_error( $image ) ) {
|
||||
$src_x = $crop[0];
|
||||
$src_y = $crop[1];
|
||||
@@ -959,7 +962,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
$image->crop( $src_x, $src_y, $src_w, $src_h );
|
||||
|
||||
$max_w = UM()->options()->get('image_max_width');
|
||||
$max_w = UM()->options()->get( 'image_max_width' );
|
||||
if ( $src_w > $max_w ) {
|
||||
$image->resize( $max_w, $src_h );
|
||||
}
|
||||
@@ -970,30 +973,46 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
$sizes_array = array();
|
||||
|
||||
foreach( $sizes as $size ){
|
||||
$sizes_array[ ] = array ('width' => $size );
|
||||
foreach ( $sizes as $size ) {
|
||||
$sizes_array[] = array( 'width' => $size );
|
||||
}
|
||||
|
||||
$image->multi_resize( $sizes_array );
|
||||
|
||||
delete_user_meta( $user_id, 'synced_profile_photo' );
|
||||
|
||||
unlink( $temp_image_path );
|
||||
|
||||
$src = str_replace( '/' . $key . '_temp.', '/' . $key . '.', $src );
|
||||
|
||||
$response['image']['source_url'] = $src;
|
||||
$response['image']['source_path'] = $image_path;
|
||||
$response['image']['filename'] = wp_basename( $image_path );
|
||||
|
||||
update_user_meta( $this->user_id, $key, wp_basename( wp_basename( $image_path ) ) );
|
||||
delete_user_meta( $this->user_id, "{$key}_metadata_temp" );
|
||||
} else {
|
||||
wp_send_json_error( esc_js( __( "Unable to crop image file: {$src}", 'ultimate-member' ) ) );
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cover photo image process
|
||||
*
|
||||
* @param string $src
|
||||
* @param integer $user_id
|
||||
* @param string $coord
|
||||
* @param array $crop
|
||||
* @param array $response
|
||||
*
|
||||
* @since 2.0.22
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function cover_photo( $image_path, $src, $key, $user_id, $coord, $crop ){
|
||||
public function cover_photo( $response, $image_path, $src, $key, $user_id, $coord, $crop ) {
|
||||
|
||||
$sizes = UM()->options()->get( 'cover_thumb_sizes' );
|
||||
|
||||
@@ -1001,6 +1020,11 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
$image = wp_get_image_editor( $image_path ); // Return an implementation that extends WP_Image_Editor
|
||||
|
||||
$temp_image_path = $image_path;
|
||||
|
||||
//refresh image_path to make temporary image permanently after upload
|
||||
$image_path = pathinfo( $image_path, PATHINFO_DIRNAME ) . DIRECTORY_SEPARATOR . $key . '.' . pathinfo( $image_path, PATHINFO_EXTENSION );
|
||||
|
||||
if ( ! is_wp_error( $image ) ) {
|
||||
|
||||
$src_x = $crop[0];
|
||||
@@ -1010,7 +1034,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
$image->crop( $src_x, $src_y, $src_w, $src_h );
|
||||
|
||||
$max_w = UM()->options()->get('image_max_width');
|
||||
$max_w = UM()->options()->get( 'image_max_width' );
|
||||
if ( $src_w > $max_w ) {
|
||||
$image->resize( $max_w, $src_h );
|
||||
}
|
||||
@@ -1021,36 +1045,53 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
$sizes_array = array();
|
||||
|
||||
foreach( $sizes as $size ){
|
||||
$sizes_array[ ] = array ('width' => $size );
|
||||
foreach ( $sizes as $size ) {
|
||||
$sizes_array[] = array( 'width' => $size );
|
||||
}
|
||||
|
||||
$resize = $image->multi_resize( $sizes_array );
|
||||
|
||||
// change filenames of resized images
|
||||
foreach( $resize as $row ){
|
||||
$new_filename = str_replace( "x{$row['height']}" , "", $row["file"] );
|
||||
$old_filename = $row["file"];
|
||||
foreach ( $resize as $row ) {
|
||||
$new_filename = str_replace( "x{$row['height']}" , '', $row['file'] );
|
||||
$old_filename = $row['file'];
|
||||
|
||||
rename( dirname( $image_path ) . DIRECTORY_SEPARATOR . $old_filename, dirname( $image_path ) . DIRECTORY_SEPARATOR . $new_filename );
|
||||
}
|
||||
|
||||
unlink( $temp_image_path );
|
||||
|
||||
$src = str_replace( '/' . $key . '_temp.', '/' . $key . '.', $src );
|
||||
|
||||
$response['image']['source_url'] = $src;
|
||||
$response['image']['source_path'] = $image_path;
|
||||
$response['image']['filename'] = wp_basename( $image_path );
|
||||
|
||||
update_user_meta( $this->user_id, $key, wp_basename( wp_basename( $image_path ) ) );
|
||||
delete_user_meta( $this->user_id, "{$key}_metadata_temp" );
|
||||
} else {
|
||||
wp_send_json_error( esc_js( __( "Unable to crop image file: {$src}", 'ultimate-member' ) ) );
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Stream photo image process
|
||||
*
|
||||
* @param array $response
|
||||
* @param string $image_path
|
||||
* @param string $src
|
||||
* @param integer $user_id
|
||||
* @param string $coord
|
||||
* @param array $crop
|
||||
*
|
||||
* @since 2.0.22
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function stream_photo( $image_path, $src, $key, $user_id, $coord, $crop ){
|
||||
public function stream_photo( $response, $image_path, $src, $key, $user_id, $coord, $crop ) {
|
||||
|
||||
$image = wp_get_image_editor( $image_path ); // Return an implementation that extends WP_Image_Editor
|
||||
|
||||
@@ -1059,8 +1100,8 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
if ( ! is_wp_error( $image ) ) {
|
||||
if ( ! empty( $crop ) ) {
|
||||
|
||||
if( ! is_array( $crop ) ) {
|
||||
$crop = explode(",", $crop );
|
||||
if ( ! is_array( $crop ) ) {
|
||||
$crop = explode( ",", $crop );
|
||||
}
|
||||
|
||||
$src_x = $crop[0];
|
||||
@@ -1070,7 +1111,7 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
$image->crop( $src_x, $src_y, $src_w, $src_h );
|
||||
|
||||
$max_w = UM()->options()->get('image_max_width');
|
||||
$max_w = UM()->options()->get( 'image_max_width' );
|
||||
if ( $src_w > $max_w ) {
|
||||
$image->resize( $max_w, $src_h );
|
||||
}
|
||||
@@ -1083,26 +1124,14 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
} else {
|
||||
wp_send_json_error( esc_js( __( "Unable to crop stream image file: {$image_path}", 'ultimate-member' ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set stream photo default settings
|
||||
* @param array $args
|
||||
* @return array
|
||||
*
|
||||
* @since 2.0.22
|
||||
*/
|
||||
public function stream_photo_data( $args ) {
|
||||
$args['max_file_size'] = apply_filters( "um_upload_images_stream_maximum_file_size", 9999999 );
|
||||
$args['max_file_size_error'] = sprintf( __( "Maximum file size allowed: %s", 'ultimate-member' ), size_format( $args['max_file_size'] ) );
|
||||
|
||||
return $args;
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resize Image
|
||||
*
|
||||
* @param string $image_path
|
||||
* @param string $src
|
||||
* @param string $key
|
||||
@@ -1117,24 +1146,30 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
$crop = explode( ',', $coord );
|
||||
$crop = array_map( 'intval', $crop );
|
||||
|
||||
do_action("um_upload_image_process__{$key}", $image_path, $src, $key, $user_id, $coord, $crop );
|
||||
$response = array(
|
||||
'image' => array(
|
||||
'source_url' => $src,
|
||||
'source_path' => $image_path,
|
||||
'filename' => wp_basename( $image_path ),
|
||||
),
|
||||
);
|
||||
|
||||
if ( ! in_array( $key, array('profile_photo','cover_photo') ) ) {
|
||||
do_action( "um_upload_stream_image_process", $image_path, $src, $key, $user_id, $coord, $crop );
|
||||
$response = apply_filters( "um_upload_image_process__{$key}", $response, $image_path, $src, $key, $user_id, $coord, $crop );
|
||||
|
||||
if ( ! in_array( $key, array( 'profile_photo', 'cover_photo' ) ) ) {
|
||||
$response = apply_filters( 'um_upload_stream_image_process', $response, $image_path, $src, $key, $user_id, $coord, $crop );
|
||||
}
|
||||
|
||||
$ret = array();
|
||||
$ret['image']['source_url'] = $src;
|
||||
$ret['image']['source_path'] = $image_path;
|
||||
$ret['image']['filename'] = wp_basename( $image_path );
|
||||
|
||||
return $ret;
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Move temporary files
|
||||
*
|
||||
* run when uploaded files are from custom fields
|
||||
* move them to the users' folder after form submitted
|
||||
*
|
||||
* @param $user_id
|
||||
* @param $files
|
||||
* @param bool $move_only
|
||||
|
||||
@@ -1640,14 +1640,11 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
* Update files
|
||||
*
|
||||
* @param $changes
|
||||
*
|
||||
* @deprecated 2.1.0
|
||||
*/
|
||||
function update_files( $changes ) {
|
||||
|
||||
foreach ( $changes as $key => $uri ) {
|
||||
$src = um_is_temp_upload( $uri );
|
||||
UM()->files()->new_user_upload( $this->id, $src, $key );
|
||||
}
|
||||
|
||||
um_deprecated_function( 'update_files', '2.1.0', '' );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Ultimate Member\n"
|
||||
"POT-Creation-Date: 2019-10-18 13:00+0300\n"
|
||||
"PO-Revision-Date: 2019-10-18 13:00+0300\n"
|
||||
"POT-Creation-Date: 2019-10-21 23:36+0300\n"
|
||||
"PO-Revision-Date: 2019-10-21 23:37+0300\n"
|
||||
"Last-Translator: \n"
|
||||
"Language-Team: \n"
|
||||
"Language: en_US\n"
|
||||
@@ -4556,7 +4556,7 @@ msgid "Register"
|
||||
msgstr ""
|
||||
|
||||
#: includes/class-config.php:135 includes/class-config.php:788
|
||||
#: includes/core/class-member-directory.php:1857
|
||||
#: includes/core/class-member-directory.php:1849
|
||||
#: includes/core/um-actions-profile.php:1225
|
||||
#: includes/core/um-actions-user.php:19
|
||||
msgid "Logout"
|
||||
@@ -7023,7 +7023,7 @@ msgstr ""
|
||||
msgid "Invalid file ownership"
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-files.php:347
|
||||
#: includes/core/class-files.php:348
|
||||
msgid "Invalid nonce"
|
||||
msgstr ""
|
||||
|
||||
@@ -7035,15 +7035,7 @@ msgstr ""
|
||||
msgid "Ultimate Member: Not a valid temp file"
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-files.php:1126
|
||||
msgid "Invalid user ID: "
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-files.php:1135 includes/core/class-files.php:1163
|
||||
msgid "Unauthorized to do this attempt."
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-files.php:1467
|
||||
#: includes/core/class-files.php:1230
|
||||
msgid "Original size"
|
||||
msgstr ""
|
||||
|
||||
@@ -7113,14 +7105,14 @@ msgstr ""
|
||||
msgid "<strong>Age:</strong> {min_range} - {max_range} years old"
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-member-directory.php:1802
|
||||
#: includes/core/class-member-directory.php:1846
|
||||
#: includes/core/class-member-directory.php:1794
|
||||
#: includes/core/class-member-directory.php:1838
|
||||
#: includes/core/um-actions-profile.php:1192
|
||||
#: includes/core/um-actions-profile.php:1223
|
||||
msgid "Edit Profile"
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-member-directory.php:1852
|
||||
#: includes/core/class-member-directory.php:1844
|
||||
#: includes/core/um-actions-profile.php:1224
|
||||
msgid "My Account"
|
||||
msgstr ""
|
||||
@@ -7233,32 +7225,27 @@ msgstr ""
|
||||
msgid "Default Template"
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-uploader.php:668
|
||||
#: includes/core/class-uploader.php:663
|
||||
msgid "Your image is invalid!"
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-uploader.php:710
|
||||
#: includes/core/class-uploader.php:705
|
||||
msgid "This media type is not recognized."
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-uploader.php:758
|
||||
#: includes/core/class-uploader.php:753
|
||||
msgid "Your image is invalid or too large!"
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-uploader.php:764 includes/core/class-uploader.php:766
|
||||
#: includes/core/class-uploader.php:759 includes/core/class-uploader.php:761
|
||||
#, php-format
|
||||
msgid "Your photo is too small. It must be at least %spx wide."
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-uploader.php:819
|
||||
#: includes/core/class-uploader.php:814
|
||||
msgid "This file type is not recognized."
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-uploader.php:1098
|
||||
#, php-format
|
||||
msgid "Maximum file size allowed: %s"
|
||||
msgstr ""
|
||||
|
||||
#: includes/core/class-user.php:623
|
||||
msgid "Ultimate Member Role"
|
||||
msgstr ""
|
||||
|
||||
Reference in New Issue
Block a user