- fixed files uploading (by Denis);

This commit is contained in:
nikitozzzzzzz
2017-10-16 15:49:40 +03:00
parent 22e43eb32d
commit 368d0b133d
2 changed files with 20 additions and 8 deletions
+17 -6
View File
@@ -34,24 +34,35 @@
* Clean user temp uploads
*
* @param $user_id
* @param $array
* @param $post_array
*/
function um_remove_unused_uploads( $user_id, $array ) {
function um_remove_unused_uploads( $user_id, $post_array ) {
um_fetch_user( $user_id );
$files = glob( um_user_uploads_dir() . '*', GLOB_BRACE );
$user_meta_keys = UM()->user()->profile;
if ( file_exists( um_user_uploads_dir() ) && $files && isset( $array ) && is_array( $array ) ) {
$_array = array();
foreach ( UM()->builtin()->custom_fields as $_field ) {
if ( $_field['type'] == 'file' && ! empty( $user_meta_keys[ $_field['metakey'] ] ) )
$_array[] = $user_meta_keys[ $_field['metakey'] ];
}
$_array = array_merge( $_array, $post_array );
$files = glob( um_user_uploads_dir() . '*', GLOB_BRACE );
$error = array();
if ( file_exists( um_user_uploads_dir() ) && $files && isset( $_array ) && is_array( $_array ) ) {
foreach ( $files as $file ) {
$str = basename( $file );
if ( ! strstr( $str, 'profile_photo' ) && ! strstr( $str, 'cover_photo' ) &&
! strstr( $str, 'stream_photo' ) && ! preg_grep( '/' . $str . '/', array_values( $array ) ) )
! strstr( $str, 'stream_photo' ) && ! preg_grep( '/' . $str . '/', $_array ) ) {
$error[] = $str;
unlink( $file );
}
}
}
}
add_action( 'um_after_user_upload','um_remove_unused_uploads', 10, 2 );
+3 -2
View File
@@ -24,10 +24,11 @@ require_once( $wp_load );
$ret['error'] = null;
$ret = array();
if ( ! is_user_logged_in() ) {
/* 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'];