options()->get( 'profile_tab_main' ) && ! isset( $_REQUEST['um_action'] ) )
return;
$can_view = apply_filters( 'um_profile_can_view_main', -1, um_profile_id() );
if ($can_view == -1) {
do_action( "um_before_form", $args );
do_action( "um_before_{$mode}_fields", $args );
do_action( "um_main_{$mode}_fields", $args );
do_action( "um_after_form_fields", $args );
do_action( "um_after_{$mode}_fields", $args );
do_action( "um_after_form", $args );
} else {
?>
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_can_edit_field( $fields[$key] ) && 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];
} else if ($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'] ) ) {
global $wp_roles;
$role_keys = array_map( function( $item ) {
return 'um_' . $item;
}, get_option( 'um_roles' ) );
$exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) );
if ( ! in_array( $args['submitted']['role'], $exclude_roles ) ) {
$to_update['role'] = $args['submitted']['role'];
}
$args['roles_before_upgrade'] = UM()->roles()->get_all_user_roles( um_user( 'ID' ) );
}
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' ), $args, $to_update );
}
$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 ) ) );
}
}
/**
* Leave roles for User, which are not in the list of update profile (are default WP or 3rd plugins roles)
*
* @param $user_id
* @param $args
* @param $to_update
*/
function um_restore_default_roles( $user_id, $args, $to_update ) {
if ( ! empty( $args['submitted']['role'] ) ) {
$wp_user = new WP_User( $user_id );
$role_keys = array_map( function( $item ) {
return 'um_' . $item;
}, get_option( 'um_roles' ) );
$leave_roles = array_diff( $args['roles_before_upgrade'], array_merge( $role_keys, array( 'subscriber' ) ) );
if ( UM()->roles()->is_role_custom( $to_update['role'] ) ) {
$wp_user->remove_role( $to_update['role'] );
$roles = array_merge( $leave_roles, array( $to_update['role'] ) );
} else {
$roles = array_merge( array( $to_update['role'] ), $leave_roles );
}
foreach ( $roles as $role_k ) {
$wp_user->add_role( $role_k );
}
}
}
add_action( 'um_after_user_updated', 'um_restore_default_roles', 10, 3 );
/***
*** @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) { ?>
options()->get( 'profile_desc' ) );
$user_id = um_user( 'ID' );
$url = um_user_profile_url();
if (um_profile( 'profile_photo' )) {
$avatar = um_user_uploads_uri() . um_profile( 'profile_photo' );
} else {
$avatar = um_get_default_avatar_uri();
}
um_reset_user(); ?>
options()->get( 'default_cover' );
$overlay = '
' . __( '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 ))
return false;
do_action( 'um_user_edit_profile', $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;
?>
options()->get( 'profile_menu' ) )
return;
// get active tabs
$tabs = UM()->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()->options()->get( '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
*/
function um_before_user_upload( $user_id, $arr_files ) {
um_fetch_user( $user_id );
foreach ( $arr_files as $key => $filename ) {
if ( um_user( $key ) ) {
$old_filename = um_user( $key );
if ( basename( $filename ) != basename( um_user( $key ) ) ||
in_array( $old_filename, array( basename( um_user( $key ) ), basename( $filename ) ) ) ||
$filename == 'empty_file' ) {
$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 );
}
}
}
}
}
add_action( "um_before_user_upload", "um_before_user_upload", 10, 2 );