Files
ultimatemember/core/um-actions-profile.php
T

470 lines
14 KiB
PHP
Raw Normal View History

2014-12-15 22:38:07 +02:00
<?php
2015-01-11 23:12:05 +02:00
/***
*** @update user's profile
***/
add_action('um_user_edit_profile', 'um_user_edit_profile', 10);
function um_user_edit_profile($args){
global $ultimatemember;
$to_update = null;
$files = null;
if ( isset( $args['user_id'] ) ) {
if ( um_current_user_can('edit', $args['user_id'] ) ) {
$ultimatemember->user->set( $args['user_id'] );
} else {
wp_die( __('You are not allowed to edit this user.','ultimatemember') );
}
} else if ( isset( $args['_user_id'] ) ) {
$ultimatemember->user->set( $args['_user_id'] );
}
$userinfo = $ultimatemember->user->profile;
$fields = unserialize( $args['custom_fields'] );
do_action('um_user_before_updating_profile', $userinfo );
// loop through fields
foreach( $fields as $key => $array ) {
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( $userinfo[$key]) && $args['submitted'][$key] != $userinfo[$key] ) {
$to_update[ $key ] = $args['submitted'][ $key ];
} else if ( $args['submitted'][$key] ) {
$to_update[ $key ] = $args['submitted'][ $key ];
}
// files
if ( isset( $fields[$key]['type'] ) && in_array( $fields[$key]['type'], array('image','file') ) && um_is_temp_upload( $args['submitted'][ $key ] ) ) {
$files[ $key ] = $args['submitted'][ $key ];
}
}
}
if ( isset( $args['submitted']['description'] ) ) {
$to_update['description'] = $ultimatemember->validation->remove_html( $args['submitted']['description'] );
}
if ( is_array( $to_update ) ) {
$ultimatemember->user->update_profile( $to_update );
}
if ( is_array( $files ) ) {
$ultimatemember->user->update_files( $files );
}
do_action('um_user_after_updating_profile', $to_update );
if ( !isset( $args['is_signup'] ) ) {
exit( wp_redirect( um_edit_my_profile_cancel_uri() ) );
}
}
2014-12-15 22:38:07 +02:00
/***
*** @if editing another user
***/
add_action('um_after_form_fields', 'um_editing_user_id_input');
function um_editing_user_id_input($args){
global $ultimatemember;
if ( $ultimatemember->fields->editing == 1 && $ultimatemember->fields->set_mode == 'profile' && $ultimatemember->user->target_id ) { ?>
<input type="hidden" name="user_id" id="user_id" value="<?php echo $ultimatemember->user->target_id; ?>" />
<?php
}
}
/***
*** @meta description
***/
add_action('wp_head', 'um_profile_dynamic_meta_desc', 9999999);
function um_profile_dynamic_meta_desc() {
global $ultimatemember;
2014-12-22 01:45:24 +02:00
if ( um_is_core_page('user') && um_get_requested_user() ) {
2014-12-15 22:38:07 +02:00
um_fetch_user( um_get_requested_user() );
$content = $ultimatemember->mail->convert_tags( um_get_option('profile_desc') );
um_reset_user();
?>
<meta name="description" content="<?php echo $content; ?>">
<?php
}
}
/***
*** @profile header cover
***/
add_action('um_profile_header_cover_area', 'um_profile_header_cover_area' );
function um_profile_header_cover_area( $args ) {
global $ultimatemember;
2014-12-29 15:51:55 +02:00
2014-12-15 22:38:07 +02:00
if ( $args['cover_enabled'] == 1 ) {
2014-12-29 15:51:55 +02:00
$overlay = '<span class="um-cover-overlay">
<span class="um-cover-overlay-s">
<ins>
<i class="um-icon-photo-2"></i>
<span class="um-cover-overlay-t">'.__('Change your cover photo').'</span>
</ins>
</span>
</span>';
2014-12-15 22:38:07 +02:00
?>
2014-12-29 15:51:55 +02:00
<div class="um-cover <?php if ( um_profile('cover_photo') ) echo 'has-cover'; ?>" data-user_id="<?php echo um_profile_id(); ?>" data-ratio="<?php echo $args['cover_ratio']; ?>">
<?php
2015-01-03 15:31:15 +02:00
if ( $ultimatemember->fields->editing ) {
2015-01-06 00:38:33 +02:00
$items = array(
2015-01-05 03:26:23 +02:00
'<a href="#" class="um-manual-trigger" data-parent=".um-cover" data-child=".um-btn-auto-width">'.__('Change cover photo','ultimatemember').'</a>',
'<a href="#" class="um-reset-cover-photo" data-user_id="'.um_profile_id().'">'.__('Remove','ultimatemember').'</a>',
'<a href="#" class="um-dropdown-hide">'.__('Cancel','ultimatemember').'</a>',
2015-01-06 00:38:33 +02:00
);
echo $ultimatemember->menu->new_ui( 'bc', 'div.um-cover', 'click', $items );
2015-01-03 15:31:15 +02:00
}
2015-01-06 00:38:33 +02:00
2014-12-29 15:51:55 +02:00
?>
<?php $ultimatemember->fields->add_hidden_field( 'cover_photo' ); ?>
<?php echo $overlay; ?>
2014-12-15 22:38:07 +02:00
<div class="um-cover-e">
2014-12-29 15:51:55 +02:00
<?php if ( um_profile('cover_photo') ) { ?>
<?php
if( $ultimatemember->mobile->isMobile() ){
2015-01-05 01:33:17 +02:00
if ( $ultimatemember->mobile->isTablet() ) {
echo um_user('cover_photo', 1000);
} else {
echo um_user('cover_photo', 300);
}
2014-12-29 15:51:55 +02:00
} else {
echo um_user('cover_photo', 1000);
}
?>
<?php } else { ?>
2015-01-05 03:26:23 +02:00
<?php if ( !isset( $ultimatemember->user->cannot_edit ) ) { ?>
2015-01-14 00:09:28 +02:00
<a href="#" class="um-cover-add um-manual-trigger" data-parent=".um-cover" data-child=".um-btn-auto-width"><span class="um-cover-add-i"><i class="um-icon-fontawesome-webfont-97 um-tip-n" title="<?php _e('Upload a cover photo','ultimatemember'); ?>"></i></span></a>
2015-01-05 03:26:23 +02:00
<?php } ?>
2014-12-29 15:51:55 +02:00
2014-12-15 22:38:07 +02:00
<?php } ?>
2014-12-29 15:51:55 +02:00
2014-12-15 22:38:07 +02:00
</div>
2014-12-29 15:51:55 +02:00
2014-12-15 22:38:07 +02:00
</div>
2014-12-29 15:51:55 +02:00
<?php
2014-12-15 22:38:07 +02:00
}
}
/***
*** @profile header
***/
add_action('um_profile_header', 'um_profile_header' );
function um_profile_header( $args ) {
global $ultimatemember;
$classes = null;
if ( !$args['cover_enabled'] ) {
$classes .= ' no-cover';
}
2014-12-29 15:51:55 +02:00
$default_size = str_replace( 'px', '', $args['photosize'] );
$overlay = '<span class="um-profile-photo-overlay">
<span class="um-profile-photo-overlay-s">
<ins>
<i class="um-icon-camera-5"></i>
</ins>
</span>
</span>';
2014-12-15 22:38:07 +02:00
?>
<div class="um-header<?php echo $classes; ?>">
<?php do_action('um_pre_header_editprofile', $args); ?>
2014-12-29 15:51:55 +02:00
<div class="um-profile-photo" data-user_id="<?php echo um_profile_id(); ?>">
<a href="<?php echo um_user_profile_url(); ?>" class="um-profile-photo-img"><?php echo $overlay . um_user('profile_photo', $default_size ); ?></a>
<?php
2015-01-05 01:33:17 +02:00
if ( !isset( $ultimatemember->user->cannot_edit ) ) {
2014-12-29 15:51:55 +02:00
$ultimatemember->fields->add_hidden_field( 'profile_photo' );
if ( !um_profile('profile_photo') ) { // has profile photo
2015-01-06 00:38:33 +02:00
$items = array(
2014-12-29 15:51:55 +02:00
'<a href="#" class="um-manual-trigger" data-parent=".um-profile-photo" data-child=".um-btn-auto-width">'.__('Upload photo','ultimatemember').'</a>',
'<a href="#" class="um-dropdown-hide">'.__('Cancel','ultimatemember').'</a>',
2015-01-06 00:38:33 +02:00
);
echo $ultimatemember->menu->new_ui( 'bc', 'div.um-profile-photo', 'click', $items );
2014-12-29 15:51:55 +02:00
} else if ( $ultimatemember->fields->editing == true ) {
2015-01-06 00:38:33 +02:00
$items = array(
2014-12-29 15:51:55 +02:00
'<a href="#" class="um-manual-trigger" data-parent=".um-profile-photo" data-child=".um-btn-auto-width">'.__('Change photo','ultimatemember').'</a>',
'<a href="#" class="um-reset-profile-photo" data-user_id="'.um_profile_id().'" data-default_src="'.um_get_default_avatar_uri().'">'.__('Remove photo','ultimatemember').'</a>',
'<a href="#" class="um-dropdown-hide">'.__('Cancel','ultimatemember').'</a>',
2015-01-06 00:38:33 +02:00
);
echo $ultimatemember->menu->new_ui( 'bc', 'div.um-profile-photo', 'click', $items );
2014-12-29 15:51:55 +02:00
}
}
?>
2014-12-15 22:38:07 +02:00
</div>
<div class="um-profile-meta">
<div class="um-main-meta">
2014-12-29 21:14:22 +02:00
<?php if ( $args['show_name'] ) { ?>
2014-12-15 22:38:07 +02:00
<div class="um-name"><a href="<?php echo um_user_profile_url(); ?>"><?php echo um_user('display_name'); ?></a></div>
2014-12-29 21:14:22 +02:00
<?php } ?>
2014-12-15 22:38:07 +02:00
<div class="um-clear"></div>
</div>
2014-12-29 15:51:55 +02:00
<?php if ( isset( $args['metafields'] ) && !empty( $args['metafields'] ) ) { ?>
2014-12-15 22:38:07 +02:00
<div class="um-meta">
2014-12-29 15:51:55 +02:00
<?php echo $ultimatemember->profile->show_meta( $args['metafields'] ); ?>
2014-12-15 22:38:07 +02:00
</div>
2014-12-29 15:51:55 +02:00
<?php } ?>
2015-01-03 15:31:15 +02:00
<?php if ( $ultimatemember->fields->viewing == true && um_user('description') && $args['show_bio'] ) { ?>
2014-12-15 22:38:07 +02:00
<div class="um-meta-text"><?php echo um_user('description'); ?></div>
2015-01-03 15:31:15 +02:00
<?php } else if ( $ultimatemember->fields->editing == true && $args['show_bio'] ) { ?>
<div class="um-meta-text">
<textarea placeholder="<?php _e('Tell us a bit about yourself...','ultimatemember'); ?>" name="<?php echo 'description-' . $args['form_id']; ?>" id="<?php echo 'description-' . $args['form_id']; ?>"><?php if ( um_user('description') ) { echo um_user('description'); } ?></textarea>
2015-01-09 03:08:31 +02:00
<?php if ( $ultimatemember->fields->is_error('description') )
echo $ultimatemember->fields->field_error( $ultimatemember->fields->show_error('description') ); ?>
2015-01-03 15:31:15 +02:00
</div>
2014-12-15 22:38:07 +02:00
<?php } ?>
2015-01-05 01:33:17 +02:00
<div class="um-profile-status <?php echo um_user('account_status'); ?>">
<span><?php printf(__('This user account status is %s','ultimatemember'), um_user('account_status_name') ); ?></span>
</div>
2014-12-15 22:38:07 +02:00
</div><div class="um-clear"></div>
</div>
<?php
}
/***
*** @adds profile permissions to view/edit
***/
add_action('um_pre_profile_shortcode', 'um_pre_profile_shortcode');
function um_pre_profile_shortcode($args){
global $ultimatemember;
extract( $args );
if ( $mode == 'profile' && $ultimatemember->fields->editing == false ) {
$ultimatemember->fields->viewing = 1;
if ( um_get_requested_user() ) {
2015-01-03 15:31:15 +02:00
if ( !um_can_view_profile( um_get_requested_user() ) ) um_redirect_home();
2015-01-11 19:07:55 +02:00
if ( !um_current_user_can('edit', um_get_requested_user() ) ) $ultimatemember->user->cannot_edit = 1;
2014-12-15 22:38:07 +02:00
um_fetch_user( um_get_requested_user() );
} else {
2015-01-03 15:31:15 +02:00
if ( !is_user_logged_in() ) um_redirect_home();
2014-12-15 22:38:07 +02:00
if ( !um_user('can_edit_profile') ) $ultimatemember->user->cannot_edit = 1;
}
}
if ( $mode == 'profile' && $ultimatemember->fields->editing == true ) {
$ultimatemember->fields->editing = 1;
if ( um_get_requested_user() ) {
2015-01-11 19:07:55 +02:00
if ( !um_current_user_can('edit', um_get_requested_user() ) ) um_redirect_home();
2014-12-15 22:38:07 +02:00
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 ) {
global $ultimatemember;
$output = '';
if ( !is_user_logged_in() ) return; // not allowed for guests
2015-01-06 00:38:33 +02:00
if ( isset( $ultimatemember->user->cannot_edit ) && $ultimatemember->user->cannot_edit == 1 ) return; // do not proceed if user cannot edit
2014-12-15 22:38:07 +02:00
if ( $ultimatemember->fields->editing == true ) {
2015-01-05 01:33:17 +02:00
?>
<div class="um-profile-edit um-profile-headericon">
2015-01-07 00:12:03 +02:00
<a href="#" class="um-profile-edit-a um-profile-save"><i class="um-icon-check"></i></a>
2015-01-05 01:33:17 +02:00
</div>
<?php } else { ?>
<div class="um-profile-edit um-profile-headericon">
<a href="#" class="um-profile-edit-a"><i class="um-icon-cog-2"></i></a>
<?php
2015-01-06 00:38:33 +02:00
$items = array(
2015-01-05 03:26:23 +02:00
'editprofile' => '<a href="'.um_edit_my_profile_uri().'" class="real_url">'.__('Edit Profile','ultimatemember').'</a>',
2015-01-06 00:38:33 +02:00
'myaccount' => '<a href="'.um_get_core_page('account').'" class="real_url">'.__('My Account','ultimatemember').'</a>',
2015-01-11 23:12:05 +02:00
'logout' => '<a href="'.um_get_core_page('logout').'" class="real_url">'.__('Logout','ultimatemember').'</a>',
2015-01-05 03:26:23 +02:00
'cancel' => '<a href="#" class="um-dropdown-hide">'.__('Cancel','ultimatemember').'</a>',
);
2015-01-06 00:38:33 +02:00
$cancel = $items['cancel'];
2015-01-05 01:33:17 +02:00
2015-01-05 03:26:23 +02:00
if ( !um_is_myprofile() ) {
2015-01-06 00:38:33 +02:00
2015-01-05 01:33:17 +02:00
$actions = $ultimatemember->user->get_admin_actions();
2015-01-06 00:38:33 +02:00
2015-01-11 19:07:55 +02:00
unset( $items['myaccount'] );
2015-01-11 23:12:05 +02:00
unset( $items['logout'] );
2015-01-06 00:38:33 +02:00
unset( $items['cancel'] );
$items = array_merge( $items, $actions );
$items['cancel'] = $cancel;
$items = apply_filters('um_profile_edit_menu_items', $items );
} else {
$items = apply_filters('um_myprofile_edit_menu_items', $items );
2015-01-05 01:33:17 +02:00
}
2015-01-14 00:11:38 +02:00
echo $ultimatemember->menu->new_ui( $args['header_menu'], 'div.um-profile-edit', 'click', $items );
2015-01-05 03:26:23 +02:00
2015-01-05 01:33:17 +02:00
?>
</div>
<?php
2014-12-15 22:38:07 +02:00
}
2015-01-05 01:33:17 +02:00
2014-12-15 22:38:07 +02:00
}
/***
*** @Show Fields
***/
add_action('um_main_profile_fields', 'um_add_profile_fields', 100);
function um_add_profile_fields($args){
global $ultimatemember;
if ( $ultimatemember->fields->editing == true ) {
echo $ultimatemember->fields->display( 'profile', $args );
} else {
$ultimatemember->fields->viewing = true;
echo $ultimatemember->fields->display_view( 'profile', $args );
}
}
/***
*** @form processing
***/
add_action('um_submit_form_profile', 'um_submit_form_profile', 10);
function um_submit_form_profile($args){
global $ultimatemember;
if ( !isset($ultimatemember->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){
global $ultimatemember;
// DO NOT add when reviewing user's details
if ( $ultimatemember->user->preview == true && is_admin() ) return;
// only when editing
if ( $ultimatemember->fields->editing == false ) return;
?>
<div class="um-col-alt">
<?php if ( isset($args['secondary_btn']) && $args['secondary_btn'] != 0 ) { ?>
<div class="um-left um-half"><input type="submit" value="<?php echo $args['primary_btn_word']; ?>" class="um-button" /></div>
<div class="um-right um-half"><a href="<?php echo um_edit_my_profile_cancel_uri(); ?>" class="um-button um-alt"><?php echo $args['secondary_btn_word']; ?></a></div>
<?php } else { ?>
<div class="um-center"><input type="submit" value="<?php echo $args['primary_btn_word']; ?>" class="um-button" /></div>
<?php } ?>
<div class="um-clear"></div>
</div>
<?php
}