roles()->um_current_user_can('edit', $args['user_id'] ) ) {
UM()->user()->set( $args['user_id'] );
} else {
wp_die( __('You are not allowed to edit this user.','ultimate-member') );
}
} else if ( isset( $args['_user_id'] ) ) {
UM()->user()->set( $args['_user_id'] );
}
$userinfo = UM()->user()->profile;
do_action( 'um_user_before_updating_profile', $userinfo );
if ( ! empty( $args['custom_fields'] ) )
$fields = unserialize( $args['custom_fields'] );
// loop through fields
if ( ! empty( $fields ) ) {
foreach ( $fields as $key => $array ) {
if( ! UM()->roles()->um_user_can( 'can_edit_everyone' ) && isset( $fields[$key]['editable'] ) && ! $fields[$key]['editable'] )
continue;
if ( $fields[$key]['type'] == 'multiselect' || $fields[$key]['type'] == 'checkbox' && ! isset( $args['submitted'][$key] ) ) {
delete_user_meta( um_user('ID'), $key );
}
if ( isset( $args['submitted'][ $key ] ) ) {
if ( isset( $fields[$key]['type'] ) && in_array( $fields[$key]['type'], array('image','file') ) &&
( um_is_temp_upload( $args['submitted'][ $key ] ) || $args['submitted'][ $key ] == 'empty_file' ) ) {
$files[ $key ] = $args['submitted'][ $key ];
} else {
if ( isset( $userinfo[$key] ) && $args['submitted'][$key] != $userinfo[$key] ) {
$to_update[ $key ] = $args['submitted'][ $key ];
} elseif ( $args['submitted'][$key] ) {
$to_update[ $key ] = $args['submitted'][ $key ];
}
}
}
}
}
if ( isset( $args['submitted']['description'] ) ) {
$to_update['description'] = $args['submitted']['description'];
}
if ( ! empty( $args['submitted']['role'] ) ) {
$to_update['role'] = $args['submitted']['role'];
}
do_action( 'um_user_pre_updating_profile', $to_update );
$to_update = apply_filters( 'um_user_pre_updating_profile_array', $to_update );
if ( is_array( $to_update ) ) {
UM()->user()->update_profile( $to_update );
do_action( 'um_after_user_updated', um_user('ID') );
}
$files = apply_filters( 'um_user_pre_updating_files_array', $files );
if ( is_array( $files ) ) {
do_action('um_before_user_upload', um_user('ID'), $files );
UM()->user()->update_files( $files );
do_action( 'um_after_user_upload', um_user('ID'), $files );
}
do_action( 'um_user_after_updating_profile', $to_update );
do_action( 'um_update_profile_full_name', $to_update );
if ( ! isset( $args['is_signup'] ) ) {
$url = UM()->user()->get_profile_url( um_user('ID'), true );
exit( wp_redirect( um_edit_my_profile_cancel_uri( $url ) ) );
}
}
/***
*** @if editing another user
***/
add_action('um_after_form_fields', 'um_editing_user_id_input');
function um_editing_user_id_input($args){
if ( UM()->fields()->editing == 1 && UM()->fields()->set_mode == 'profile' && UM()->user()->target_id ) { ?>
'.__('Change your cover photo','ultimate-member').'
';
?>
fields()->editing ) {
$items = array(
'
'.__('Change cover photo','ultimate-member').'',
'
'.__('Remove','ultimate-member').'',
'
'.__('Cancel','ultimate-member').'',
);
echo UM()->menu()->new_ui( 'bc', 'div.um-cover', 'click', $items );
}
?>
fields()->add_hidden_field( 'cover_photo' ); ?>
mobile()->isMobile() ){
if ( UM()->mobile()->isTablet() ) {
echo um_user('cover_photo', 1000);
} else {
echo um_user('cover_photo', 300);
}
} else {
echo um_user('cover_photo', 1000);
}
?>
';
} else {
if ( !isset( UM()->user()->cannot_edit ) ) { ?>
';
UM()->fields()->show_social_urls();
echo '';
}
}
/***
*** @profile header
***/
add_action('um_profile_header', 'um_profile_header', 9 );
function um_profile_header( $args ) {
$classes = null;
if ( !$args['cover_enabled'] ) {
$classes .= ' no-cover';
}
$default_size = str_replace( 'px', '', $args['photosize'] );
$overlay = '
';
?>
fields()->editing == false ) {
UM()->fields()->viewing = 1;
if ( um_get_requested_user() ) {
if ( ! um_can_view_profile( um_get_requested_user() ) && ! um_is_myprofile() )
um_redirect_home();
if ( ! UM()->roles()->um_current_user_can( 'edit', um_get_requested_user() ) )
UM()->user()->cannot_edit = 1;
um_fetch_user( um_get_requested_user() );
} else {
if ( !is_user_logged_in() ) um_redirect_home();
if ( !um_user('can_edit_profile') ) UM()->user()->cannot_edit = 1;
}
}
if ( $mode == 'profile' && UM()->fields()->editing == true ) {
UM()->fields()->editing = 1;
if ( um_get_requested_user() ) {
if ( ! UM()->roles()->um_current_user_can('edit', um_get_requested_user() ) ) um_redirect_home();
um_fetch_user( um_get_requested_user() );
}
}
}
/***
*** @display the edit profile icon
***/
add_action('um_pre_header_editprofile', 'um_add_edit_icon' );
function um_add_edit_icon( $args ) {
$output = '';
if ( !is_user_logged_in() ) return; // not allowed for guests
if ( isset( UM()->user()->cannot_edit ) && UM()->user()->cannot_edit == 1 ) return; // do not proceed if user cannot edit
if ( UM()->fields()->editing == true ) {
?>
fields()->editing == true ) {
echo UM()->fields()->display( 'profile', $args );
} else {
UM()->fields()->viewing = true;
echo UM()->fields()->display_view( 'profile', $args );
}
}
/***
*** @form processing
***/
add_action('um_submit_form_profile', 'um_submit_form_profile', 10);
function um_submit_form_profile($args){
if ( !isset( UM()->form()->errors) ) do_action('um_user_edit_profile', $args);
do_action('um_user_profile_extra_hook', $args );
}
/***
*** @Show the submit button (highest priority)
***/
add_action('um_after_profile_fields', 'um_add_submit_button_to_profile', 1000);
function um_add_submit_button_to_profile($args){
// DO NOT add when reviewing user's details
if ( UM()->user()->preview == true && is_admin() ) return;
// only when editing
if ( UM()->fields()->editing == false ) return;
?>
profile()->tabs_active();
$tabs = apply_filters('um_user_profile_tabs', $tabs );
UM()->user()->tabs = $tabs;
// need enough tabs to continue
if ( count( $tabs ) <= 1 ) return;
$active_tab = UM()->profile()->active_tab();
if ( !isset( $tabs[$active_tab] ) ) {
$active_tab = 'main';
UM()->profile()->active_tab = $active_tab;
UM()->profile()->active_subnav = null;
}
// Move default tab priority
$default_tab = um_get_option('profile_menu_default_tab');
$dtab = ( isset( $tabs[$default_tab] ) )? $tabs[$default_tab] : 'main';
if ( isset( $tabs[ $default_tab ] ) ) {
unset( $tabs[$default_tab] );
$dtabs[$default_tab] = $dtab;
$tabs = $dtabs + $tabs;
}
?>
$tab ) {
if ( isset( $tab['hidden'] ) ) continue;
$nav_link = UM()->permalinks()->get_current_url( get_option('permalink_structure') );
$nav_link = remove_query_arg( 'um_action', $nav_link );
$nav_link = remove_query_arg( 'subnav', $nav_link );
$nav_link = add_query_arg('profiletab', $id, $nav_link );
$nav_link = apply_filters("um_profile_menu_link_{$id}", $nav_link);
?>
$tab ) {
if ( isset( $tab['subnav'] ) && $active_tab == $id ) {
$active_subnav = ( UM()->profile()->active_subnav() ) ? UM()->profile()->active_subnav() : $tab['subnav_default'];
echo '';
foreach( $tab['subnav'] as $id => $subtab ) {
?>
';
}
}
}
/**
* Clean up file for new uploaded files
* @param integer $user_id
* @param array $arr_files
*/
add_action( "um_before_user_upload","um_before_user_upload", 10 ,2 );
function um_before_user_upload( $user_id, $arr_files ){
um_fetch_user( $user_id );
foreach ($arr_files as $key => $filename ) {
if( um_user( $key ) ){
if( basename( $filename ) != basename( um_user( $key ) ) || in_array( $old_filename , array( basename( um_user( $key ) ), basename( $filename ) ) ) || $filename == 'empty_file' ){
$old_filename = um_user( $key );
$path = UM()->files()->upload_basedir;
delete_user_meta( $user_id, $old_filename );
if ( file_exists( $path . $user_id . '/' . $old_filename ) ) {
unlink( $path . $user_id . '/' . $old_filename );
}
}
}
}
}