2014-12-15 22:38:07 +02:00
< ? php
/***
*** @submit account page changes
***/
add_action ( 'um_submit_account_details' , 'um_submit_account_details' );
function um_submit_account_details ( $args ) {
global $ultimatemember ;
if ( $_POST [ 'user_password' ] && $_POST [ 'confirm_user_password' ] ) {
$changes [ 'user_pass' ] = $_POST [ 'user_password' ];
}
2015-02-04 20:31:39 +02:00
2014-12-15 22:38:07 +02:00
foreach ( $_POST as $k => $v ) {
if ( ! strstr ( $k , 'password' ) && ! strstr ( $k , 'um_account' ) ) {
$changes [ $k ] = $v ;
}
}
2015-01-11 19:07:55 +02:00
if ( isset ( $changes [ 'hide_in_members' ] ) && $changes [ 'hide_in_members' ] == 'No' ){
delete_user_meta ( um_user ( 'ID' ), 'hide_in_members' );
unset ( $changes [ 'hide_in_members' ] );
}
2014-12-15 22:38:07 +02:00
2015-02-19 00:49:08 +02:00
// fired on account page, just before updating profile
do_action ( 'um_account_pre_update_profile' , $changes , um_user ( 'ID' ) );
2014-12-15 22:38:07 +02:00
$ultimatemember -> user -> update_profile ( $changes );
// delete account
2015-02-02 02:10:06 +02:00
if ( $_POST [ 'single_user_password' ] && isset ( $_POST [ 'um_account_submit' ]) && $_POST [ 'um_account_submit' ] == __ ( 'Delete Account' , 'ultimatemember' ) ) {
2014-12-15 22:38:07 +02:00
if ( current_user_can ( 'delete_users' ) || um_user ( 'can_delete_profile' ) ) {
if ( ! um_user ( 'super_admin' ) ) {
$ultimatemember -> user -> delete ();
2015-02-23 01:43:11 +02:00
if ( um_user ( 'after_delete' ) && um_user ( 'after_delete' ) == 'redirect_home' ) {
2015-01-03 15:31:15 +02:00
um_redirect_home ();
2015-02-23 01:43:11 +02:00
} elseif ( um_user ( 'delete_redirect_url' ) ) {
2014-12-15 22:38:07 +02:00
exit ( wp_redirect ( um_user ( 'delete_redirect_url' ) ) );
2015-02-23 01:43:11 +02:00
} else {
um_redirect_home ();
2014-12-15 22:38:07 +02:00
}
}
}
}
2015-02-11 00:50:38 +02:00
do_action ( 'um_post_account_update' );
2015-02-10 02:05:27 +02:00
2015-02-04 20:31:39 +02:00
$tab = ( get_query_var ( 'um_tab' ) ) ? get_query_var ( 'um_tab' ) : 'general' ;
2015-02-11 00:50:38 +02:00
$url = $ultimatemember -> account -> tab_link ( $tab );
$url = add_query_arg ( 'updated' , 'account' , $url );
exit ( wp_redirect ( $url ) );
2014-12-15 22:38:07 +02:00
}
/***
*** @validate for errors in account page
***/
add_action ( 'um_submit_account_errors_hook' , 'um_submit_account_errors_hook' );
function um_submit_account_errors_hook ( $args ) {
global $ultimatemember ;
2015-02-23 01:43:11 +02:00
// errors on general tab
if ( isset ( $_POST [ 'um_account_submit' ]) && ! $_POST [ 'um_account_submit' ] == __ ( 'Delete Account' , 'ultimatemember' ) ) {
if ( isset ( $_POST [ 'first_name' ]) && strlen ( trim ( $_POST [ 'first_name' ] ) ) == 0 ) {
$ultimatemember -> form -> add_error ( 'first_name' , __ ( 'You must provide your first name' , 'ultimatemember' ) );
}
if ( isset ( $_POST [ 'last_name' ]) && strlen ( trim ( $_POST [ 'last_name' ] ) ) == 0 ) {
$ultimatemember -> form -> add_error ( 'last_name' , __ ( 'You must provide your last name' , 'ultimatemember' ) );
}
if ( isset ( $_POST [ 'user_email' ]) && strlen ( trim ( $_POST [ 'user_email' ] ) ) == 0 ) {
$ultimatemember -> form -> add_error ( 'user_email' , __ ( 'You must provide your e-mail' , 'ultimatemember' ) );
}
if ( isset ( $_POST [ 'user_email' ]) && ! is_email ( $_POST [ 'user_email' ] ) ) {
$ultimatemember -> form -> add_error ( 'user_email' , __ ( 'Please provide a valid e-mail' , 'ultimatemember' ) );
}
2014-12-15 22:38:07 +02:00
}
$ultimatemember -> account -> current_tab = 'general' ;
2015-02-23 01:43:11 +02:00
// change password
2014-12-15 22:38:07 +02:00
if ( $_POST [ 'current_user_password' ] != '' ) {
if ( ! wp_check_password ( $_POST [ 'current_user_password' ], um_user ( 'user_pass' ), um_user ( 'ID' ) ) ) {
2015-02-18 00:45:09 +02:00
$ultimatemember -> form -> add_error ( 'current_user_password' , __ ( 'This is not your password' , 'ultimatemember' ) );
2014-12-15 22:38:07 +02:00
$ultimatemember -> account -> current_tab = 'password' ;
} else { // correct password
if ( $_POST [ 'user_password' ] != $_POST [ 'confirm_user_password' ] && $_POST [ 'user_password' ] ) {
2015-02-11 00:50:38 +02:00
$ultimatemember -> form -> add_error ( 'user_password' , __ ( 'Your new password does not match' , 'ultimatemember' ) );
2014-12-15 22:38:07 +02:00
$ultimatemember -> account -> current_tab = 'password' ;
}
2015-02-11 00:50:38 +02:00
if ( um_get_option ( 'account_require_strongpass' ) ) {
if ( strlen ( utf8_decode ( $_POST [ 'user_password' ] ) ) < 8 ) {
$ultimatemember -> form -> add_error ( 'user_password' , __ ( 'Your password must contain at least 8 characters' , 'ultimatemember' ) );
}
2014-12-15 22:38:07 +02:00
2015-02-11 00:50:38 +02:00
if ( strlen ( utf8_decode ( $_POST [ 'user_password' ] ) ) > 30 ) {
$ultimatemember -> form -> add_error ( 'user_password' , __ ( 'Your password must contain less than 30 characters' , 'ultimatemember' ) );
}
if ( ! $ultimatemember -> validation -> strong_pass ( $_POST [ 'user_password' ] ) ) {
$ultimatemember -> form -> add_error ( 'user_password' , __ ( 'Your password must contain at least one lowercase letter, one capital letter and one number' , 'ultimatemember' ) );
$ultimatemember -> account -> current_tab = 'password' ;
}
2014-12-15 22:38:07 +02:00
}
}
}
2015-02-23 01:43:11 +02:00
// delete account
2015-02-02 02:10:06 +02:00
if ( isset ( $_POST [ 'um_account_submit' ]) && $_POST [ 'um_account_submit' ] == __ ( 'Delete Account' , 'ultimatemember' ) ) {
2014-12-15 22:38:07 +02:00
if ( strlen ( trim ( $_POST [ 'single_user_password' ] ) ) == 0 ) {
2015-02-18 00:45:09 +02:00
$ultimatemember -> form -> add_error ( 'single_user_password' , __ ( 'You must enter your password' , 'ultimatemember' ) );
2014-12-15 22:38:07 +02:00
} else {
if ( ! wp_check_password ( $_POST [ 'single_user_password' ], um_user ( 'user_pass' ), um_user ( 'ID' ) ) ) {
2015-02-18 00:45:09 +02:00
$ultimatemember -> form -> add_error ( 'single_user_password' , __ ( 'This is not your password' , 'ultimatemember' ) );
2014-12-15 22:38:07 +02:00
}
}
$ultimatemember -> account -> current_tab = 'delete' ;
}
}
/***
*** @hidden inputs for account page
***/
add_action ( 'um_account_page_hidden_fields' , 'um_account_page_hidden_fields' );
function um_account_page_hidden_fields ( $args ) {
?>
<input type="hidden" name="_um_account" id="_um_account" value="1" />
<?php
}
/***
*** @display tab "Delete"
***/
add_action('um_account_tab__delete', 'um_account_tab__delete');
function um_account_tab__delete( $info ) {
global $ultimatemember;
extract( $info );
2015-01-03 15:31:15 +02:00
$output = $ultimatemember->account->get_tab_output('delete');
if ( $output ) { ?>
2014-12-15 22:38:07 +02:00
2015-01-14 00:11:38 +02:00
<div class="um-account-heading uimob300-hide uimob500-hide"><i class="<?php echo $icon; ?>"></i><?php echo $title; ?></div>
2014-12-15 22:38:07 +02:00
<?php echo wpautop( um_get_option('delete_account_text') ); ?>
2015-01-03 15:31:15 +02:00
<?php echo $output; ?>
2014-12-15 22:38:07 +02:00
2015-03-07 13:07:49 +02:00
<?php do_action('um_after_account_delete'); ?>
2015-03-01 00:44:04 +02:00
<div class="um-col-alt um-col-alt-b">
<div class="um-left"><input type="submit" name="um_account_submit" id="um_account_submit" value="<?php _e('Delete Account','ultimatemember'); ?>" class="um-button" /></div>
<?php do_action('um_after_account_delete_button'); ?>
<div class="um-clear"></div>
</div>
2014-12-15 22:38:07 +02:00
<?php
2015-01-03 15:31:15 +02:00
}
2015-03-07 13:07:49 +02:00
2014-12-15 22:38:07 +02:00
}
/***
*** @display tab "Privacy"
***/
add_action('um_account_tab__privacy', 'um_account_tab__privacy');
function um_account_tab__privacy( $info ) {
global $ultimatemember;
extract( $info );
2015-01-03 15:31:15 +02:00
$output = $ultimatemember->account->get_tab_output('privacy');
if ( $output ) { ?>
2014-12-15 22:38:07 +02:00
2015-01-14 00:11:38 +02:00
<div class="um-account-heading uimob340-hide uimob500-hide"><i class="<?php echo $icon; ?>"></i><?php echo $title; ?></div>
2014-12-15 22:38:07 +02:00
2015-01-03 15:31:15 +02:00
<?php echo $output; ?>
2014-12-15 22:38:07 +02:00
2015-03-07 13:07:49 +02:00
<?php do_action('um_after_account_privacy'); ?>
2015-03-01 00:44:04 +02:00
<div class="um-col-alt um-col-alt-b">
<div class="um-left"><input type="submit" name="um_account_submit" id="um_account_submit" value="<?php _e('Update Privacy','ultimatemember'); ?>" class="um-button" /></div>
<?php do_action('um_after_account_privacy_button'); ?>
<div class="um-clear"></div>
</div>
2014-12-15 22:38:07 +02:00
<?php
2015-01-03 15:31:15 +02:00
}
2015-03-07 13:07:49 +02:00
2014-12-15 22:38:07 +02:00
}
/***
*** @display tab "General"
***/
add_action('um_account_tab__general', 'um_account_tab__general');
function um_account_tab__general( $info ) {
global $ultimatemember;
extract( $info );
2015-03-01 00:44:04 +02:00
2015-01-03 15:31:15 +02:00
$output = $ultimatemember->account->get_tab_output('general');
if ( $output ) { ?>
2014-12-15 22:38:07 +02:00
2015-01-14 00:11:38 +02:00
<div class="um-account-heading uimob340-hide uimob500-hide"><i class="<?php echo $icon; ?>"></i><?php echo $title; ?></div>
2014-12-15 22:38:07 +02:00
2015-01-03 15:31:15 +02:00
<?php echo $output; ?>
2014-12-15 22:38:07 +02:00
2015-03-07 13:07:49 +02:00
<?php do_action('um_after_account_general'); ?>
2015-03-01 00:44:04 +02:00
<div class="um-col-alt um-col-alt-b">
<div class="um-left"><input type="submit" name="um_account_submit" id="um_account_submit" value="<?php _e('Update Account','ultimatemember'); ?>" class="um-button" /></div>
<?php do_action('um_after_account_general_button'); ?>
<div class="um-clear"></div>
</div>
2014-12-15 22:38:07 +02:00
<?php
2015-03-01 00:44:04 +02:00
2015-01-03 15:31:15 +02:00
}
2015-03-07 13:07:49 +02:00
2014-12-15 22:38:07 +02:00
}
/***
*** @display tab "Password"
***/
add_action('um_account_tab__password', 'um_account_tab__password');
function um_account_tab__password( $info ) {
global $ultimatemember;
extract( $info );
2015-01-03 15:31:15 +02:00
$output = $ultimatemember->account->get_tab_output('password');
if ( $output ) { ?>
2014-12-15 22:38:07 +02:00
2015-01-14 00:11:38 +02:00
<div class="um-account-heading uimob340-hide uimob500-hide"><i class="<?php echo $icon; ?>"></i><?php echo $title; ?></div>
2014-12-15 22:38:07 +02:00
2015-01-03 15:31:15 +02:00
<?php echo $output; ?>
2014-12-15 22:38:07 +02:00
2015-03-07 13:07:49 +02:00
<?php do_action('um_after_account_password'); ?>
2015-03-01 00:44:04 +02:00
<div class="um-col-alt um-col-alt-b">
<div class="um-left"><input type="submit" name="um_account_submit" id="um_account_submit" value="<?php _e('Update Password','ultimatemember'); ?>" class="um-button" /></div>
<?php do_action('um_after_account_password_button'); ?>
<div class="um-clear"></div>
</div>
2014-12-15 22:38:07 +02:00
<?php
2015-02-10 02:05:27 +02:00
}
2015-03-07 13:07:49 +02:00
2015-02-10 02:05:27 +02:00
}
/***
*** @display tab "Notifications"
***/
add_action('um_account_tab__notifications', 'um_account_tab__notifications');
function um_account_tab__notifications( $info ) {
global $ultimatemember;
extract( $info );
$output = $ultimatemember->account->get_tab_output('notifications');
if ( $output ) { ?>
<div class="um-account-heading uimob340-hide uimob500-hide"><i class="<?php echo $icon; ?>"></i><?php echo $title; ?></div>
<?php echo $output; ?>
2015-03-07 13:07:49 +02:00
<?php do_action('um_after_account_notifications'); ?>
2015-03-01 00:44:04 +02:00
<div class="um-col-alt um-col-alt-b">
<div class="um-left"><input type="submit" name="um_account_submit" id="um_account_submit" value="<?php _e('Update Notifications','ultimatemember'); ?>" class="um-button" /></div>
<?php do_action('um_after_account_notifications_button'); ?>
<div class="um-clear"></div>
</div>
2015-02-10 02:05:27 +02:00
<?php
2015-03-01 00:44:04 +02:00
2015-01-03 15:31:15 +02:00
}
2015-03-07 13:07:49 +02:00
2014-12-15 22:38:07 +02:00
}
/***
2014-12-19 00:42:23 +02:00
*** @display account photo and username
***/
add_action('um_account_user_photo_hook__mobile', 'um_account_user_photo_hook__mobile');
function um_account_user_photo_hook__mobile( $args ) {
global $ultimatemember;
extract( $args );
?>
2015-01-14 00:11:38 +02:00
<div class="um-account-meta radius-<?php echo um_get_option('profile_photocorner'); ?> uimob340-show uimob500-show">
2014-12-19 00:42:23 +02:00
2015-01-26 16:58:31 +02:00
<div class="um-account-meta-img"><a href="<?php echo um_user_profile_url(); ?>"><?php echo get_avatar( um_user('ID'), 120); ?></a></div>
2014-12-19 00:42:23 +02:00
<div class="um-account-name"><a href="<?php echo um_user_profile_url(); ?>"><?php echo um_user('display_name'); ?></a></div>
</div>
<?php
}
/***
*** @display account photo and username
2014-12-15 22:38:07 +02:00
***/
add_action('um_account_user_photo_hook', 'um_account_user_photo_hook');
function um_account_user_photo_hook( $args ) {
global $ultimatemember;
extract( $args );
?>
2015-01-07 08:37:25 +02:00
<div class="um-account-meta radius-<?php echo um_get_option('profile_photocorner'); ?>">
2014-12-15 22:38:07 +02:00
2015-01-26 16:58:31 +02:00
<div class="um-account-meta-img uimob800-hide"><a href="<?php echo um_user_profile_url(); ?>"><?php echo get_avatar( um_user('ID'), 120); ?></a></div>
2014-12-15 22:38:07 +02:00
2015-01-14 00:11:38 +02:00
<?php if ( $ultimatemember->mobile->isMobile() ) { ?>
2015-01-26 16:58:31 +02:00
<div class="um-account-meta-img-b uimob800-show" title="<?php echo um_user('display_name'); ?>"><a href="<?php echo um_user_profile_url(); ?>"><?php echo get_avatar( um_user('ID'), 120); ?></a></div>
2015-01-14 00:11:38 +02:00
<?php } else { ?>
2015-01-26 16:58:31 +02:00
<div class="um-account-meta-img-b uimob800-show um-tip-w" title="<?php echo um_user('display_name'); ?>"><a href="<?php echo um_user_profile_url(); ?>"><?php echo get_avatar( um_user('ID'), 120); ?></a></div>
2014-12-19 00:42:23 +02:00
2015-01-14 00:11:38 +02:00
<?php } ?>
2014-12-19 00:42:23 +02:00
<div class="um-account-name uimob800-hide"><a href="<?php echo um_user_profile_url(); ?>"><?php echo um_user('display_name'); ?></a></div>
2014-12-15 22:38:07 +02:00
</div>
<?php
}
/***
*** @display account page tabs
***/
add_action('um_account_display_tabs_hook', 'um_account_display_tabs_hook');
function um_account_display_tabs_hook( $args ) {
global $ultimatemember;
extract( $args );
2015-02-19 00:49:08 +02:00
$ultimatemember->account->tabs = apply_filters('um_account_page_default_tabs_hook', $tabs=array() );
2014-12-15 22:38:07 +02:00
2015-02-19 00:49:08 +02:00
ksort( $ultimatemember->account->tabs );
2014-12-15 22:38:07 +02:00
?>
<ul>
<?php
foreach( $ultimatemember->account->tabs as $k => $arr ) {
foreach( $arr as $id => $info ) { extract( $info );
$current_tab = $ultimatemember->account->current_tab;
2015-02-23 01:43:11 +02:00
if ( isset($info['custom']) || um_get_option('account_tab_'.$id ) == 1 || $id == 'general' ) { ?>
2014-12-15 22:38:07 +02:00
<li>
<a data-tab="<?php echo $id; ?>" href="<?php echo $ultimatemember->account->tab_link($id); ?>" class="um-account-link <?php if ( $id == $current_tab ) echo 'current'; ?>">
2015-01-14 00:11:38 +02:00
<?php if ( $ultimatemember->mobile->isMobile() ) { ?>
<span class="um-account-icontip uimob800-show" title="<?php echo $title; ?>"><i class="<?php echo $icon; ?>"></i></span>
<?php } else { ?>
2014-12-19 00:42:23 +02:00
<span class="um-account-icontip uimob800-show um-tip-w" title="<?php echo $title; ?>"><i class="<?php echo $icon; ?>"></i></span>
2015-01-14 00:11:38 +02:00
<?php } ?>
2014-12-19 00:42:23 +02:00
<span class="um-account-icon uimob800-hide"><i class="<?php echo $icon; ?>"></i></span>
<span class="um-account-title uimob800-hide"><?php echo $title; ?></span>
2015-01-15 17:15:12 +02:00
<span class="um-account-arrow uimob800-hide"><i class="um-faicon-angle-right"></i></span>
2014-12-15 22:38:07 +02:00
</a>
</li>
<?php
}
}
}
?>
</ul>
<?php
}