2014-12-15 22:38:07 +02:00
< ? php
class UM_User {
function __construct () {
$this -> id = 0 ;
$this -> usermeta = null ;
$this -> data = null ;
$this -> banned_keys = array (
'metabox' , 'postbox' , 'meta-box' ,
'dismissed_wp_pointers' , 'session_tokens' ,
'screen_layout' , 'wp_user-' , 'dismissed' ,
'cap_key' , 'wp_capabilities' ,
'managenav' , 'nav_menu' , 'user_activation_key' ,
'level_' , 'wp_user_level'
);
add_action ( 'init' , array ( & $this , 'set' ), 1 );
$this -> preview = false ;
2015-02-07 01:39:29 +02:00
// a list of keys that should never be in wp_usermeta
2014-12-15 22:38:07 +02:00
$this -> update_user_keys = array (
'user_email' ,
'user_pass' ,
2015-02-07 01:39:29 +02:00
'user_password' ,
2015-02-08 01:49:10 +02:00
'display_name' ,
2014-12-15 22:38:07 +02:00
);
$this -> target_id = null ;
2015-05-02 02:49:05 +03:00
// When the cache should be cleared
add_action ( 'um_delete_user_hook' , array ( & $this , 'remove_cached_queue' ) );
add_action ( 'um_new_user_registration_plain' , array ( & $this , 'remove_cached_queue' ) );
add_action ( 'um_after_user_status_is_changed_hook' , array ( & $this , 'remove_cached_queue' ) );
2015-05-05 18:06:39 +03:00
// When user cache should be cleared
add_action ( 'um_after_user_updated' , array ( & $this , 'remove_cache' ) );
add_action ( 'um_after_user_account_updated' , array ( & $this , 'remove_cache' ) );
add_action ( 'personal_options_update' , array ( & $this , 'remove_cache' ) );
add_action ( 'edit_user_profile_update' , array ( & $this , 'remove_cache' ) );
2015-05-18 14:12:50 +03:00
add_action ( 'um_when_role_is_set' , array ( & $this , 'remove_cache' ) );
add_action ( 'um_when_status_is_set' , array ( & $this , 'remove_cache' ) );
2015-05-05 18:06:39 +03:00
2014-12-15 22:38:07 +02:00
}
2015-05-02 02:49:05 +03:00
/***
*** @Remove cached queue from Users backend
***/
function remove_cached_queue () {
delete_option ( 'um_cached_users_queue' );
}
2014-12-15 22:38:07 +02:00
/***
*** @Converts object to array
***/
function toArray ( $obj )
{
if ( is_object ( $obj )) $obj = ( array ) $obj ;
if ( is_array ( $obj )) {
$new = array ();
foreach ( $obj as $key => $val ) {
$new [ $key ] = $this -> toArray ( $val );
}
} else {
$new = $obj ;
}
return $new ;
}
2015-05-05 18:06:39 +03:00
function get_cached_data ( $user_id ) {
2015-11-05 19:51:31 +08:00
if ( is_numeric ( $user_id ) && $user_id > 0 ) {
$find_user = get_option ( " um_cache_userdata_ { $user_id } " );
if ( $find_user ) {
$find_user = apply_filters ( 'um_user_permissions_filter' , $find_user , $user_id );
return $find_user ;
}
2015-05-18 14:12:50 +03:00
}
2015-11-05 19:51:31 +08:00
return '' ;
2015-05-05 18:06:39 +03:00
}
function setup_cache ( $user_id , $profile ) {
update_option ( " um_cache_userdata_ { $user_id } " , $profile );
}
function remove_cache ( $user_id ) {
delete_option ( " um_cache_userdata_ { $user_id } " );
}
2015-03-10 14:27:56 +02:00
/**
* @function set()
*
* @description This method lets you set a user. For example, to retrieve a profile or anything related to that user.
*
* @usage <?php $ultimatemember->user->set( $user_id, $clean = false ); ?>
*
* @param $user_id (numeric) (optional) Which user to retrieve. A numeric user ID
* @param $clean (boolean) (optional) Should be true or false. Basically, if you did not provide a user ID It will set the current logged in user as a profile
*
* @returns This API method does not return anything. It sets user profile and permissions and allow you to retrieve any details for that user.
*
* @example The following example makes you set a user and retrieve their display name after that using the user API.
<?php
$ultimatemember->user->set( 12 );
$display_name = $ultimatemember->user->profile['display_name']; // Should print user display name
?>
*
*
*/
function set ( $user_id = null , $clean = false ) {
2014-12-15 22:38:07 +02:00
global $ultimatemember ;
if ( isset ( $this -> profile ) ) {
unset ( $this -> profile );
}
2015-05-05 18:06:39 +03:00
if ( $user_id ) {
$this -> id = $user_id ;
} elseif ( is_user_logged_in () && $clean == false ){
$this -> id = get_current_user_id ();
} else {
$this -> id = 0 ;
}
if ( $this -> get_cached_data ( $this -> id ) ) {
$this -> profile = $this -> get_cached_data ( $this -> id );
} else {
2014-12-15 22:38:07 +02:00
if ( $user_id ) {
$this -> id = $user_id ;
$this -> usermeta = get_user_meta ( $user_id );
$this -> data = get_userdata ( $this -> id );
} elseif ( is_user_logged_in () && $clean == false ){
$this -> id = get_current_user_id ();
$this -> usermeta = get_user_meta ( $this -> id );
$this -> data = get_userdata ( $this -> id );
} else {
$this -> id = 0 ;
$this -> usermeta = null ;
$this -> data = null ;
}
// we have a user, populate a profile
if ( $this -> id && $this -> toArray ( $this -> data ) ) {
// add user data
$this -> data = $this -> toArray ( $this -> data );
foreach ( $this -> data as $k => $v ) {
if ( $k == 'roles' ) {
$this -> profile [ 'wp_roles' ] = implode ( ',' , $v );
} else if ( is_array ( $v )){
foreach ( $v as $k2 => $v2 ){
$this -> profile [ $k2 ] = $v2 ;
}
} else {
$this -> profile [ $k ] = $v ;
}
}
// add account status
if ( ! isset ( $this -> usermeta [ 'account_status' ][ 0 ] ) ) {
$this -> usermeta [ 'account_status' ][ 0 ] = 'approved' ;
}
if ( $this -> usermeta [ 'account_status' ][ 0 ] == 'approved' ) {
2015-11-05 19:51:31 +08:00
$this -> usermeta [ 'account_status_name' ][ 0 ] = __ ( 'Approved' , 'ultimatemember' );
2014-12-15 22:38:07 +02:00
}
if ( $this -> usermeta [ 'account_status' ][ 0 ] == 'awaiting_email_confirmation' ) {
2015-11-05 19:51:31 +08:00
$this -> usermeta [ 'account_status_name' ][ 0 ] = __ ( 'Awaiting E-mail Confirmation' , 'ultimatemember' );
2014-12-15 22:38:07 +02:00
}
if ( $this -> usermeta [ 'account_status' ][ 0 ] == 'awaiting_admin_review' ) {
2015-11-05 19:51:31 +08:00
$this -> usermeta [ 'account_status_name' ][ 0 ] = __ ( 'Pending Review' , 'ultimatemember' );
2014-12-15 22:38:07 +02:00
}
if ( $this -> usermeta [ 'account_status' ][ 0 ] == 'rejected' ) {
2015-11-05 19:51:31 +08:00
$this -> usermeta [ 'account_status_name' ][ 0 ] = __ ( 'Membership Rejected' , 'ultimatemember' );
2014-12-15 22:38:07 +02:00
}
if ( $this -> usermeta [ 'account_status' ][ 0 ] == 'inactive' ) {
2015-11-05 19:51:31 +08:00
$this -> usermeta [ 'account_status_name' ][ 0 ] = __ ( 'Membership Inactive' , 'ultimatemember' );
2014-12-15 22:38:07 +02:00
}
// add user meta
foreach ( $this -> usermeta as $k => $v ){
2015-12-24 18:11:07 +02:00
if ( $k == 'display_name' ) continue ;
2014-12-15 22:38:07 +02:00
$this -> profile [ $k ] = $v [ 0 ];
}
2015-02-08 01:49:10 +02:00
2014-12-15 22:38:07 +02:00
// add permissions
$user_role = $this -> get_role ();
$this -> role_meta = $ultimatemember -> query -> role_data ( $user_role );
2015-01-26 16:58:31 +02:00
$this -> role_meta = apply_filters ( 'um_user_permissions_filter' , $this -> role_meta , $this -> id );
2015-01-28 17:16:04 +02:00
2014-12-15 22:38:07 +02:00
$this -> profile = array_merge ( $this -> profile , ( array ) $this -> role_meta );
$this -> profile [ 'super_admin' ] = ( is_super_admin ( $this -> id ) ) ? 1 : 0 ;
// clean profile
$this -> clean ();
2015-05-05 18:06:39 +03:00
// Setup cache
$this -> setup_cache ( $this -> id , $this -> profile );
2014-12-15 22:38:07 +02:00
}
2015-05-05 18:06:39 +03:00
}
2014-12-15 22:38:07 +02:00
}
/***
*** @reset user data
***/
function reset ( $clean = false ){
$this -> set ( 0 , $clean );
}
2015-04-07 20:10:23 +02:00
/***
*** @Security check for roles
***/
function is_secure_role ( $user_id , $role ) {
if ( is_admin () ) return ;
if ( $role == 'admin' ) {
$this -> delete ( false );
wp_die ( __ ( 'This is not allowed for security reasons.' , 'ultimatemember' ) );
}
if ( um_get_option ( 'advanced_denied_roles' ) && strstr ( um_get_option ( 'advanced_denied_roles' ), $role ) ) {
$this -> delete ( false );
wp_die ( __ ( 'This is not allowed for security reasons.' , 'ultimatemember' ) );
}
}
2014-12-15 22:38:07 +02:00
/***
*** @Clean user profile
***/
function clean (){
foreach ( $this -> profile as $key => $value ){
foreach ( $this -> banned_keys as $ban ){
if ( strstr ( $key , $ban ) || is_numeric ( $key ) )
unset ( $this -> profile [ $key ]);
}
}
}
2015-03-10 14:27:56 +02:00
/**
* @function auto_login()
*
* @description This method lets you auto sign-in a user to your site.
*
* @usage <?php $ultimatemember->user->auto_login( $user_id, $rememberme = false ); ?>
*
* @param $user_id (numeric) (required) Which user ID to sign in automatically
* @param $rememberme (boolean) (optional) Should be true or false. If you want the user sign in session to use cookies, use true
*
* @returns Sign in the specified user automatically.
*
* @example The following example lets you sign in a user automatically by their ID.
<?php $ultimatemember->user->auto_login( 2 ); ?>
*
*
* @example The following example lets you sign in a user automatically by their ID and makes the plugin remember their session.
<?php $ultimatemember->user->auto_login( 10, true ); ?>
*
*
*/
2015-02-15 20:31:41 +02:00
function auto_login ( $user_id , $rememberme = 0 ) {
2014-12-15 22:38:07 +02:00
wp_set_current_user ( $user_id );
2015-02-15 20:31:41 +02:00
wp_set_auth_cookie ( $user_id , $rememberme );
2014-12-15 22:38:07 +02:00
}
/***
*** @Set user's registration details
***/
function set_registration_details ( $submitted ) {
2015-04-07 20:10:23 +02:00
if ( isset ( $submitted [ 'user_pass' ] ) ) {
unset ( $submitted [ 'user_pass' ] );
}
if ( isset ( $submitted [ 'user_password' ] ) ) {
unset ( $submitted [ 'user_password' ] );
}
2015-11-05 19:51:31 +08:00
if ( isset ( $submitted [ 'confirm_user_password' ] ) ) {
unset ( $submitted [ 'confirm_user_password' ] );
}
do_action ( 'um_before_save_registration_details' , $this -> id , $submitted );
2014-12-15 22:38:07 +02:00
update_user_meta ( $this -> id , 'submitted' , $submitted );
2015-11-05 19:51:31 +08:00
do_action ( 'um_after_save_registration_details' , $this -> id , $submitted );
2014-12-15 22:38:07 +02:00
}
2015-01-22 02:10:26 +02:00
/***
*** @A plain version of password
***/
function set_plain_password ( $plain ) {
update_user_meta ( $this -> id , '_um_cool_but_hard_to_guess_plain_pw' , $plain );
}
2014-12-15 22:38:07 +02:00
function set_role ( $role ){
2015-05-18 14:12:50 +03:00
do_action ( 'um_when_role_is_set' , um_user ( 'ID' ) );
2014-12-15 22:38:07 +02:00
do_action ( 'um_before_user_role_is_changed' );
2015-04-07 20:10:23 +02:00
do_action ( 'um_member_role_upgrade' , $role , $this -> profile [ 'role' ] );
2014-12-15 22:38:07 +02:00
$this -> profile [ 'role' ] = $role ;
$this -> update_usermeta_info ( 'role' );
do_action ( 'um_after_user_role_is_changed' );
2015-11-05 19:51:31 +08:00
do_action ( 'um_after_user_role_is_updated' , um_user ( 'ID' ), $role );
2014-12-15 22:38:07 +02:00
}
/***
*** @Set user's account status
***/
2015-01-03 15:31:15 +02:00
function set_status ( $status ){
2014-12-15 22:38:07 +02:00
2015-05-18 14:12:50 +03:00
do_action ( 'um_when_status_is_set' , um_user ( 'ID' ) );
2014-12-15 22:38:07 +02:00
$this -> profile [ 'account_status' ] = $status ;
2015-01-03 15:31:15 +02:00
2014-12-15 22:38:07 +02:00
$this -> update_usermeta_info ( 'account_status' );
2015-05-02 02:49:05 +03:00
do_action ( 'um_after_user_status_is_changed_hook' );
do_action ( 'um_after_user_status_is_changed' , $status );
2014-12-15 22:38:07 +02:00
}
2014-12-22 01:45:24 +02:00
/***
*** @Set user's hash for password reset
***/
function password_reset_hash (){
global $ultimatemember ;
2015-03-02 16:46:00 +02:00
$this -> profile [ 'reset_pass_hash' ] = $ultimatemember -> validation -> generate ();
2014-12-22 01:45:24 +02:00
$this -> update_usermeta_info ( 'reset_pass_hash' );
}
2014-12-15 22:38:07 +02:00
/***
*** @Set user's hash
***/
function assign_secretkey (){
global $ultimatemember ;
do_action ( 'um_before_user_hash_is_changed' );
2015-03-02 16:46:00 +02:00
$this -> profile [ 'account_secret_hash' ] = $ultimatemember -> validation -> generate ();
2014-12-15 22:38:07 +02:00
$this -> update_usermeta_info ( 'account_secret_hash' );
do_action ( 'um_after_user_hash_is_changed' );
}
2014-12-22 01:45:24 +02:00
/***
*** @password reset email
***/
function password_reset (){
global $ultimatemember ;
$this -> password_reset_hash ();
$ultimatemember -> mail -> send ( um_user ( 'user_email' ), 'resetpw_email' );
}
2015-03-10 14:27:56 +02:00
/**
* @function approve()
*
* @description This method approves a user membership and sends them an optional welcome/approval e-mail.
*
* @usage <?php $ultimatemember->user->approve(); ?>
*
* @returns Approves a user membership.
*
* @example Approve a pending user and allow him to sign-in to your site.
<?php
um_fetch_user( 352 );
$ultimatemember->user->approve();
?>
*
*
*/
2014-12-15 22:38:07 +02:00
function approve (){
global $ultimatemember ;
2015-01-09 03:08:31 +02:00
2015-05-18 14:12:50 +03:00
$user_id = um_user ( 'ID' );
delete_option ( " um_cache_userdata_ { $user_id } " );
2015-01-09 03:08:31 +02:00
if ( um_user ( 'account_status' ) == 'awaiting_admin_review' ) {
$email_tpl = 'approved_email' ;
} else {
$email_tpl = 'welcome_email' ;
}
2014-12-15 22:38:07 +02:00
$this -> set_status ( 'approved' );
2015-01-09 03:08:31 +02:00
$ultimatemember -> mail -> send ( um_user ( 'user_email' ), $email_tpl );
2015-02-21 01:39:02 +02:00
$this -> delete_meta ( 'account_secret_hash' );
$this -> delete_meta ( '_um_cool_but_hard_to_guess_plain_pw' );
2015-03-01 00:44:04 +02:00
do_action ( 'um_after_user_is_approved' , um_user ( 'ID' ) );
2014-12-15 22:38:07 +02:00
}
/***
*** @pending email
***/
function email_pending (){
global $ultimatemember ;
$this -> assign_secretkey ();
$this -> set_status ( 'awaiting_email_confirmation' );
$ultimatemember -> mail -> send ( um_user ( 'user_email' ), 'checkmail_email' );
}
2015-03-10 14:27:56 +02:00
/**
* @function pending()
*
* @description This method puts a user under manual review by administrator and sends them an optional e-mail.
*
* @usage <?php $ultimatemember->user->pending(); ?>
*
* @returns Puts a user under review and sends them an email optionally.
*
* @example An example of putting a user pending manual review
<?php
um_fetch_user( 54 );
$ultimatemember->user->pending();
?>
*
*
*/
2014-12-15 22:38:07 +02:00
function pending (){
global $ultimatemember ;
$this -> set_status ( 'awaiting_admin_review' );
$ultimatemember -> mail -> send ( um_user ( 'user_email' ), 'pending_email' );
}
2015-03-10 14:27:56 +02:00
/**
* @function reject()
*
* @description This method rejects a user membership and sends them an optional e-mail.
*
* @usage <?php $ultimatemember->user->reject(); ?>
*
* @returns Rejects a user membership.
*
* @example Reject a user membership example
<?php
um_fetch_user( 114 );
$ultimatemember->user->reject();
?>
*
*
*/
2014-12-15 22:38:07 +02:00
function reject (){
global $ultimatemember ;
$this -> set_status ( 'rejected' );
$ultimatemember -> mail -> send ( um_user ( 'user_email' ), 'rejected_email' );
}
2015-03-10 14:27:56 +02:00
/**
* @function deactivate()
*
* @description This method deactivates a user membership and sends them an optional e-mail.
*
* @usage <?php $ultimatemember->user->deactivate(); ?>
*
* @returns Deactivates a user membership.
*
* @example Deactivate a user membership with the following example
<?php
um_fetch_user( 32 );
$ultimatemember->user->deactivate();
?>
*
*
*/
2014-12-15 22:38:07 +02:00
function deactivate (){
global $ultimatemember ;
$this -> set_status ( 'inactive' );
2015-11-05 19:51:31 +08:00
do_action ( 'um_after_user_is_inactive' , um_user ( 'ID' ) );
2014-12-15 22:38:07 +02:00
$ultimatemember -> mail -> send ( um_user ( 'user_email' ), 'inactive_email' );
}
/***
*** @delete user
***/
2015-01-09 03:08:31 +02:00
function delete ( $send_mail = true ) {
2014-12-15 22:38:07 +02:00
global $ultimatemember ;
2015-05-02 02:49:05 +03:00
do_action ( 'um_delete_user_hook' );
2015-04-25 21:41:47 +02:00
do_action ( 'um_delete_user' , um_user ( 'ID' ) );
2015-05-02 02:49:05 +03:00
// send email notifications
2015-01-09 03:08:31 +02:00
if ( $send_mail ) {
$ultimatemember -> mail -> send ( um_user ( 'user_email' ), 'deletion_email' );
2015-04-07 20:10:23 +02:00
$ultimatemember -> mail -> send ( um_admin_email (), 'notification_deletion' , array ( 'admin' => true ) );
2015-01-09 03:08:31 +02:00
}
2014-12-15 22:38:07 +02:00
2015-05-02 02:49:05 +03:00
// remove uploads
2015-01-22 18:36:29 +02:00
$ultimatemember -> files -> remove_dir ( um_user_uploads_dir () );
2015-05-02 02:49:05 +03:00
// remove user
2014-12-15 22:38:07 +02:00
if ( is_multisite () ) {
2015-02-08 13:38:41 +02:00
if ( ! function_exists ( 'wpmu_delete_user' ) ) {
require_once ( ABSPATH . 'wp-admin/includes/ms.php' );
}
2014-12-15 22:38:07 +02:00
wpmu_delete_user ( $this -> id );
2015-02-08 13:38:41 +02:00
2014-12-15 22:38:07 +02:00
} else {
2015-02-08 13:38:41 +02:00
if ( ! function_exists ( 'wp_delete_user' ) ) {
require_once ( ABSPATH . 'wp-admin/includes/user.php' );
}
2015-11-05 19:51:31 +08:00
wp_delete_user ( $this -> id );
2015-02-08 13:38:41 +02:00
2014-12-15 22:38:07 +02:00
}
2015-01-22 18:36:29 +02:00
2014-12-15 22:38:07 +02:00
}
2015-03-10 14:27:56 +02:00
/**
* @function get_role()
*
* @description This method gets a user role in slug format. e.g. member
*
* @usage <?php $ultimatemember->user->get_role(); ?>
*
* @returns The user role's slug.
*
* @example Do something if the user's role is paid-member
<?php
um_fetch_user( 12 );
if ( $ultimatemember->user->get_role() == 'paid-member' ) {
// Show this to paid customers
} else {
// You are a free member
}
?>
*
*
*/
2014-12-15 22:38:07 +02:00
function get_role () {
if ( isset ( $this -> profile [ 'role' ]) && ! empty ( $this -> profile [ 'role' ] ) ) {
return $this -> profile [ 'role' ];
} else {
if ( $this -> profile [ 'wp_roles' ] == 'administrator' ) {
return 'admin' ;
} else {
return 'member' ;
}
}
}
2015-11-05 19:51:31 +08:00
function get_role_name ( $slug ) {
global $wpdb ;
$post_id = $wpdb -> get_var ( " SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'um_role' AND post_name = ' $slug ' " );
return get_the_title ( $post_id );
2014-12-15 22:38:07 +02:00
}
/***
*** @Update one key in user meta
***/
2015-11-05 19:51:31 +08:00
function update_usermeta_info ( $key ) {
// delete the key first just in case
delete_user_meta ( $this -> id , $key );
2014-12-15 22:38:07 +02:00
update_user_meta ( $this -> id , $key , $this -> profile [ $key ] );
}
2015-03-10 14:27:56 +02:00
/**
* @function delete_meta()
*
* @description This method can be used to delete user's meta key.
*
* @usage <?php $ultimatemember->user->delete_meta( $key ); ?>
*
* @param $key (string) (required) The meta field key to remove from user
*
* @returns This method will not return anything. The specified meta key will be deleted from database for the specified user.
*
* @example Delete user's age field
<?php
um_fetch_user( 15 );
$ultimatemember->user->delete_meta( 'age' );
?>
*
*
*/
2014-12-15 22:38:07 +02:00
function delete_meta ( $key ){
delete_user_meta ( $this -> id , $key );
}
/***
*** @Get all bulk actions
***/
function get_bulk_admin_actions () {
$output = '' ;
$actions = array ();
$actions = apply_filters ( 'um_admin_bulk_user_actions_hook' , $actions );
foreach ( $actions as $id => $arr ) {
if ( isset ( $arr [ 'disabled' ])){
$arr [ 'disabled' ] = 'disabled' ;
} else {
$arr [ 'disabled' ] = '' ;
}
2015-01-05 01:33:17 +02:00
2014-12-15 22:38:07 +02:00
$output .= '<option value="' . $id . '" ' . $arr [ 'disabled' ] . '>' . $arr [ 'label' ] . '</option>' ;
}
return $output ;
}
/***
2015-01-05 01:33:17 +02:00
*** @Get admin actions for individual user
2014-12-15 22:38:07 +02:00
***/
function get_admin_actions () {
2015-01-05 01:33:17 +02:00
$items = '' ;
2014-12-15 22:38:07 +02:00
$actions = array ();
$actions = apply_filters ( 'um_admin_user_actions_hook' , $actions );
if ( ! isset ( $actions ) || empty ( $actions ) ) return false ;
foreach ( $actions as $id => $arr ) {
2015-01-05 01:33:17 +02:00
$url = add_query_arg ( 'um_action' , $id );
$url = add_query_arg ( 'uid' , um_profile_id (), $url );
$items [] = '<a href="' . $url . '" class="real_url">' . $arr [ 'label' ] . '</a>' ;
2014-12-15 22:38:07 +02:00
}
2015-01-05 01:33:17 +02:00
return $items ;
2014-12-15 22:38:07 +02:00
}
2015-03-10 14:27:56 +02:00
/**
* @function is_private_profile()
*
* @description This method checks if give user profile is private.
*
* @usage <?php $ultimatemember->user->is_private_profile( $user_id ); ?>
*
* @param $user_id (numeric) (required) A user ID must be passed to check if the user profile is private
*
* @returns Returns true if user profile is private and false if user profile is public.
*
* @example This example display a specific user's name If his profile is public
<?php
um_fetch_user( 60 );
$is_private = $ultimatemember->user->is_private_profile( 60 );
if ( !$is_private ) {
echo 'User is public and his name is ' . um_user('display_name');
}
?>
*
*
*/
2014-12-15 22:38:07 +02:00
function is_private_profile ( $user_id ) {
$privacy = get_user_meta ( $user_id , 'profile_privacy' , true );
2015-03-01 00:44:04 +02:00
if ( $privacy == __ ( 'Only me' , 'ultimatemember' ) ) {
2014-12-15 22:38:07 +02:00
return true ;
}
return false ;
}
2015-03-10 14:27:56 +02:00
/**
* @function is_approved()
*
* @description This method can be used to determine If a certain user is approved or not.
*
* @usage <?php $ultimatemember->user->is_approved( $user_id ); ?>
*
* @param $user_id (numeric) (required) The user ID to check approval status for
*
* @returns True if user is approved and false if user is not approved.
*
* @example Do something If a user's membership is approved
<?php
if ( $ultimatemember->user->is_approved( 55 ) {
// User account is approved
} else {
// User account is not approved
}
?>
*
*
*/
2015-01-05 01:33:17 +02:00
function is_approved ( $user_id ) {
$status = get_user_meta ( $user_id , 'account_status' , true );
if ( $status == 'approved' || $status == '' ) {
return true ;
}
return false ;
}
2015-04-25 21:41:47 +02:00
/***
*** @Is private
***/
function is_private_case ( $user_id , $case ) {
$privacy = get_user_meta ( $user_id , 'profile_privacy' , true );
if ( $privacy == $case ) {
$bool = apply_filters ( 'um_is_private_filter_hook' , false , $privacy , $user_id );
return $bool ;
}
return false ;
}
2014-12-30 20:18:29 +02:00
/***
*** @update files
***/
2015-01-11 23:12:05 +02:00
function update_files ( $changes ) {
2014-12-30 20:18:29 +02:00
global $ultimatemember ;
2015-01-11 23:12:05 +02:00
foreach ( $changes as $key => $uri ) {
2014-12-30 20:18:29 +02:00
$src = um_is_temp_upload ( $uri );
$ultimatemember -> files -> new_user_upload ( $this -> id , $src , $key );
}
}
2014-12-15 22:38:07 +02:00
/***
*** @update profile
***/
function update_profile ( $changes ) {
global $ultimatemember ;
$args [ 'ID' ] = $this -> id ;
// save or update profile meta
foreach ( $changes as $key => $value ) {
if ( ! in_array ( $key , $this -> update_user_keys ) ) {
update_user_meta ( $this -> id , $key , $value );
} else {
$args [ $key ] = esc_attr ( $changes [ $key ] );
}
}
2015-01-24 23:39:43 +02:00
// hook for name changes
2014-12-15 22:38:07 +02:00
do_action ( 'um_update_profile_full_name' , $changes );
// update user
if ( count ( $args ) > 1 ) {
wp_update_user ( $args );
}
}
/***
*** @user exists by meta key and value
***/
function user_has_metadata ( $key , $value ) {
global $ultimatemember ;
$value = $ultimatemember -> validation -> safe_name_in_url ( $value );
$ids = get_users ( array ( 'fields' => 'ID' , 'meta_key' => $key , 'meta_value' => $value , 'meta_compare' => '=' ) );
if ( ! isset ( $ids ) || empty ( $ids ) ) return false ;
foreach ( $ids as $k => $id ) {
if ( $id == um_user ( 'ID' ) ){
unset ( $ids [ $k ] );
} else {
$duplicates [] = $id ;
}
}
if ( isset ( $duplicates ) && ! empty ( $duplicates ) )
return count ( $duplicates );
return false ;
}
/***
*** @user exists by name
***/
function user_exists_by_name ( $value ) {
global $ultimatemember ;
$value = $ultimatemember -> validation -> safe_name_in_url ( $value );
$ids = get_users ( array ( 'fields' => 'ID' , 'meta_key' => 'full_name' , 'meta_value' => $value , 'meta_compare' => '=' ) );
if ( isset ( $ids [ 0 ] ) )
return $ids [ 0 ];
return false ;
}
2015-03-10 14:27:56 +02:00
/**
* @function user_exists_by_id()
*
* @description This method checks if a user exists or not in your site based on the user ID.
*
* @usage <?php $ultimatemember->user->user_exists_by_id( $user_id ); ?>
*
* @param $user_id (numeric) (required) A user ID must be passed to check if the user exists
*
* @returns Returns true if user exists and false if user does not exist.
*
* @example Basic Usage
<?php
$boolean = $ultimatemember->user->user_exists_by_id( 15 );
if ( $boolean ) {
// That user exists
}
?>
*
*
*/
2014-12-15 22:38:07 +02:00
function user_exists_by_id ( $user_id ) {
$aux = get_userdata ( $user_id );
if ( $aux == false ){
return false ;
} else {
return $user_id ;
}
}
}