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

771 lines
23 KiB
PHP
Raw Normal View History

2014-12-15 22:38:07 +02:00
<?php
2015-01-24 23:39:43 +02:00
/***
2017-10-03 16:29:04 +03:00
*** @um_profile_content_{main_tab}
***/
add_action( 'um_profile_content_main', 'um_profile_content_main' );
2015-01-24 23:39:43 +02:00
function um_profile_content_main( $args ) {
extract( $args );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (!um_get_option( 'profile_tab_main' ) && !isset( $_REQUEST['um_action'] ))
2015-05-02 02:49:05 +03:00
return;
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$can_view = apply_filters( 'um_profile_can_view_main', -1, um_profile_id() );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if ($can_view == -1) {
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
do_action( "um_before_form", $args );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
do_action( "um_before_{$mode}_fields", $args );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
do_action( "um_main_{$mode}_fields", $args );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
do_action( "um_after_form_fields", $args );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
do_action( "um_after_{$mode}_fields", $args );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
do_action( "um_after_form", $args );
2015-12-28 15:00:30 -08:00
2015-04-25 21:41:47 +02:00
} else {
2015-12-28 15:00:30 -08:00
2015-04-25 21:41:47 +02:00
?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-profile-note"><span><i class="um-faicon-lock"></i><?php echo $can_view; ?></span></div>
2015-12-28 15:00:30 -08:00
2015-04-25 21:41:47 +02:00
<?php
2015-12-28 15:00:30 -08:00
2015-04-25 21:41:47 +02:00
}
2015-12-28 15:00:30 -08:00
2015-01-24 23:39:43 +02:00
}
2015-12-28 15:00:30 -08:00
2015-01-11 23:12:05 +02:00
/***
2017-10-03 16:29:04 +03:00
*** @update user's profile
***/
add_action( 'um_user_edit_profile', 'um_user_edit_profile', 10 );
function um_user_edit_profile( $args ) {
2015-12-28 15:00:30 -08:00
2015-01-11 23:12:05 +02:00
$to_update = null;
$files = null;
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (isset( $args['user_id'] )) {
if (UM()->roles()->um_current_user_can( 'edit', $args['user_id'] )) {
UM()->user()->set( $args['user_id'] );
2015-01-11 23:12:05 +02:00
} else {
2017-10-03 16:29:04 +03:00
wp_die( __( 'You are not allowed to edit this user.', 'ultimate-member' ) );
2015-01-11 23:12:05 +02:00
}
2017-10-03 16:29:04 +03:00
} else if (isset( $args['_user_id'] )) {
UM()->user()->set( $args['_user_id'] );
2015-01-11 23:12:05 +02:00
}
2015-12-28 15:00:30 -08:00
$userinfo = UM()->user()->profile;
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
do_action( 'um_user_before_updating_profile', $userinfo );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (!empty( $args['custom_fields'] ))
$fields = unserialize( $args['custom_fields'] );
2015-12-28 15:00:30 -08:00
2015-01-11 23:12:05 +02:00
// loop through fields
2017-10-03 16:29:04 +03:00
if (!empty( $fields )) {
foreach ($fields as $key => $array) {
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (!um_can_edit_field( $fields[$key] ) && isset( $fields[$key]['editable'] ) && !$fields[$key]['editable'])
continue;
2016-01-24 14:46:14 -08:00
2017-10-03 16:29:04 +03:00
if ($fields[$key]['type'] == 'multiselect' || $fields[$key]['type'] == 'checkbox' && !isset( $args['submitted'][$key] )) {
delete_user_meta( um_user( 'ID' ), $key );
2015-11-05 19:51:31 +08:00
}
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (isset( $args['submitted'][$key] )) {
2015-01-22 18:36:29 +02:00
2017-10-03 16:29:04 +03:00
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' )
) {
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$files[$key] = $args['submitted'][$key];
2015-12-28 15:00:30 -08:00
2015-11-05 19:51:31 +08:00
} else {
2015-01-11 23:12:05 +02:00
2017-10-03 16:29:04 +03:00
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];
2015-11-05 19:51:31 +08:00
}
2015-12-28 15:00:30 -08:00
2015-01-22 18:36:29 +02:00
}
2015-12-28 15:00:30 -08:00
2015-01-22 18:36:29 +02:00
}
2015-01-11 23:12:05 +02:00
}
}
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (isset( $args['submitted']['description'] )) {
2015-05-18 14:12:50 +03:00
$to_update['description'] = $args['submitted']['description'];
2015-01-11 23:12:05 +02:00
}
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (!empty( $args['submitted']['role'] )) {
2015-02-13 02:05:04 +02:00
$to_update['role'] = $args['submitted']['role'];
}
2015-12-28 15:00:30 -08:00
do_action( 'um_user_pre_updating_profile', $to_update );
2015-12-28 15:00:30 -08:00
$to_update = apply_filters( 'um_user_pre_updating_profile_array', $to_update );
2015-01-11 23:12:05 +02:00
2017-10-03 16:29:04 +03:00
if (is_array( $to_update )) {
UM()->user()->update_profile( $to_update );
2017-10-03 16:29:04 +03:00
do_action( 'um_after_user_updated', um_user( 'ID' ) );
2015-01-11 23:12:05 +02:00
}
$files = apply_filters( 'um_user_pre_updating_files_array', $files );
2017-10-03 16:29:04 +03:00
if (is_array( $files )) {
do_action( 'um_before_user_upload', um_user( 'ID' ), $files );
UM()->user()->update_files( $files );
2017-10-03 16:29:04 +03:00
do_action( 'um_after_user_upload', um_user( 'ID' ), $files );
2015-01-11 23:12:05 +02:00
}
2015-12-28 15:00:30 -08:00
do_action( 'um_user_after_updating_profile', $to_update );
2015-12-28 15:00:30 -08:00
do_action( 'um_update_profile_full_name', $to_update );
2016-09-29 21:53:50 +08:00
2017-10-03 16:29:04 +03:00
if (!isset( $args['is_signup'] )) {
$url = UM()->user()->get_profile_url( um_user( 'ID' ), true );
2016-04-05 14:09:33 +08:00
exit( wp_redirect( um_edit_my_profile_cancel_uri( $url ) ) );
2015-01-11 23:12:05 +02:00
}
2015-12-28 15:00:30 -08:00
2015-01-11 23:12:05 +02:00
}
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
/***
2017-10-03 16:29:04 +03:00
*** @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) { ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<input type="hidden" name="user_id" id="user_id" value="<?php echo UM()->user()->target_id; ?>"/>
2014-12-15 22:38:07 +02:00
2017-10-03 16:29:04 +03:00
<?php
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
}
}
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
/***
2017-10-03 16:29:04 +03:00
*** @meta description
***/
add_action( 'wp_head', 'um_profile_dynamic_meta_desc', 9999999 );
2014-12-15 22:38:07 +02:00
function um_profile_dynamic_meta_desc() {
2017-10-03 16:29:04 +03:00
if (um_is_core_page( 'user' ) && um_get_requested_user()) {
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
um_fetch_user( um_get_requested_user() );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$content = um_convert_tags( um_get_option( 'profile_desc' ) );
$user_id = um_user( 'ID' );
2015-02-15 20:31:41 +02:00
$url = um_user_profile_url();
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (um_profile( 'profile_photo' )) {
$avatar = um_user_uploads_uri() . um_profile( 'profile_photo' );
2015-02-15 20:31:41 +02:00
} else {
$avatar = um_get_default_avatar_uri();
}
2015-12-28 15:00:30 -08:00
2015-02-15 20:31:41 +02:00
um_reset_user(); ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<meta name="description" content="<?php echo $content; ?>">
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<meta property="og:title" content="<?php echo um_get_display_name( $user_id ); ?>"/>
<meta property="og:type" content="article"/>
<meta property="og:image" content="<?php echo $avatar; ?>"/>
<meta property="og:url" content="<?php echo $url; ?>"/>
<meta property="og:description" content="<?php echo $content; ?>"/>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php
2014-12-15 22:38:07 +02:00
}
}
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
/***
2017-10-03 16:29:04 +03:00
*** @profile header cover
***/
add_action( 'um_profile_header_cover_area', 'um_profile_header_cover_area', 9 );
2014-12-15 22:38:07 +02:00
function um_profile_header_cover_area( $args ) {
2017-10-03 16:29:04 +03:00
if ($args['cover_enabled'] == 1) {
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$default_cover = um_get_option( 'default_cover' );
2015-12-28 15:00:30 -08:00
2014-12-29 15:51:55 +02:00
$overlay = '<span class="um-cover-overlay">
<span class="um-cover-overlay-s">
<ins>
2015-01-15 17:15:12 +02:00
<i class="um-faicon-picture-o"></i>
2017-10-03 16:29:04 +03:00
<span class="um-cover-overlay-t">' . __( 'Change your cover photo', 'ultimate-member' ) . '</span>
2014-12-29 15:51:55 +02:00
</ins>
</span>
</span>';
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
?>
2014-12-29 15:51:55 +02:00
2017-10-03 16:29:04 +03:00
<div class="um-cover <?php if (um_profile( 'cover_photo' ) || ( $default_cover && $default_cover['url'] )) echo 'has-cover'; ?>"
data-user_id="<?php echo um_profile_id(); ?>" data-ratio="<?php echo $args['cover_ratio']; ?>">
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php do_action( 'um_cover_area_content', um_profile_id() ); ?>
2014-12-29 15:51:55 +02:00
<?php
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (UM()->fields()->editing) {
2015-12-28 15:00:30 -08:00
2015-01-06 00:38:33 +02:00
$items = array(
2017-10-03 16:29:04 +03:00
'<a href="#" class="um-manual-trigger" data-parent=".um-cover" data-child=".um-btn-auto-width">' . __( 'Change cover photo', 'ultimate-member' ) . '</a>',
'<a href="#" class="um-reset-cover-photo" data-user_id="' . um_profile_id() . '">' . __( 'Remove', 'ultimate-member' ) . '</a>',
'<a href="#" class="um-dropdown-hide">' . __( 'Cancel', 'ultimate-member' ) . '</a>',
2015-01-06 00:38:33 +02:00
);
2015-12-28 15:00:30 -08:00
echo UM()->menu()->new_ui( 'bc', 'div.um-cover', 'click', $items );
2015-12-28 15:00:30 -08:00
2015-01-03 15:31:15 +02:00
}
2014-12-29 15:51:55 +02:00
?>
2015-12-28 15:00:30 -08:00
<?php UM()->fields()->add_hidden_field( 'cover_photo' ); ?>
2015-12-28 15:00:30 -08:00
2014-12-29 15:51:55 +02:00
<?php echo $overlay; ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-cover-e">
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php if (um_profile( 'cover_photo' )) { ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (UM()->mobile()->isMobile()) {
if (UM()->mobile()->isTablet()) {
echo um_user( 'cover_photo', 1000 );
} else {
echo um_user( 'cover_photo', 300 );
}
2015-01-05 01:33:17 +02:00
} else {
2017-10-03 16:29:04 +03:00
echo um_user( 'cover_photo', 1000 );
2015-01-05 01:33:17 +02:00
}
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php } else if ($default_cover && $default_cover['url']) {
2015-02-01 01:30:04 +02:00
$default_cover = $default_cover['url'];
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
echo '<img src="' . $default_cover . '" alt="" />';
2015-12-28 15:00:30 -08:00
2015-02-01 01:30:04 +02:00
} else {
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (!isset( UM()->user()->cannot_edit )) { ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03: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-plus um-tip-n"
title="<?php _e( 'Upload a cover photo', 'ultimate-member' ); ?>"></i></span></a>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php }
2015-12-28 15:00:30 -08:00
2015-02-01 01:30:04 +02:00
} ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
</div>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
</div>
2015-12-28 15:00:30 -08:00
2014-12-29 15:51:55 +02:00
<?php
2014-12-15 22:38:07 +02:00
}
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
}
2015-12-28 15:00:30 -08:00
2015-03-14 23:39:33 +02:00
/***
2017-10-03 16:29:04 +03:00
*** @Show social links as icons below profile name
***/
add_action( 'um_after_profile_header_name_args', 'um_social_links_icons', 50 );
2015-03-14 23:39:33 +02:00
function um_social_links_icons( $args ) {
2017-10-03 16:29:04 +03:00
if (!empty( $args['show_social_links'] )) {
2015-03-14 23:39:33 +02:00
echo '<div class="um-profile-connect um-member-connect">';
UM()->fields()->show_social_urls();
2015-03-14 23:39:33 +02:00
echo '</div>';
}
}
2014-12-15 22:38:07 +02:00
/***
2017-10-03 16:29:04 +03:00
*** @profile header
***/
add_action( 'um_profile_header', 'um_profile_header', 9 );
2014-12-15 22:38:07 +02:00
function um_profile_header( $args ) {
$classes = null;
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (!$args['cover_enabled']) {
2014-12-15 22:38:07 +02:00
$classes .= ' no-cover';
}
2015-12-28 15:00:30 -08:00
2014-12-29 15:51:55 +02:00
$default_size = str_replace( 'px', '', $args['photosize'] );
2015-12-28 15:00:30 -08:00
2014-12-29 15:51:55 +02:00
$overlay = '<span class="um-profile-photo-overlay">
<span class="um-profile-photo-overlay-s">
<ins>
2015-01-15 17:15:12 +02:00
<i class="um-faicon-camera"></i>
2014-12-29 15:51:55 +02:00
</ins>
</span>
</span>';
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-header<?php echo $classes; ?>">
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php do_action( 'um_pre_header_editprofile', $args ); ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-profile-photo" data-user_id="<?php echo um_profile_id(); ?>">
2014-12-29 15:51:55 +02:00
2017-10-03 16:29:04 +03:00
<a href="<?php echo um_user_profile_url(); ?>" class="um-profile-photo-img"
title="<?php echo um_user( 'display_name' ); ?>"><?php echo $overlay . get_avatar( um_user( 'ID' ), $default_size ); ?></a>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (!isset( UM()->user()->cannot_edit )) {
2015-12-28 15:00:30 -08:00
UM()->fields()->add_hidden_field( 'profile_photo' );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (!um_profile( 'profile_photo' )) { // has profile photo
2015-12-28 15:00:30 -08:00
2015-01-06 00:38:33 +02:00
$items = array(
2017-10-03 16:29:04 +03:00
'<a href="#" class="um-manual-trigger" data-parent=".um-profile-photo" data-child=".um-btn-auto-width">' . __( 'Upload photo', 'ultimate-member' ) . '</a>',
'<a href="#" class="um-dropdown-hide">' . __( 'Cancel', 'ultimate-member' ) . '</a>',
2015-01-06 00:38:33 +02:00
);
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$items = apply_filters( 'um_user_photo_menu_view', $items );
2015-12-28 15:00:30 -08:00
echo UM()->menu()->new_ui( 'bc', 'div.um-profile-photo', 'click', $items );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
} else if (UM()->fields()->editing == true) {
2015-12-28 15:00:30 -08:00
2015-01-06 00:38:33 +02:00
$items = array(
2017-10-03 16:29:04 +03:00
'<a href="#" class="um-manual-trigger" data-parent=".um-profile-photo" data-child=".um-btn-auto-width">' . __( 'Change photo', 'ultimate-member' ) . '</a>',
'<a href="#" class="um-reset-profile-photo" data-user_id="' . um_profile_id() . '" data-default_src="' . um_get_default_avatar_uri() . '">' . __( 'Remove photo', 'ultimate-member' ) . '</a>',
'<a href="#" class="um-dropdown-hide">' . __( 'Cancel', 'ultimate-member' ) . '</a>',
2015-01-06 00:38:33 +02:00
);
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$items = apply_filters( 'um_user_photo_menu_edit', $items );
2015-12-28 15:00:30 -08:00
echo UM()->menu()->new_ui( 'bc', 'div.um-profile-photo', 'click', $items );
2015-12-28 15:00:30 -08:00
2014-12-29 15:51:55 +02:00
}
2015-12-28 15:00:30 -08:00
2014-12-29 15:51:55 +02:00
}
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
</div>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-profile-meta">
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-main-meta">
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php if ($args['show_name']) { ?>
<div class="um-name">
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<a href="<?php echo um_user_profile_url(); ?>"
title="<?php echo um_user( 'display_name' ); ?>"><?php echo um_user( 'display_name', 'html' ); ?></a>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php do_action( 'um_after_profile_name_inline', $args ); ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
</div>
<?php } ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-clear"></div>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php do_action( 'um_after_profile_header_name_args', $args ); ?>
<?php do_action( 'um_after_profile_header_name' ); ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
</div>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php if (isset( $args['metafields'] ) && !empty( $args['metafields'] )) { ?>
<div class="um-meta">
2015-12-28 15:00:30 -08:00
<?php echo UM()->profile()->show_meta( $args['metafields'] ); ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
</div>
<?php } ?>
<?php if (UM()->fields()->viewing == true && um_user( 'description' ) && $args['show_bio']) { ?>
<div class="um-meta-text">
<?php
2014-12-29 15:51:55 +02:00
2017-10-03 16:29:04 +03:00
$description = get_user_meta( um_user( 'ID' ), 'description', true );
if (um_get_option( 'profile_show_html_bio' )) : ?>
<?php echo make_clickable( wpautop( wp_kses_post( $description ) ) ); ?>
<?php else : ?>
<?php echo esc_html( $description ); ?>
<?php endif; ?>
</div>
<?php } else if (UM()->fields()->editing == true && $args['show_bio']) { ?>
<div class="um-meta-text">
<textarea id="um-meta-bio"
data-character-limit="<?php echo um_get_option( 'profile_bio_maxchars' ); ?>"
placeholder="<?php _e( 'Tell us a bit about yourself...', 'ultimate-member' ); ?>"
name="<?php echo 'description-' . $args['form_id']; ?>"
id="<?php echo 'description-' . $args['form_id']; ?>"><?php if (um_user( 'description' )) {
echo um_user( 'description' );
} ?></textarea>
<span class="um-meta-bio-character um-right"><span
class="um-bio-limit"><?php echo um_get_option( 'profile_bio_maxchars' ); ?></span></span>
<?php
if (UM()->fields()->is_error( 'description' )) {
echo UM()->fields()->field_error( UM()->fields()->show_error( 'description' ), true );
2016-07-19 23:16:18 +08:00
}
2015-05-02 02:49:05 +03:00
?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
</div>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php } ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-profile-status <?php echo um_user( 'account_status' ); ?>">
<span><?php printf( __( 'This user account status is %s', 'ultimate-member' ), um_user( 'account_status_name' ) ); ?></span>
</div>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php do_action( 'um_after_header_meta', um_user( 'ID' ), $args ); ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
</div>
<div class="um-clear"></div>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php
if (UM()->fields()->is_error( 'profile_photo' )) {
echo UM()->fields()->field_error( UM()->fields()->show_error( 'profile_photo' ), 'force_show' );
}
?>
<?php do_action( 'um_after_header_info', um_user( 'ID' ), $args ); ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
</div>
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
<?php
}
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
/***
2017-10-03 16:29:04 +03:00
*** @adds profile permissions to view/edit
***/
add_action( 'um_pre_profile_shortcode', 'um_pre_profile_shortcode' );
2017-10-03 16:29:04 +03:00
function um_pre_profile_shortcode( $args ) {
2014-12-15 22:38:07 +02:00
extract( $args );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if ($mode == 'profile' && UM()->fields()->editing == false) {
UM()->fields()->viewing = 1;
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (um_get_requested_user()) {
if (!um_can_view_profile( um_get_requested_user() ) && !um_is_myprofile())
um_redirect_home();
2017-10-03 16:29:04 +03:00
if (!UM()->roles()->um_current_user_can( 'edit', um_get_requested_user() ))
UM()->user()->cannot_edit = 1;
2017-10-03 16:29:04 +03:00
um_fetch_user( um_get_requested_user() );
2014-12-15 22:38:07 +02:00
} else {
2017-10-03 16:29:04 +03:00
if (!is_user_logged_in()) um_redirect_home();
if (!um_user( 'can_edit_profile' )) UM()->user()->cannot_edit = 1;
2014-12-15 22:38:07 +02:00
}
}
2017-10-03 16:29:04 +03:00
if ($mode == 'profile' && UM()->fields()->editing == true) {
UM()->fields()->editing = 1;
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (um_get_requested_user()) {
if (!UM()->roles()->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() );
}
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
}
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
}
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
/***
2017-10-03 16:29:04 +03:00
*** @display the edit profile icon
***/
add_action( 'um_pre_header_editprofile', 'um_add_edit_icon' );
2014-12-15 22:38:07 +02:00
function um_add_edit_icon( $args ) {
$output = '';
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (!is_user_logged_in()) return; // not allowed for guests
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (isset( UM()->user()->cannot_edit ) && UM()->user()->cannot_edit == 1) return; // do not proceed if user cannot edit
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (UM()->fields()->editing == true) {
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-profile-edit um-profile-headericon">
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<a href="#" class="um-profile-edit-a um-profile-save"><i class="um-faicon-check"></i></a>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
</div>
2015-12-28 15:00:30 -08:00
2015-01-05 01:33:17 +02:00
<?php } else { ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-profile-edit um-profile-headericon">
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<a href="#" class="um-profile-edit-a"><i class="um-faicon-cog"></i></a>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$items = array(
'editprofile' => '<a href="' . um_edit_profile_url() . '" class="real_url">' . __( 'Edit Profile', 'ultimate-member' ) . '</a>',
'myaccount' => '<a href="' . um_get_core_page( 'account' ) . '" class="real_url">' . __( 'My Account', 'ultimate-member' ) . '</a>',
'logout' => '<a href="' . um_get_core_page( 'logout' ) . '" class="real_url">' . __( 'Logout', 'ultimate-member' ) . '</a>',
'cancel' => '<a href="#" class="um-dropdown-hide">' . __( 'Cancel', 'ultimate-member' ) . '</a>',
);
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$cancel = $items['cancel'];
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (!um_is_myprofile()) {
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$actions = UM()->user()->get_admin_actions();
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
unset( $items['myaccount'] );
unset( $items['logout'] );
unset( $items['cancel'] );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (is_array( $actions )) {
$items = array_merge( $items, $actions );
}
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$items = apply_filters( 'um_profile_edit_menu_items', $items, um_profile_id() );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$items['cancel'] = $cancel;
2015-04-07 20:10:23 +02:00
2017-10-03 16:29:04 +03:00
} else {
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$items = apply_filters( 'um_myprofile_edit_menu_items', $items );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
}
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
UM()->menu()->new_ui( $args['header_menu'], 'div.um-profile-edit', 'click', $items );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
</div>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php
2014-12-15 22:38:07 +02:00
}
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
}
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
/***
2017-10-03 16:29:04 +03:00
*** @Show Fields
***/
add_action( 'um_main_profile_fields', 'um_add_profile_fields', 100 );
function um_add_profile_fields( $args ) {
if (UM()->fields()->editing == true) {
2015-12-28 15:00:30 -08:00
echo UM()->fields()->display( 'profile', $args );
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
} else {
2015-12-28 15:00:30 -08:00
UM()->fields()->viewing = true;
2015-12-28 15:00:30 -08:00
echo UM()->fields()->display_view( 'profile', $args );
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
}
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
}
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
/***
2017-10-03 16:29:04 +03:00
*** @form processing
***/
add_action( 'um_submit_form_profile', 'um_submit_form_profile', 10 );
function um_submit_form_profile( $args ) {
2017-10-03 16:29:04 +03:00
if (isset( UM()->form()->errors ))
return false;
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
do_action( 'um_user_edit_profile', $args );
2014-12-15 22:38:07 +02:00
}
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
/***
2017-10-03 16:29:04 +03:00
*** @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 ) {
2014-12-15 22:38:07 +02:00
// DO NOT add when reviewing user's details
2017-10-03 16:29:04 +03:00
if (UM()->user()->preview == true && is_admin()) return;
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
// only when editing
2017-10-03 16:29:04 +03:00
if (UM()->fields()->editing == false) return;
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-col-alt">
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php if (isset( $args['secondary_btn'] ) && $args['secondary_btn'] != 0) { ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<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>
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
<?php } else { ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-center"><input type="submit" value="<?php echo $args['primary_btn_word']; ?>"
class="um-button"/></div>
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
<?php } ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-clear"></div>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
</div>
2015-12-28 15:00:30 -08:00
2014-12-15 22:38:07 +02:00
<?php
2015-01-24 23:39:43 +02:00
}
2015-12-28 15:00:30 -08:00
2015-01-24 23:39:43 +02:00
/***
2017-10-03 16:29:04 +03:00
*** @display the available profile tabs
***/
add_action( 'um_profile_menu', 'um_profile_menu', 9 );
function um_profile_menu( $args ) {
2017-10-03 16:29:04 +03:00
if (!um_get_option( 'profile_menu' ))
2015-02-21 01:39:02 +02:00
return;
2015-12-28 15:00:30 -08:00
2015-02-21 01:39:02 +02:00
// get active tabs
$tabs = UM()->profile()->tabs_active();
2015-01-24 23:39:43 +02:00
2017-10-03 16:29:04 +03:00
$tabs = apply_filters( 'um_user_profile_tabs', $tabs );
2015-05-02 02:49:05 +03:00
UM()->user()->tabs = $tabs;
2015-12-28 15:00:30 -08:00
2015-02-21 01:39:02 +02:00
// need enough tabs to continue
2017-10-03 16:29:04 +03:00
if (count( $tabs ) <= 1) return;
2015-12-28 15:00:30 -08:00
$active_tab = UM()->profile()->active_tab();
2015-02-01 01:30:04 +02:00
2017-10-03 16:29:04 +03:00
if (!isset( $tabs[$active_tab] )) {
2015-02-01 01:30:04 +02:00
$active_tab = 'main';
UM()->profile()->active_tab = $active_tab;
UM()->profile()->active_subnav = null;
2015-04-25 21:41:47 +02:00
}
2015-12-28 15:00:30 -08:00
2015-11-05 19:51:31 +08:00
// Move default tab priority
2017-10-03 16:29:04 +03:00
$default_tab = um_get_option( 'profile_menu_default_tab' );
$dtab = ( isset( $tabs[$default_tab] ) ) ? $tabs[$default_tab] : 'main';
if (isset( $tabs[$default_tab] )) {
2015-11-05 19:51:31 +08:00
unset( $tabs[$default_tab] );
$dtabs[$default_tab] = $dtab;
$tabs = $dtabs + $tabs;
}
2015-12-28 15:00:30 -08:00
2015-01-24 23:39:43 +02:00
?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-profile-nav">
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php foreach ($tabs as $id => $tab) {
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (isset( $tab['hidden'] )) continue;
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$nav_link = UM()->permalinks()->get_current_url( get_option( 'permalink_structure' ) );
2015-01-28 17:16:04 +02:00
$nav_link = remove_query_arg( 'um_action', $nav_link );
$nav_link = remove_query_arg( 'subnav', $nav_link );
2017-10-03 16:29:04 +03:00
$nav_link = add_query_arg( 'profiletab', $id, $nav_link );
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$nav_link = apply_filters( "um_profile_menu_link_{$id}", $nav_link );
2015-12-28 15:00:30 -08:00
2015-01-24 23:39:43 +02:00
?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-profile-nav-item um-profile-nav-<?php echo $id; ?> <?php if (!um_get_option( 'profile_menu_icons' )) {
echo 'without-icon';
} ?> <?php if ($id == $active_tab) {
echo 'active';
} ?>">
<?php if (um_get_option( 'profile_menu_icons' )) { ?>
<a href="<?php echo $nav_link; ?>" class="um-tip-n uimob500-show uimob340-show uimob800-show"
title="<?php echo $tab['name']; ?>" original-title="<?php echo $tab['name']; ?>">
2015-02-01 01:30:04 +02:00
2017-10-03 16:29:04 +03:00
<i class="<?php echo $tab['icon']; ?>"></i>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php if (isset( $tab['notifier'] ) && $tab['notifier'] > 0) { ?>
<span class="um-tab-notifier uimob500-show uimob340-show uimob800-show"><?php echo $tab['notifier']; ?></span>
<?php } ?>
2017-09-18 14:44:40 +03:00
2017-10-03 16:29:04 +03:00
<span class="uimob500-hide uimob340-hide uimob800-hide title"><?php echo $tab['name']; ?></span>
2017-09-18 14:44:40 +03:00
2017-10-03 16:29:04 +03:00
</a>
<a href="<?php echo $nav_link; ?>" class="uimob500-hide uimob340-hide uimob800-hide"
title="<?php echo $tab['name']; ?>" original-title="<?php echo $tab['name']; ?>">
2017-09-18 14:44:40 +03:00
2017-10-03 16:29:04 +03:00
<i class="<?php echo $tab['icon']; ?>"></i>
2017-09-18 14:44:40 +03:00
2017-10-03 16:29:04 +03:00
<?php if (isset( $tab['notifier'] ) && $tab['notifier'] > 0) { ?>
<span class="um-tab-notifier uimob500-show uimob340-show uimob800-show"><?php echo $tab['notifier']; ?></span>
<?php } ?>
2017-09-18 14:44:40 +03:00
2017-10-03 16:29:04 +03:00
<span class="uimob500-hide uimob340-hide uimob800-hide title"><?php echo $tab['name']; ?></span>
2017-09-18 14:44:40 +03:00
2017-10-03 16:29:04 +03:00
</a>
<?php } else { ?>
<a href="<?php echo $nav_link; ?>" title="<?php echo $tab['name']; ?>"
original-title="<?php echo $tab['name']; ?>">
2017-09-18 14:44:40 +03:00
2017-10-03 16:29:04 +03:00
<?php if (isset( $tab['notifier'] ) && $tab['notifier'] > 0) { ?>
<span class="um-tab-notifier uimob500-show uimob340-show uimob800-show"><?php echo $tab['notifier']; ?></span>
<?php } ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<span class="uimob500-hide uimob340-hide uimob800-hide title"><?php echo $tab['name']; ?></span>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
</a>
<?php } ?>
</div>
2015-12-28 15:00:30 -08:00
2015-01-24 23:39:43 +02:00
<?php } ?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<div class="um-clear"></div>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
</div>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php foreach ($tabs as $id => $tab) {
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
if (isset( $tab['subnav'] ) && $active_tab == $id) {
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
$active_subnav = ( UM()->profile()->active_subnav() ) ? UM()->profile()->active_subnav() : $tab['subnav_default'];
2015-01-24 23:39:43 +02:00
2017-10-03 16:29:04 +03:00
echo '<div class="um-profile-subnav">';
foreach ($tab['subnav'] as $id => $subtab) {
2015-12-28 15:00:30 -08:00
2016-07-19 23:16:18 +08:00
?>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<a href="<?php echo add_query_arg( 'subnav', $id ); ?>"
class="<?php if ($active_subnav == $id) echo 'active'; ?>"><?php echo $subtab; ?></a>
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
<?php
2015-12-28 15:00:30 -08:00
2015-01-24 23:39:43 +02:00
}
2017-10-03 16:29:04 +03:00
echo '</div>';
2016-07-19 23:16:18 +08:00
}
2015-12-28 15:00:30 -08:00
2017-10-03 16:29:04 +03:00
}
2015-12-28 15:00:30 -08:00
}
/**
* Clean up file for new uploaded files
2017-10-03 16:29:04 +03:00
*
* @param integer $user_id
2017-10-03 16:29:04 +03:00
* @param array $arr_files
*/
2017-10-03 16:29:04 +03:00
function um_before_user_upload( $user_id, $arr_files ) {
um_fetch_user( $user_id );
2017-10-31 15:49:48 +02:00
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 );
2017-10-03 16:29:04 +03:00
if (file_exists( $path . $user_id . '/' . $old_filename )) {
unlink( $path . $user_id . '/' . $old_filename );
}
}
}
}
}
2017-10-31 15:49:48 +02:00
add_action( "um_before_user_upload", "um_before_user_upload", 10, 2 );