mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-20 07:04:06 +09:00
Fix file and image uploader
This commit is contained in:
@@ -104,8 +104,7 @@ if ( ! class_exists( 'um\core\Files' ) ) {
|
||||
if ( $coord_n != 3 ) {
|
||||
wp_send_json_error( esc_js( __( 'Invalid coordinates', 'ultimate-member' ) ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
$image_path = um_is_file_owner( $src, $user_id, true );
|
||||
if ( ! $image_path ) {
|
||||
wp_send_json_error( esc_js( __( 'Invalid file ownership', 'ultimate-member' ) ) );
|
||||
@@ -163,7 +162,7 @@ if ( ! class_exists( 'um\core\Files' ) ) {
|
||||
if ( ! wp_verify_nonce( $nonce, "um_upload_nonce-{$timestamp}" ) && is_user_logged_in() ) {
|
||||
// This nonce is not valid.
|
||||
$ret['error'] = 'Invalid nonce';
|
||||
die( json_encode( $ret ) );
|
||||
wp_send_json_error( $ret );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,12 +185,95 @@ if ( ! class_exists( 'um\core\Files' ) ) {
|
||||
} else {
|
||||
$ret['error'] = __('A theme or plugin compatibility issue','ultimate-member');
|
||||
}
|
||||
wp_send_json_success( $ret );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* File upload by AJAX
|
||||
*/
|
||||
function ajax_file_upload(){
|
||||
$ret['error'] = null;
|
||||
$ret = array();
|
||||
|
||||
/* commented for enable download files on registration form
|
||||
* if ( ! is_user_logged_in() ) {
|
||||
$ret['error'] = 'Invalid user';
|
||||
die( json_encode( $ret ) );
|
||||
}*/
|
||||
|
||||
$nonce = $_POST['_wpnonce'];
|
||||
$id = $_POST['key'];
|
||||
$timestamp = $_POST['timestamp'];
|
||||
|
||||
UM()->fields()->set_id = $_POST['set_id'];
|
||||
UM()->fields()->set_mode = $_POST['set_mode'];
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_file_upload_nonce
|
||||
* @description Change File Upload nonce
|
||||
* @input_vars
|
||||
* [{"var":"$nonce","type":"bool","desc":"Nonce"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_file_upload_nonce', 'function_name', 10, 1 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_file_upload_nonce', 'my_file_upload_nonce', 10, 1 );
|
||||
* function my_file_upload_nonce( $nonce ) {
|
||||
* // your code here
|
||||
* return $nonce;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$um_file_upload_nonce = apply_filters("um_file_upload_nonce", true );
|
||||
|
||||
if ( $um_file_upload_nonce ) {
|
||||
if ( ! wp_verify_nonce( $nonce, 'um_upload_nonce-'.$timestamp ) && is_user_logged_in() ) {
|
||||
// This nonce is not valid.
|
||||
$ret['error'] = 'Invalid nonce';
|
||||
wp_send_json_error( $ret );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( isset( $_FILES[ $id ]['name'] ) ) {
|
||||
|
||||
if( ! is_array( $_FILES[ $id ]['name'] ) ) {
|
||||
|
||||
$uploaded = UM()->uploader()->upload_file( $_FILES[ $id ], $user_id, $id );
|
||||
if ( isset( $uploaded['error'] ) ){
|
||||
|
||||
$ret['error'] = $uploaded['error'];
|
||||
|
||||
}else{
|
||||
|
||||
$uploaded_file = $uploaded['handle_upload'];
|
||||
$ret['url'] = $uploaded_file['file_info']['name'];
|
||||
$ret['icon'] = UM()->files()->get_fonticon_by_ext( $uploaded_file['file_info']['ext'] );
|
||||
$ret['icon_bg'] = UM()->files()->get_fonticon_bg_by_ext( $uploaded_file['file_info']['ext'] );
|
||||
$ret['filename'] = $uploaded_file['file_info']['basename'];
|
||||
$ret['original_name'] = $uploaded_file['file_info']['original_name'];
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
$ret['error'] = __('A theme or plugin compatibility issue','ultimate-member');
|
||||
}
|
||||
|
||||
|
||||
echo json_encode($ret);
|
||||
exit;
|
||||
wp_send_json_success( $ret );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Allowed image types
|
||||
*
|
||||
@@ -1255,88 +1337,5 @@ if ( ! class_exists( 'um\core\Files' ) ) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function ajax_file_upload(){
|
||||
$ret['error'] = null;
|
||||
$ret = array();
|
||||
|
||||
/* commented for enable download files on registration form
|
||||
* if ( ! is_user_logged_in() ) {
|
||||
$ret['error'] = 'Invalid user';
|
||||
die( json_encode( $ret ) );
|
||||
}*/
|
||||
|
||||
$nonce = $_POST['_wpnonce'];
|
||||
$id = $_POST['key'];
|
||||
$timestamp = $_POST['timestamp'];
|
||||
|
||||
UM()->fields()->set_id = $_POST['set_id'];
|
||||
UM()->fields()->set_mode = $_POST['set_mode'];
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_file_upload_nonce
|
||||
* @description Change File Upload nonce
|
||||
* @input_vars
|
||||
* [{"var":"$nonce","type":"bool","desc":"Nonce"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_file_upload_nonce', 'function_name', 10, 1 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_file_upload_nonce', 'my_file_upload_nonce', 10, 1 );
|
||||
* function my_file_upload_nonce( $nonce ) {
|
||||
* // your code here
|
||||
* return $nonce;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$um_file_upload_nonce = apply_filters("um_file_upload_nonce", true );
|
||||
|
||||
if ( $um_file_upload_nonce ) {
|
||||
if ( ! wp_verify_nonce( $nonce, 'um_upload_nonce-'.$timestamp ) && is_user_logged_in() ) {
|
||||
// This nonce is not valid.
|
||||
$ret['error'] = 'Invalid nonce';
|
||||
die( json_encode( $ret ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if( isset( $_FILES[ $id ]['name'] ) ) {
|
||||
|
||||
if( ! is_array( $_FILES[ $id ]['name'] ) ) {
|
||||
|
||||
$uploaded = UM()->uploader()->upload_file( $_FILES[ $id ], $user_id, $id );
|
||||
if ( isset( $uploaded['error'] ) ){
|
||||
|
||||
$ret['error'] = $uploaded['error'];
|
||||
|
||||
}else{
|
||||
|
||||
$uploaded_file = $uploaded['handle_upload'];
|
||||
$ret['url'] = $uploaded_file['file_info']['name'];
|
||||
$ret['icon'] = UM()->files()->get_fonticon_by_ext( $uploaded_file['file_info']['ext'] );
|
||||
$ret['icon_bg'] = UM()->files()->get_fonticon_bg_by_ext( $uploaded_file['file_info']['ext'] );
|
||||
$ret['filename'] = $uploaded_file['file_info']['basename'];
|
||||
$ret['original_name'] = $uploaded_file['file_info']['original_name'];
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
$ret['error'] = __('A theme or plugin compatibility issue','ultimate-member');
|
||||
}
|
||||
|
||||
echo json_encode($ret);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -71,12 +71,11 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
|
||||
|
||||
/**
|
||||
* Files constructor.
|
||||
* Uploader constructor.
|
||||
*/
|
||||
function __construct() {
|
||||
|
||||
$this->core_upload_dir = "/ultimatemember/";
|
||||
$this->user_id = get_current_user_id();
|
||||
$this->upload_image_type = 'stream_photo';
|
||||
$this->wp_upload_dir = wp_upload_dir();
|
||||
$this->temp_upload_dir = "temp";
|
||||
@@ -88,9 +87,17 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
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_action("init", array( $this, "init" ) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Init
|
||||
*/
|
||||
function init(){
|
||||
$this->user_id = get_current_user_id();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get core temporary directory path
|
||||
*
|
||||
@@ -309,17 +316,18 @@ if ( ! class_exists( 'um\core\Uploader' ) ) {
|
||||
$response['error'] = $movefile['error'];
|
||||
}else{
|
||||
|
||||
$movefile['file'] = wp_basename( $movefile['file'] );
|
||||
|
||||
$file_type = wp_check_filetype( $movefile['file'] );
|
||||
$movefile['file_info']['basename'] = wp_basename( $movefile['file'] );
|
||||
|
||||
$file_type = wp_check_filetype( $movefile['file_info']['basename'] );
|
||||
|
||||
$movefile['file_info']['name'] = $movefile['url'];
|
||||
$movefile['file_info']['original_name'] = $uploadedfile['name'];
|
||||
$movefile['file_info']['basename'] = wp_basename( $movefile['file'] );
|
||||
$movefile['file_info']['ext'] = $file_type['ext'];
|
||||
$movefile['file_info']['type'] = $file_type['type'];
|
||||
$movefile['file_info']['size'] = filesize( $movefile['file'] );
|
||||
$movefile['file_info']['size_format'] = size_format( $movefile['file_info']['size'] );
|
||||
$movefile['file'] = $movefile['file_info']['basename'];
|
||||
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
|
||||
Reference in New Issue
Block a user