2014-12-15 22:38:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
2015-02-08 01:49:10 +02:00
|
|
|
/***
|
|
|
|
|
*** @after user uploads, clean up uploads dir
|
|
|
|
|
***/
|
|
|
|
|
add_action('um_after_user_upload','um_remove_unused_uploads', 10);
|
|
|
|
|
function um_remove_unused_uploads( $user_id ) {
|
|
|
|
|
global $ultimatemember;
|
2015-02-17 00:51:40 +02:00
|
|
|
|
2015-02-08 01:49:10 +02:00
|
|
|
um_fetch_user( $user_id );
|
2015-02-09 00:29:16 +02:00
|
|
|
|
2015-02-08 01:49:10 +02:00
|
|
|
$array = $ultimatemember->user->profile;
|
2015-02-17 00:51:40 +02:00
|
|
|
|
2015-02-08 01:49:10 +02:00
|
|
|
$files = glob( um_user_uploads_dir() . '*', GLOB_BRACE);
|
2015-02-17 00:51:40 +02:00
|
|
|
|
|
|
|
|
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') && !preg_grep('/' . $str . '/', $array ) )
|
|
|
|
|
unlink( $file );
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-08 01:49:10 +02:00
|
|
|
}
|
2015-02-09 00:29:16 +02:00
|
|
|
|
2015-02-08 01:49:10 +02:00
|
|
|
}
|
|
|
|
|
|
2014-12-15 22:38:07 +02:00
|
|
|
/***
|
|
|
|
|
*** @listen to a new user creation in backend
|
|
|
|
|
***/
|
2015-02-08 01:49:10 +02:00
|
|
|
add_action( 'user_register', 'um_new_user_via_wpadmin', 10, 1 );
|
2014-12-15 22:38:07 +02:00
|
|
|
function um_new_user_via_wpadmin( $user_id ) {
|
|
|
|
|
|
|
|
|
|
if ( is_admin() ) {
|
|
|
|
|
|
|
|
|
|
global $ultimatemember;
|
|
|
|
|
|
|
|
|
|
if ( isset( $_POST['role'] ) && $_POST['role'] == 'administrator' ) {
|
|
|
|
|
$args['role'] = 'admin';
|
|
|
|
|
} else {
|
|
|
|
|
$args['role'] = 'member';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
do_action('um_after_new_user_register', $user_id, $args);
|
|
|
|
|
|
|
|
|
|
do_action('um_update_profile_full_name', $_POST);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-08 01:49:10 +02:00
|
|
|
}
|