- changed wp-admin > Users page;

* updated filters by status, avoid slow queries for getting users count;
* updated bulk-actions for changing statuses (moved to WP native dropdown)
* separate handlers for changing user statuses on wp-admin and frontend (partially implemented);
* created class UM()->common()->users() to handle user statuses in more clear format;
* deprecated old hooks and old functions
This commit is contained in:
Mykyta Synelnikov
2024-09-20 18:41:08 +03:00
parent 2c0478757f
commit 512dc53a18
22 changed files with 1250 additions and 1020 deletions
+2 -1
View File
@@ -150,7 +150,8 @@ if ( ! class_exists( 'um\admin\Secure' ) ) {
}
// Restore Account Status.
if ( isset( $metadata['account_status'] ) ) {
UM()->user()->set_status( $metadata['account_status'] );
// UM()->user()->set_status( $metadata['account_status'] );
UM()->common()->users()->set_status( $user_id, $metadata['account_status'] );
}
// Delete blocked meta.
+288 -251
View File
@@ -2,6 +2,7 @@
namespace um\admin;
use WP_User;
use WP_User_Query;
if ( ! defined( 'ABSPATH' ) ) {
exit;
@@ -20,17 +21,157 @@ if ( ! class_exists( 'um\admin\Users_Columns' ) ) {
* Users_Columns constructor.
*/
public function __construct() {
add_filter( 'manage_users_columns', array( &$this, 'manage_users_columns' ) );
add_filter( 'manage_users_custom_column', array( &$this, 'manage_users_custom_column' ), 10, 3 );
add_action( 'pre_user_query', array( &$this, 'sort_by_newest' ) );
add_filter( 'users_list_table_query_args', array( &$this, 'hide_by_caps' ), 1 );
add_filter( 'views_users', array( &$this, 'restrict_role_links' ) );
add_filter( 'user_row_actions', array( &$this, 'user_row_actions' ), 10, 2 );
add_filter( 'bulk_actions-users', array( &$this, 'add_bulk_actions' ) );
// add_filter( 'handle_bulk_actions-users', array( &$this, 'handle_bulk_actions' ), 10, 3 );
// add_action( 'manage_users_extra_tablenav', array( &$this, 'filter_by_status_action' ) );
//
// add_filter( 'user_row_actions', array( &$this, 'user_row_actions' ), 10, 2 );
//
// add_filter( 'users_list_table_query_args', array( &$this, 'hide_by_caps' ), 1 );
// add_action( 'pre_user_query', array( &$this, 'sort_by_newest' ) );
// add_action( 'pre_user_query', array( &$this, 'filter_users_by_status' ) );
//
// add_filter( 'removable_query_args', array( &$this, 'add_removable_query_args' ) );
add_filter( 'handle_bulk_actions-users', array( &$this, 'handle_bulk_actions' ), 10, 3 );
add_action( 'manage_users_extra_tablenav', array( &$this, 'add_status_filter' ) );
add_action( 'pre_user_query', array( &$this, 'filter_users_by_status' ) );
add_filter( 'removable_query_args', array( &$this, 'add_removable_query_args' ) );
}
/**
* Filter: Add column 'Status'
*
* @param array $columns
*
* @return array
*/
public function manage_users_columns( $columns ) {
$columns['account_status'] = __( 'Status', 'ultimate-member' );
return $columns;
}
/**
* Filter: Show column 'Status'
*
* @param string $value
* @param string $column_name
* @param int $user_id
*
* @return string
*/
public function manage_users_custom_column( $value, $column_name, $user_id ) {
if ( 'account_status' === $column_name ) {
um_fetch_user( $user_id );
$value = um_user( 'account_status_name' );
um_reset_user();
}
return $value;
}
/**
* Change default sorting at WP Users list table
*
* @param WP_User_Query $query Current instance of WP_User_Query (passed by reference).
*/
public function sort_by_newest( $query ) {
global $pagenow;
// phpcs:ignore WordPress.Security.NonceVerification -- situated in WP native query and just checking sorting
if ( 'users.php' === $pagenow && ! isset( $_REQUEST['orderby'] ) && is_admin() ) {
$query->query_vars['order'] = 'desc';
$query->query_orderby = ' ORDER BY user_registered DESC';
}
}
/**
* Hide users who are hidden by role access for not Administrator user
*
* @param array $args Arguments passed to WP_User_Query to retrieve items for the current
* users list table
*
* @return array
*/
public function hide_by_caps( $args ) {
if ( current_user_can( 'manage_options' ) ) {
return $args;
}
// @todo avoid um_user() function using
// @todo check another restrictions not only the role settings. We need to exclude users per user ID.
$can_view_roles = um_user( 'can_view_roles' );
if ( ! empty( $can_view_roles ) && um_user( 'can_view_all' ) ) {
$args['role__in'] = $can_view_roles;
}
return $args;
}
/**
* Hide role filters with not accessible roles
*
* @param array $views
* @return array
*/
public function restrict_role_links( $views ) {
if ( current_user_can( 'manage_options' ) ) {
return $views;
}
$can_view_roles = um_user( 'can_view_roles' );
if ( ! empty( $can_view_roles ) && um_user( 'can_view_all' ) ) {
$wp_roles = wp_roles();
foreach ( $wp_roles->get_names() as $this_role => $name ) {
if ( ! in_array( $this_role, $can_view_roles, true ) ) {
unset( $views[ $this_role ] );
}
}
}
return $views;
}
/**
* Custom row actions for users page
*
* @param array $actions
* @param WP_User $user_object
*
* @return array
*/
public function user_row_actions( $actions, $user_object ) {
$user_id = $user_object->ID;
// Link to Ultimate Member Profile.
$actions['frontend_profile'] = '<a href="' . esc_url( um_user_profile_url( $user_id ) ) . '">' . esc_html__( 'View profile', 'ultimate-member' ) . '</a>';
// The link for open popup with the registration data submitted through Ultimate Member Registration form.
$submitted = get_user_meta( $user_id, 'submitted', true );
if ( ! empty( $submitted ) ) {
$actions['view_info'] = '<a href="#" data-modal="UM_preview_registration" data-modal-size="smaller"
data-dynamic-content="um_admin_review_registration" data-arg1="' . esc_attr( $user_id ) . '" data-arg2="edit_registration">' . esc_html__( 'Info', 'ultimate-member' ) . '</a>';
// For new modal below.
// $actions['view_info'] = '<a href="#" class="um-preview-registration" data-user_id="' . esc_attr( $user_id ) . '">' . esc_html__( 'Info', 'ultimate-member' ) . '</a>';
}
// Remove row actions for now Administrator role and who cannot view profiles of row's user.
if ( ! current_user_can( 'manage_options' ) && ! um_can_view_profile( $user_id ) ) {
unset( $actions['frontend_profile'], $actions['view_info'], $actions['view'] );
}
/**
* Filters the rows actions for the user in wp-admin > Users List Table screen.
*
* Note: Row actions format is 'key' => 'action_link_html'
*
* @since 1.3.x
* @hook um_admin_user_row_actions
*
* @param {array} $actions User's row actions.
* @param {int} $user_id Row's user ID.
*
* @return {array} User's row actions.
*/
return apply_filters( 'um_admin_user_row_actions', $actions, $user_id );
}
/**
@@ -46,7 +187,7 @@ if ( ! class_exists( 'um\admin\Users_Columns' ) ) {
'um_put_as_pending' => __( 'Put as Pending Review', 'ultimate-member' ),
'um_resend_activation' => __( 'Resend Activation E-mail', 'ultimate-member' ),
'um_deactivate' => __( 'Deactivate', 'ultimate-member' ),
'um_reactivate' => __( 'Reactivate', 'ultimate-member' ),
'um_reactivate' => __( 'Reactivate', 'ultimate-member' ), // um_reenable
);
/**
* Filters wp-admin > Users List Table bulk actions.
@@ -92,41 +233,41 @@ if ( ! class_exists( 'um\admin\Users_Columns' ) ) {
}
/**
* Add query args to list of query variable names to remove.
* Adds HTML with the filter by the Ultimate Member status.
*
* @param array $removable_query_args An array of query variable names to remove from a URL
*
* @return array
* @param string $which Where the callback's hook fired.
*/
public function add_removable_query_args( $removable_query_args ) {
$removable_query_args[] = '_um_wpnonce';
$removable_query_args[] = 'approved_count';
$removable_query_args[] = 'rejected_count';
$removable_query_args[] = 'reactivated_count';
$removable_query_args[] = 'deactivated_count';
$removable_query_args[] = 'pending_count';
$removable_query_args[] = 'resend_activation_count';
return $removable_query_args;
public function add_status_filter( $which ) {
if ( 'top' !== $which ) {
return;
}
/**
* Get the user statuses list.
*
* @return array
*/
public function get_user_statuses() {
$statuses = apply_filters(
'um_admin_get_user_statuses',
array(
'approved' => __( 'Approved', 'ultimate-member' ),
'awaiting_admin_review' => __( 'Pending review', 'ultimate-member' ),
'awaiting_email_confirmation' => __( 'Waiting e-mail confirmation', 'ultimate-member' ),
'inactive' => __( 'Inactive', 'ultimate-member' ),
'rejected' => __( 'Rejected', 'ultimate-member' ),
)
);
// Set default statuses if not already done.
UM()->setup()->set_default_user_status();
return $statuses;
$id = 'um_user_status';
// need to add there additional nonce field because WordPress native _wpnonce field isn't visible on the users.php screen then custom actions
wp_nonce_field( 'um-bulk-users', '_um_wpnonce', false );
$statuses = UM()->common()->users()->statuses_list();
?>
<div class="alignleft actions um-filter-by-status">
<label class="screen-reader-text" for="<?php echo esc_attr( $id ); ?>"><?php esc_html_e( 'All Statuses', 'ultimate-member' ); ?></label>
<select name="<?php echo esc_attr( $id ); ?>" id="<?php echo esc_attr( $id ); ?>">
<option value=""><?php esc_html_e( 'All Statuses', 'ultimate-member' ); ?></option>
<?php
foreach ( $statuses as $k => $v ) {
$selected = isset( $_GET[ $id ] ) && sanitize_key( $_GET[ $id ] ) === $k; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- native WordPress nonce is used
?>
<option value="<?php echo esc_attr( $k ); ?>" <?php selected( $selected ); ?>><?php echo esc_html( $v ); ?></option>
<?php
}
?>
</select>
<?php submit_button( __( 'Filter', 'ultimate-member' ), '', 'um_filter_users', false ); ?>
</div>
<?php
}
/**
@@ -146,25 +287,30 @@ if ( ! class_exists( 'um\admin\Users_Columns' ) ) {
}
// need to handle there additional nonce field because WordPress native _wpnonce field isn't visible on the users.php screen then custom actions
check_admin_referer( 'bulk-users', '_um_wpnonce' );
check_admin_referer( 'um-bulk-users', '_um_wpnonce' );
$rolename = UM()->roles()->get_priority_user_role( get_current_user_id() );
$role = get_role( $rolename );
if ( null === $role ) {
return $sendback;
}
// Make Ultimate Member bulk actions only when the current user has 'edit_users' capability.
if ( ! current_user_can( 'edit_users' ) && ! $role->has_cap( 'edit_users' ) ) {
wp_die( esc_html__( 'You do not have enough permissions to do that.', 'ultimate-member' ) );
}
$users = array_map( 'absint', $userids );
$users = array_diff( $users, array( get_current_user_id() ) ); // cannot make any action related to himself.
switch ( $current_action ) {
case 'um_approve_membership':
$approved_count = 0;
foreach ( $users as $user_id ) {
$res = UM()->common()->user()->approve( $user_id );
$res = UM()->common()->users()->approve( $user_id );
if ( $res ) {
$approved_count++;
++$approved_count;
}
}
@@ -176,12 +322,13 @@ if ( ! class_exists( 'um\admin\Users_Columns' ) ) {
$this->set_redirect_uri( $sendback )
);
break;
case 'um_reactivate':
$reactivated_count = 0;
foreach ( $users as $user_id ) {
$res = UM()->common()->user()->reactivate( $user_id );
$res = UM()->common()->users()->reactivate( $user_id );
if ( $res ) {
$reactivated_count++;
++$reactivated_count;
}
}
@@ -193,12 +340,13 @@ if ( ! class_exists( 'um\admin\Users_Columns' ) ) {
$this->set_redirect_uri( $sendback )
);
break;
case 'um_reject_membership':
$rejected_count = 0;
foreach ( $users as $user_id ) {
$res = UM()->common()->user()->reject( $user_id );
$res = UM()->common()->users()->reject( $user_id );
if ( $res ) {
$rejected_count++;
++$rejected_count;
}
}
@@ -210,12 +358,13 @@ if ( ! class_exists( 'um\admin\Users_Columns' ) ) {
$this->set_redirect_uri( $sendback )
);
break;
case 'um_deactivate':
$deactivated_count = 0;
foreach ( $users as $user_id ) {
$res = UM()->common()->user()->deactivate( $user_id );
$res = UM()->common()->users()->deactivate( $user_id );
if ( $res ) {
$deactivated_count++;
++$deactivated_count;
}
}
@@ -227,12 +376,13 @@ if ( ! class_exists( 'um\admin\Users_Columns' ) ) {
$this->set_redirect_uri( $sendback )
);
break;
case 'um_put_as_pending':
$pending_count = 0;
foreach ( $users as $user_id ) {
$res = UM()->common()->user()->set_as_pending( $user_id );
$res = UM()->common()->users()->set_as_pending( $user_id );
if ( $res ) {
$pending_count++;
++$pending_count;
}
}
@@ -244,12 +394,13 @@ if ( ! class_exists( 'um\admin\Users_Columns' ) ) {
$this->set_redirect_uri( $sendback )
);
break;
case 'um_resend_activation':
$email_pending_count = 0;
foreach ( $users as $user_id ) {
$res = UM()->common()->user()->resend_activation( $user_id );
$res = UM()->common()->users()->send_activation( $user_id );
if ( $res ) {
$email_pending_count++;
++$email_pending_count;
}
}
@@ -261,222 +412,90 @@ if ( ! class_exists( 'um\admin\Users_Columns' ) ) {
$this->set_redirect_uri( $sendback )
);
break;
default:
// hook for the handling custom UM actions added via 'um_admin_bulk_user_actions_hook' hook
$sendback = apply_filters( "um_handle_bulk_actions-users-{$current_action}", $sendback, $userids );
/**
* Fires when a custom Ultimate Member bulk action for wp-admin > Users list table should be handled.
*
* The redirect link should be modified with success or failure feedback
* from the action to be used to display feedback to the user.
*
* The dynamic portion of the hook name, `$current_action`, refers to the current bulk action.
* Use together with custom actions added via `um_admin_bulk_user_actions_hook` hook.
*
* @param {string} $sendback The redirect URL.
* @param {array} $userids Selected users in bulk action.
*
* @return {string} The redirect URL.
*
* @since 2.8.7
* @hook um_handle_bulk_actions-users-{$current_action}
*
* @example <caption>Handle custom-action and set redirect after it.</caption>
* function um_custom_bulk_actions_users( $sendback, $userids ) {
* foreach ( $userids as $user_id ) {
* // make some action here
* }
* return add_query_arg( 'action_counter', 'completed action count', $sendback );
* }
* add_filter( 'um_handle_bulk_actions-users-custom-action', 'um_custom_bulk_actions_users' );
*/
$sendback = apply_filters( "um_handle_bulk_actions-users-{$current_action}", $sendback, $userids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
break;
}
return $sendback;
}
/**
* Adds HTML with the filter by the Ultimate Member status.
*
* @param string $which Where the callback's hook fired.
*/
public function filter_by_status_action( $which ) {
$id = 'bottom' === $which ? 'um_status2' : 'um_status';
$button_id = 'bottom' === $which ? 'um_filter_action2' : 'um_filter_action';
if ( 'top' === $which ) {
// need to add there additional nonce field because WordPress native _wpnonce field isn't visible on the users.php screen then custom actions
wp_nonce_field('bulk-users', '_um_wpnonce', false );
}
// Set default statuses if not already done.
UM()->install()->set_default_user_status();
$statuses = $this->get_user_statuses();
?>
<div class="alignleft actions">
<label class="screen-reader-text" for="<?php echo esc_attr( $id ); ?>"><?php _e( 'All Statuses', 'ultimate-member' ); ?></label>
<select name="<?php echo esc_attr( $id ); ?>" id="<?php echo esc_attr( $id ); ?>">
<option value=""><?php esc_html_e( 'All Statuses', 'ultimate-member' ); ?></option>
<?php
foreach ( $statuses as $k => $v ) {
$selected = isset( $_GET['um_status'] ) && $k === sanitize_key( $_GET['um_status'] );
?>
<option value="<?php echo esc_attr( $k ) ?>" <?php selected( $selected ) ?>><?php echo esc_html( $v ); ?></option>
<?php
}
?>
</select>
<?php submit_button( __( 'Filter', 'ultimate-member' ), '', $button_id, false ); ?>
</div>
<?php
}
/**
* Custom row actions for users page
*
* @param array $actions
* @param WP_User $user_object
*
* @return array
*/
public function user_row_actions( $actions, $user_object ) {
$user_id = $user_object->ID;
// Link to Ultimate Member Profile.
$actions['frontend_profile'] = '<a href="' . esc_url( um_user_profile_url( $user_id ) ) . '">' . esc_html__( 'View profile', 'ultimate-member' ) . '</a>';
// The link for open popup with the registration data submitted through Ultimate Member Registration form.
$submitted = get_user_meta( $user_id, 'submitted', true );
if ( ! empty( $submitted ) ) {
$actions['view_info'] = '<a href="#" class="um-preview-registration" data-user_id="' . esc_attr( $user_id ) . '">' . esc_html__( 'Info', 'ultimate-member' ) . '</a>';
}
// Remove row actions for now Administrator role and who cannot view profiles of row's user.
// @todo make the um_can_view_profile() function review. Maybe rewrite it.
if ( ! current_user_can( 'manage_options' ) && ! um_can_view_profile( $user_id ) ) {
unset( $actions['frontend_profile'], $actions['view_info'], $actions['view'] );
}
/**
* Filters the rows actions for the user in wp-admin > Users List Table screen.
*
* Note: Row actions format is 'key' => 'action_link_html'
*
* @since 2.8.7
* @hook um_admin_user_row_actions
*
* @param {array} $actions User's row actions.
* @param {int} $user_id Row's user ID.
*
* @return {array} User's row actions.
*/
return apply_filters( 'um_admin_user_row_actions', $actions, $user_id );
}
/**
* Hide users who are hidden by role access for not Administrator user
*
* @param array $args
* @return array
*/
public function hide_by_caps( $args ) {
if ( current_user_can( 'administrator' ) ) {
return $args;
}
// @todo avoid um_user() function using
$can_view_roles = um_user( 'can_view_roles' );
if ( um_user( 'can_view_all' ) && ! empty( $can_view_roles ) ) {
$args['role__in'] = $can_view_roles;
}
return $args;
}
/**
* Change default sorting at WP Users list table
*
* @param \WP_User_Query $query
*/
public function sort_by_newest( $query ) {
global $pagenow;
if ( is_admin() && 'users.php' === $pagenow ) {
if ( ! isset( $_REQUEST['orderby'] ) ) {
$query->query_vars['order'] = 'desc';
$query->query_orderby = ' ORDER BY user_registered ' . ( 'desc' === $query->query_vars['order'] ? 'desc ' : 'asc ' ); //set sort order
}
}
}
/**
* Filter WP users by UM Status
*
* @param \WP_User_Query $query
* WP_User_Query $query Current instance of WP_User_Query (passed by reference).
*/
public function filter_users_by_status( $query ) {
global $wpdb, $pagenow;
if ( is_admin() && 'users.php' === $pagenow && ! empty( $_REQUEST['um_status'] ) ) {
$status = sanitize_key( $_REQUEST['um_status'] );
if ( 'users.php' !== $pagenow || ! is_admin() ) {
return;
}
if ( empty( $_REQUEST['um_user_status'] ) ) {
return;
}
$status = sanitize_key( $_REQUEST['um_user_status'] );
/**
* Filters the marker to disable Ultimate Member default filter by user status.
*
* @since 2.8.7
* @hook um_skip_filter_users_by_status
*
* @param {bool} $skip Marker to skip Ultimate Member core user filter handler.
* @param {string} $status User Status
*
* @return {array} User's row actions.
*/
$skip_status_filter = apply_filters( 'um_skip_filter_users_by_status', false, $status );
if ( ! $skip_status_filter ) {
if ( false !== $skip_status_filter ) {
return;
}
$query->query_where = str_replace(
'WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.ID IN (
SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
WHERE {$wpdb->usermeta}.meta_key = 'account_status'
AND {$wpdb->usermeta}.meta_value = '{$status}')",
$wpdb->prepare(
"WHERE 1=1 AND
{$wpdb->users}.ID IN (
SELECT {$wpdb->usermeta}.user_id
FROM $wpdb->usermeta
WHERE {$wpdb->usermeta}.meta_key = 'account_status' AND
{$wpdb->usermeta}.meta_value = %s
)",
$status
),
$query->query_where
);
}
}
}
/**
* Does an action to user asap
*
* @param string $action
*/
public function user_action_hook( $action ) {
switch ( $action ) {
default:
/**
* UM hook
*
* @type action
* @title um_admin_custom_hook_{$action}
* @description Integration hook on user action
* @input_vars
* [{"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_admin_custom_hook_{$action}', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_admin_custom_hook_{$action}', 'my_admin_custom_hook', 10, 1 );
* function my_admin_after_main_notices( $user_id ) {
* // your code here
* }
* ?>
*/
do_action( "um_admin_custom_hook_{$action}", UM()->user()->id );
break;
// case 'um_put_as_pending':
// UM()->user()->pending();
// break;
// case 'um_approve_membership':
// case 'um_reenable':
//
// add_filter( 'um_template_tags_patterns_hook', array( UM()->password(), 'add_placeholder' ), 10, 1 );
// add_filter( 'um_template_tags_replaces_hook', array( UM()->password(), 'add_replace_placeholder' ), 10, 1 );
//
// UM()->user()->approve();
// break;
// case 'um_reject_membership':
// UM()->user()->reject();
// break;
// case 'um_resend_activation':
//
// add_filter( 'um_template_tags_patterns_hook', array( UM()->user(), 'add_activation_placeholder' ), 10, 1 );
// add_filter( 'um_template_tags_replaces_hook', array( UM()->user(), 'add_activation_replace_placeholder' ), 10, 1 );
//
// UM()->user()->email_pending();
// break;
// case 'um_deactivate':
// UM()->user()->deactivate();
// break;
case 'um_delete':
if ( is_admin() ) {
wp_die( __( 'This action is not allowed in backend.', 'ultimate-member' ) );
}
UM()->user()->delete();
break;
}
}
/**
* Sets redirect URI after bulk action
@@ -489,11 +508,29 @@ if ( ! class_exists( 'um\admin\Users_Columns' ) ) {
$uri = add_query_arg( 's', sanitize_text_field( $_REQUEST['s'] ), $uri );
}
if ( ! empty( $_REQUEST['um_status'] ) ) {
$uri = add_query_arg( 'um_status', sanitize_key( $_REQUEST['um_status'] ), $uri );
if ( ! empty( $_REQUEST['um_user_status'] ) ) {
$uri = add_query_arg( 'um_user_status', sanitize_key( $_REQUEST['um_user_status'] ), $uri );
}
return $uri;
}
/**
* Add query args to list of query variable names to remove.
*
* @param array $removable_query_args An array of query variable names to remove from a URL
*
* @return array
*/
public function add_removable_query_args( $removable_query_args ) {
$removable_query_args[] = '_um_wpnonce'; // need to add there additional nonce field because WordPress native _wpnonce field isn't visible on the users.php screen then custom actions
$removable_query_args[] = 'approved_count';
$removable_query_args[] = 'rejected_count';
$removable_query_args[] = 'reactivated_count';
$removable_query_args[] = 'deactivated_count';
$removable_query_args[] = 'pending_count';
$removable_query_args[] = 'resend_activation_count';
return $removable_query_args;
}
}
}
@@ -30,8 +30,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Ajax_Hooks' ) ) {
add_action( 'wp_ajax_um_member_directory_default_filter_settings', array( UM()->member_directory(), 'default_filter_settings' ) );
add_action( 'wp_ajax_um_same_page_update', array( UM()->admin_settings(), 'same_page_update_ajax' ) );
add_action( 'wp_ajax_um_get_users', array( UM()->users(), 'get_users' ) );
}
}
@@ -33,42 +33,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Columns' ) ) {
add_filter( 'display_post_states', array( &$this, 'add_display_post_states' ), 10, 2 );
add_filter( 'post_row_actions', array( &$this, 'remove_bulk_actions_um_form_inline' ), 10, 2 );
add_filter( 'manage_users_columns', array( &$this, 'manage_users_columns' ) );
add_filter( 'manage_users_custom_column', array( &$this, 'manage_users_custom_column' ), 10, 3 );
}
/**
* Filter: Add column 'Status'
*
* @param array $columns
*
* @return array
*/
public function manage_users_columns( $columns ) {
$columns['account_status'] = __( 'Status', 'ultimate-member' );
return $columns;
}
/**
* Filter: Show column 'Status'
*
* @param string $val
* @param string $column_name
* @param int $user_id
*
* @return string
*/
public function manage_users_custom_column( $val, $column_name, $user_id ) {
if ( $column_name == 'account_status' ) {
um_fetch_user( $user_id );
$value = um_user( 'account_status_name' );
um_reset_user();
return $value;
}
return $val;
}
/**
@@ -502,6 +502,36 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
case 'um_secure_restore':
$messages[0]['content'] = __( 'Account has been successfully restored.', 'ultimate-member' );
break;
case 'um_approved':
$approved_count = isset( $_REQUEST['approved_count'] ) ? absint( $_REQUEST['approved_count'] ) : 0;
$messages[0]['content'] = sprintf( _n( '<strong>%s</strong> user has been approved.', '<strong>%s</strong> users have been approved.', $approved_count, 'ultimate-member' ), $approved_count );
break;
case 'um_reactivated':
$reactivated_count = isset( $_REQUEST['reactivated_count'] ) ? absint( $_REQUEST['reactivated_count'] ) : 0;
$messages[0]['content'] = sprintf( _n( '<strong>%s</strong> user has been reactivated.', '<strong>%s</strong> users have been reactivated.', $reactivated_count, 'ultimate-member' ), $reactivated_count );
break;
case 'um_rejected':
$rejected_count = isset( $_REQUEST['rejected_count'] ) ? absint( $_REQUEST['rejected_count'] ) : 0;
$messages[0]['content'] = sprintf( _n( '<strong>%s</strong> user has been rejected.', '<strong>%s</strong> users have been rejected.', $rejected_count, 'ultimate-member' ), $rejected_count );
break;
case 'um_deactivate':
$deactivated_count = isset( $_REQUEST['deactivated_count'] ) ? absint( $_REQUEST['deactivated_count'] ) : 0;
$messages[0]['content'] = sprintf( _n( '<strong>%s</strong> user has been deactivated.', '<strong>%s</strong> users have been deactivated.', $deactivated_count, 'ultimate-member' ), $deactivated_count );
break;
case 'um_pending':
$pending_count = isset( $_REQUEST['pending_count'] ) ? absint( $_REQUEST['pending_count'] ) : 0;
$messages[0]['content'] = sprintf( _n( '<strong>%s</strong> user has been set as pending admin review.', '<strong>%s</strong> users have been set as pending admin review.', $pending_count, 'ultimate-member' ), $pending_count );
break;
case 'um_resend_activation':
$resend_activation_count = isset( $_REQUEST['resend_activation_count'] ) ? absint( $_REQUEST['resend_activation_count'] ) : 0;
$messages[0]['content'] = sprintf( _n( 'Activation email for <strong>%s</strong> user has been sent.', 'Activation emails for <strong>%s</strong> users have been sent.', $resend_activation_count, 'ultimate-member' ), $resend_activation_count );
break;
default:
/**
* Filters the custom admin notice after um_adm_action.
+2 -384
View File
@@ -13,102 +13,13 @@ if ( ! class_exists( 'um\admin\core\Admin_Users' ) ) {
*/
class Admin_Users {
/**
* @var string
*/
public $custom_role = 'um_role';
/**
* Admin_Users constructor.
*/
public function __construct() {
add_filter( 'user_row_actions', array( &$this, 'user_row_actions' ), 10, 2 );
//add_action( 'admin_init', array( &$this, 'um_bulk_users_edit' ), 9 );
add_filter( 'user_has_cap', array( &$this, 'map_caps_by_role' ), 10, 4 );
add_filter( 'users_list_table_query_args', array( &$this, 'hide_by_caps' ), 1, 1 );
add_filter( 'pre_user_query', array( &$this, 'sort_by_newest' ) );
add_filter( 'pre_user_query', array( &$this, 'filter_users_by_status' ) );
add_filter( 'views_users', array( &$this, 'add_status_links' ) );
add_action( 'admin_init', array( &$this, 'um_bulk_users_edit' ), 9 );
add_action( 'um_admin_user_action_hook', array( &$this, 'user_action_hook' ), 10, 1 );
}
public function get_users() {
UM()->admin()->check_ajax_nonce();
$search_request = ! empty( $_REQUEST['search'] ) ? sanitize_text_field( $_REQUEST['search'] ) : '';
$page = ! empty( $_REQUEST['page'] ) ? absint( $_REQUEST['page'] ) : 1;
$per_page = 20;
$args = array(
'fields' => array( 'ID', 'user_login' ),
'paged' => $page,
'number' => $per_page,
);
if ( ! empty( $search_request ) ) {
$args['search'] = '*' . $search_request . '*';
}
$args = apply_filters( 'um_get_users_list_ajax_args', $args );
$users_query = new \WP_User_Query( $args );
$users = $users_query->get_results();
$total_count = $users_query->get_total();
if ( ! empty( $_REQUEST['avatar'] ) ) {
foreach ( $users as $key => $user ) {
$url = get_avatar_url( $user->ID );
$users[ $key ]->img = $url;
}
}
wp_send_json_success(
array(
'users' => $users,
'total_count' => $total_count,
)
);
}
/**
* Restrict the edit/delete users via wp-admin screen by the UM role capabilities
*
* @param $allcaps
* @param $cap
* @param $args
* @param $user
*
* @return mixed
*/
public function map_caps_by_role( $allcaps, $cap, $args, $user ) {
if ( isset( $cap[0] ) && $cap[0] == 'edit_users' ) {
if ( isset( $args[0] ) && isset( $args[1] ) && ! user_can( $args[1], 'administrator' ) && $args[0] == 'edit_user' ) {
if ( isset( $args[2] ) && ! UM()->roles()->um_current_user_can( 'edit', $args[2] ) ) {
$allcaps[ $cap[0] ] = false;
}
}
} elseif ( isset( $cap[0] ) && $cap[0] == 'delete_users' ) {
if ( isset( $args[0] ) && isset( $args[1] ) && ! user_can( $args[1], 'administrator' ) && $args[0] == 'delete_user' ) {
if ( isset( $args[2] ) && ! UM()->roles()->um_current_user_can( 'delete', $args[2] ) ) {
$allcaps[ $cap[0] ] = false;
}
}
} elseif ( isset( $cap[0] ) && $cap[0] == 'list_users' ) {
if ( isset( $args[0] ) && isset( $args[1] ) && ! user_can( $args[1], 'administrator' ) && $args[0] == 'list_users' ) {
if ( ! um_user( 'can_view_all' ) ) {
$allcaps[ $cap[0] ] = false;
}
}
}
return $allcaps;
//add_action( 'um_admin_user_action_hook', array( &$this, 'user_action_hook' ), 10, 1 );
}
/**
@@ -141,33 +52,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Users' ) ) {
do_action( "um_admin_custom_hook_{$action}", UM()->user()->id );
break;
case 'um_put_as_pending':
UM()->user()->pending();
break;
case 'um_approve_membership':
case 'um_reenable':
add_filter( 'um_template_tags_patterns_hook', array( UM()->password(), 'add_placeholder' ), 10, 1 );
add_filter( 'um_template_tags_replaces_hook', array( UM()->password(), 'add_replace_placeholder' ), 10, 1 );
UM()->user()->approve();
break;
case 'um_reject_membership':
UM()->user()->reject();
break;
case 'um_resend_activation':
add_filter( 'um_template_tags_patterns_hook', array( UM()->user(), 'add_activation_placeholder' ), 10, 1 );
add_filter( 'um_template_tags_replaces_hook', array( UM()->user(), 'add_activation_replace_placeholder' ), 10, 1 );
UM()->user()->email_pending();
break;
case 'um_deactivate':
UM()->user()->deactivate();
break;
case 'um_delete':
if ( is_admin() ) {
wp_die( esc_html__( 'This action is not allowed in backend.', 'ultimate-member' ) );
@@ -202,252 +86,6 @@ if ( ! class_exists( 'um\admin\core\Admin_Users' ) ) {
}
}
/**
* Get UM bulk actions HTML
*
* @deprecated 2.8.7
*
* @return string
*/
public function get_bulk_admin_actions() {
$actions = apply_filters( 'um_admin_bulk_user_actions_hook', array(
'um_approve_membership' => array(
'label' => __( 'Approve Membership', 'ultimate-member' )
),
'um_reject_membership' => array(
'label' => __( 'Reject Membership', 'ultimate-member' )
),
'um_put_as_pending' => array(
'label' => __( 'Put as Pending Review', 'ultimate-member' )
),
'um_resend_activation' => array(
'label' => __( 'Resend Activation Email', 'ultimate-member' )
),
'um_deactivate' => array(
'label' => __( 'Deactivate', 'ultimate-member' )
),
'um_reenable' => array(
'label' => __( 'Reactivate', 'ultimate-member' )
)
) );
$output = '';
foreach ( $actions as $id => $action_data ) {
$output .= '<option value="' . $id . '" '. disabled( isset( $arr['disabled'] ), true, false ) . '>' . $action_data['label'] . '</option>';
}
return $output;
}
/**
* Custom row actions for users page
*
* @param array $actions
* @param $user_object \WP_User
* @return array
*/
public function user_row_actions( $actions, $user_object ) {
$user_id = $user_object->ID;
$actions['frontend_profile'] = '<a href="' . esc_url( um_user_profile_url( $user_id ) ) . '">' . __( 'View profile', 'ultimate-member' ) . '</a>';
$submitted = get_user_meta( $user_id, 'submitted', true );
if ( ! empty( $submitted ) ) {
$actions['view_info'] = '<a href="javascript:void(0);" data-modal="UM_preview_registration" data-modal-size="smaller"
data-dynamic-content="um_admin_review_registration" data-arg1="' . esc_attr( $user_id ) . '" data-arg2="edit_registration">' . __( 'Info', 'ultimate-member' ) . '</a>';
}
if ( ! current_user_can( 'administrator' ) ) {
if ( ! um_can_view_profile( $user_id ) ) {
unset( $actions['frontend_profile'] );
unset( $actions['view_info'] );
unset( $actions['view'] );
}
}
/**
* UM hook
*
* @type filter
* @title um_admin_user_row_actions
* @description Admin views array
* @input_vars
* [{"var":"$actions","type":"array","desc":"User List Table actions"},
* {"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_admin_user_row_actions', 'function_name', 10, 2 );
* @example
* <?php
* add_filter( 'um_admin_user_row_actions', 'my_admin_user_row_actions', 10, 2 );
* function my_admin_user_row_actions( $actions, $user_id ) {
* // your code here
* return $actions;
* }
* ?>
*/
$actions = apply_filters( 'um_admin_user_row_actions', $actions, $user_id );
return $actions;
}
/**
* Change default sorting at WP Users list table
*
* @param array $args
* @return array
*/
public function hide_by_caps( $args ) {
if ( ! current_user_can( 'administrator' ) ) {
$can_view_roles = um_user( 'can_view_roles' );
if ( um_user( 'can_view_all' ) && ! empty( $can_view_roles ) ) {
$args['role__in'] = $can_view_roles;
}
}
return $args;
}
/**
* Change default sorting at WP Users list table
*
* @param $query
* @return mixed
*/
public function sort_by_newest( $query ) {
global $pagenow;
if ( is_admin() && 'users.php' === $pagenow ) {
if ( ! isset( $_REQUEST['orderby'] ) ) {
$query->query_vars['order'] = 'desc';
$query->query_orderby = ' ORDER BY user_registered ' . ( 'desc' === $query->query_vars['order'] ? 'desc ' : 'asc ' ); //set sort order
}
}
return $query;
}
/**
* Filter WP users by UM Status
*
* @param $query
* @return mixed
*/
public function filter_users_by_status( $query ) {
global $wpdb, $pagenow;
if ( is_admin() && 'users.php' === $pagenow && ! empty( $_REQUEST['um_status'] ) ) {
$status = sanitize_key( $_REQUEST['um_status'] );
if ( 'needs-verification' === $status ) {
$query->query_where = str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.ID IN (
SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
WHERE {$wpdb->usermeta}.meta_key = '_um_verified'
AND {$wpdb->usermeta}.meta_value = 'pending')",
$query->query_where
);
} else {
$query->query_where = str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.ID IN (
SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta
WHERE {$wpdb->usermeta}.meta_key = 'account_status'
AND {$wpdb->usermeta}.meta_value = '{$status}')",
$query->query_where
);
}
}
return $query;
}
/**
* Add status links to WP Users List Table
*
* @param $views
* @return array
*/
public function add_status_links( $views ) {
remove_filter( 'pre_user_query', array( &$this, 'filter_users_by_status' ) );
$old_views = $views;
$views = array();
if ( ! isset( $_REQUEST['role'] ) && ! isset( $_REQUEST['um_status'] ) ) {
$views['all'] = '<a href="' . admin_url( 'users.php' ) . '" class="current">' . __( 'All', 'ultimate-member' ) . ' <span class="count">(' . UM()->query()->count_users() . ')</span></a>';
} else {
$views['all'] = '<a href="' . admin_url( 'users.php' ) . '">' . __( 'All', 'ultimate-member' ) . ' <span class="count">(' . UM()->query()->count_users() . ')</span></a>';
}
$status = array(
'approved' => __( 'Approved', 'ultimate-member' ),
'awaiting_admin_review' => __( 'Pending review', 'ultimate-member' ),
'awaiting_email_confirmation' => __( 'Waiting email confirmation', 'ultimate-member' ),
'inactive' => __( 'Inactive', 'ultimate-member' ),
'rejected' => __( 'Rejected', 'ultimate-member' ),
);
// set default statuses if not already done
UM()->setup()->set_default_user_status();
foreach ( $status as $k => $v ) {
if ( isset( $_REQUEST['um_status'] ) && sanitize_key( $_REQUEST['um_status'] ) === $k ) {
$current = 'class="current"';
} else {
$current = '';
}
$views[ $k ] = '<a href="' . esc_url( admin_url( 'users.php' ) . '?um_status=' . $k ) . '" ' . $current . '>' . $v . ' <span class="count">(' . UM()->query()->count_users_by_status( $k ) . ')</span></a>';
}
/**
* UM hook
*
* @type filter
* @title um_admin_views_users
* @description Admin views array
* @input_vars
* [{"var":"$views","type":"array","desc":"User Views"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_admin_views_users', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_admin_views_users', 'my_admin_views_users', 10, 1 );
* function my_admin_views_users( $views ) {
* // your code here
* return $views;
* }
* ?>
*/
$views = apply_filters( 'um_admin_views_users', $views );
// remove all filters
unset( $old_views['all'] );
// add separator
$views['subsep'] = '<span></span>';
// merge views
foreach ( $old_views as $key => $view ) {
$views[ $key ] = $view;
}
// hide filters with not accessible roles
if ( ! current_user_can( 'administrator' ) ) {
$wp_roles = wp_roles();
$can_view_roles = um_user( 'can_view_roles' );
if ( ! empty( $can_view_roles ) ) {
foreach ( $wp_roles->get_names() as $this_role => $name ) {
if ( ! in_array( $this_role, $can_view_roles, true ) ) {
unset( $views[ $this_role ] );
}
}
}
}
return $views;
}
/**
* Bulk user editing actions
*/
@@ -528,25 +166,5 @@ if ( ! class_exists( 'um\admin\core\Admin_Users' ) ) {
exit;
}
}
/**
* Sets redirect URI after bulk action
*
* @param string $uri
* @return string
*/
public function set_redirect_uri( $uri ) {
if ( ! empty( $_REQUEST['s'] ) ) {
$uri = add_query_arg( 's', sanitize_text_field( $_REQUEST['s'] ), $uri );
}
if ( ! empty( $_REQUEST['um_status'] ) ) {
$uri = add_query_arg( 'um_status', sanitize_key( $_REQUEST['um_status'] ), $uri );
}
return $uri;
}
}
}
+13
View File
@@ -23,6 +23,7 @@ if ( ! class_exists( 'um\ajax\Init' ) ) {
$this->forms();
$this->pages();
$this->secure();
$this->users();
}
/**
@@ -60,5 +61,17 @@ if ( ! class_exists( 'um\ajax\Init' ) ) {
}
return UM()->classes['um\ajax\secure'];
}
/**
* @since 2.8.7
*
* @return Users
*/
public function users() {
if ( empty( UM()->classes['um\ajax\users'] ) ) {
UM()->classes['um\ajax\users'] = new Users();
}
return UM()->classes['um\ajax\users'];
}
}
}
+56
View File
@@ -0,0 +1,56 @@
<?php
namespace um\ajax;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class Users
*
* @package um\ajax
*/
class Users {
public function __construct() {
add_action( 'wp_ajax_um_get_users', array( $this, 'get_users' ) );
}
public function get_users() {
UM()->admin()->check_ajax_nonce();
$search_request = ! empty( $_REQUEST['search'] ) ? sanitize_text_field( $_REQUEST['search'] ) : '';
$page = ! empty( $_REQUEST['page'] ) ? absint( $_REQUEST['page'] ) : 1;
$per_page = 20;
$args = array(
'fields' => array( 'ID', 'user_login' ),
'paged' => $page,
'number' => $per_page,
);
if ( ! empty( $search_request ) ) {
$args['search'] = '*' . $search_request . '*';
}
$args = apply_filters( 'um_get_users_list_ajax_args', $args );
$users_query = new \WP_User_Query( $args );
$users = $users_query->get_results();
$total_count = $users_query->get_total();
if ( ! empty( $_REQUEST['avatar'] ) ) {
foreach ( $users as $key => $user ) {
$url = get_avatar_url( $user->ID );
$users[ $key ]->img = $url;
}
}
wp_send_json_success(
array(
'users' => $users,
'total_count' => $total_count,
)
);
}
}
-15
View File
@@ -526,7 +526,6 @@ if ( ! class_exists( 'UM' ) ) {
$this->admin_settings();
$this->columns();
$this->metabox();
$this->users();
$this->dragdrop();
$this->admin_gdpr();
$this->admin_navmenu();
@@ -902,20 +901,6 @@ if ( ! class_exists( 'UM' ) ) {
return $this->classes['admin_metabox'];
}
/**
* @since 2.0
*
* @return um\admin\core\Admin_Users()
*/
function users() {
if ( empty( $this->classes['admin_users'] ) ) {
$this->classes['admin_users'] = new um\admin\core\Admin_Users();
}
return $this->classes['admin_users'];
}
/**
* @since 2.0
*
+13
View File
@@ -25,6 +25,7 @@ if ( ! class_exists( 'um\common\Init' ) ) {
$this->secure()->hooks();
$this->site_health();
$this->theme()->hooks();
$this->users()->hooks();
}
/**
@@ -86,5 +87,17 @@ if ( ! class_exists( 'um\common\Init' ) ) {
}
return UM()->classes['um\common\theme'];
}
/**
* @since 2.8.7
*
* @return Users
*/
public function users() {
if ( empty( UM()->classes['um\common\users'] ) ) {
UM()->classes['um\common\users'] = new Users();
}
return UM()->classes['um\common\users'];
}
}
}
+4 -2
View File
@@ -229,9 +229,11 @@ if ( ! class_exists( 'um\common\Secure' ) ) {
$user->update_user_level_from_caps();
if ( is_user_logged_in() ) {
UM()->user()->set_status( 'inactive' );
//UM()->user()->set_status( 'inactive' );
UM()->common()->users()->set_status( $user->ID, 'inactive' );
} else {
UM()->user()->set_status( 'rejected' );
//UM()->user()->set_status( 'rejected' );
UM()->common()->users()->set_status( $user->ID, 'rejected' );
}
um_reset_user();
update_user_meta( $user->ID, 'um_user_blocked', 'suspicious_activity' );
+755
View File
@@ -0,0 +1,755 @@
<?php
namespace um\common;
use WP_Error;
use WP_Session_Tokens;
use WP_User;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class Users
*
* @package um\common
*/
class Users {
public function hooks() {
add_filter( 'user_has_cap', array( &$this, 'map_caps_by_role' ), 10, 3 );
add_filter( 'editable_roles', array( &$this, 'restrict_roles' ) );
}
/**
* Restrict the edit/delete users via wp-admin screen due UM role capabilities
*
* @param bool[] $allcaps Array of key/value pairs where keys represent a capability name
* and boolean values represent whether the user has that capability.
* @param string[] $caps Required primitive capabilities for the requested capability.
* @param array $args {
* Arguments that accompany the requested capability check.
*
* @type string $0 Requested capability.
* @type int $1 Concerned user ID.
* @type mixed ...$2 Optional second and further parameters, typically object ID.
* }
*
* @return bool[]
*/
public function map_caps_by_role( $allcaps, $caps, $args ) {
if ( ! isset( $caps[0], $args[0], $args[1] ) ) {
return $allcaps;
}
if ( ! in_array( $caps[0], array( 'edit_users', 'delete_users', 'list_users' ), true ) ) {
return $allcaps;
}
if ( user_can( $args[1], 'manage_options' ) ) {
return $allcaps;
}
if ( 'edit_users' === $caps[0] && 'edit_user' === $args[0] ) {
if ( isset( $args[2] ) && ! UM()->roles()->um_current_user_can( 'edit', $args[2] ) ) {
$allcaps[ $caps[0] ] = false;
}
} elseif ( 'delete_users' === $caps[0] && 'delete_user' === $args[0] ) {
if ( isset( $args[2] ) && ! UM()->roles()->um_current_user_can( 'delete', $args[2] ) ) {
$allcaps[ $caps[0] ] = false;
}
} elseif ( 'list_users' === $caps[0] ) {
if ( 'list_users' === $args[0] && ! um_user( 'can_view_all' ) ) {
$allcaps[ $caps[0] ] = false;
}
}
return $allcaps;
}
/**
* Hide role filters with not accessible roles
*
* @param array $roles
* @return array
*/
public function restrict_roles( $roles ) {
if ( current_user_can( 'manage_options' ) ) {
return $roles;
}
$can_view_roles = UM()->roles()->um_user_can( 'can_view_roles' );
if ( UM()->roles()->um_user_can( 'can_view_all' ) && empty( $can_view_roles ) ) {
return $roles;
}
if ( ! empty( $can_view_roles ) ) {
$wp_roles = wp_roles();
foreach ( $wp_roles->get_names() as $this_role => $name ) {
if ( ! in_array( $this_role, $can_view_roles, true ) ) {
unset( $roles[ $this_role ] );
}
}
}
return $roles;
}
/**
* Get the user statuses list.
*
* @return array
*/
public function statuses_list() {
$statuses = array(
'approved' => __( 'Approved', 'ultimate-member' ),
'awaiting_admin_review' => __( 'Pending review', 'ultimate-member' ),
'awaiting_email_confirmation' => __( 'Waiting email confirmation', 'ultimate-member' ),
'inactive' => __( 'Inactive', 'ultimate-member' ),
'rejected' => __( 'Rejected', 'ultimate-member' ),
);
/**
* Filters the user statuses added via Ultimate Member plugin.
*
* Note: Statuses format is 'key' => 'title'
*
* @since 2.8.7
* @hook um_admin_get_user_statuses
*
* @param {array} $statuses User statuses in Ultimate Member environment.
*
* @return {array} User statuses.
*/
return apply_filters( 'um_admin_get_user_statuses', $statuses );
}
/**
* Set user's account status.
*
* @param int $user_id User ID.
* @param string $status Status key.
*
* @return bool
*/
public function set_status( $user_id, $status ) {
$old_status = $this->get_status( $user_id );
/**
* Fires before User status is set.
*
* @since 2.8.7
* @hook um_before_user_status_is_set
*
* @param {string} $status New status key.
* @param {int} $user_id User ID.
* @param {string} $old_status Old status key.
*/
do_action( 'um_before_user_status_is_set', $status, $user_id, $old_status );
$result = update_user_meta( $user_id, 'account_status', $status );
// false on failure or if the value passed to the function is the same as the one that is already in the database.
if ( false !== $result ) {
// backward compatibility. @todo maybe uncomment it after some testing.
// UM()->user()->profile['account_status'] = $status;
// Reset cache.
$this->remove_cache( $user_id );
/**
* Fires just after User status is changed.
*
* @since 1.3.x
* @since 2.0 Added $user_id
* @since 2.8.7 Added $old_status
*
* @hook um_after_user_status_is_changed
*
* @param {string} $status Status key.
* @param {int} $user_id User ID. Since 2.0
* @param {string} $old_status Old status key. Since 2.8.7
*/
do_action( 'um_after_user_status_is_changed', $status, $user_id, $old_status );
return true;
}
return false;
}
/**
* Get user account status.
*
* @param int $user_id User ID
*
* @return string
*/
public function get_status( $user_id ) {
return get_user_meta( $user_id, 'account_status', true );
}
/**
* Check if user has selected account status.
*
* @since 2.8.7
*
* @param int $user_id User ID.
* @param string $status_control Status key.
*
* @return bool
*/
public function has_status( $user_id, $status_control ) {
$status = $this->get_status( $user_id );
return $status === $status_control;
}
/**
* Reset User cache
*
* @param int $user_id User ID.
*/
public function remove_cache( $user_id ) {
delete_option( "um_cache_userdata_{$user_id}" );
}
/**
* Reset Activation link hash.
*
* @param int $user_id User ID.
*/
public function reset_activation_link( $user_id ) {
delete_user_meta( $user_id, 'account_secret_hash' );
delete_user_meta( $user_id, 'account_secret_hash_expiry' );
}
/**
* Set user's activation link hash
*
* @param int $user_id User ID.
*/
public function assign_secretkey( $user_id ) {
if ( ! $this->has_status( $user_id, 'awaiting_email_confirmation' ) ) {
return;
}
/**
* Fires before user activation link hash is generated.
*
* @since 1.3.x
* @since 2.8.7 Added $user_id
* @hook um_before_user_hash_is_changed
*
* @param {int} $user_id User ID. Since 2.8.7
*/
do_action( 'um_before_user_hash_is_changed', $user_id );
$hash = UM()->validation()->generate();
update_user_meta( $user_id, 'account_secret_hash', $hash );
// backward compatibility. @todo maybe uncomment it after some testing.
// UM()->user()->profile['account_secret_hash'] = $hash;
$expiration = '';
$expiry_time = UM()->options()->get( 'activation_link_expiry_time' );
if ( ! empty( $expiry_time ) && is_numeric( $expiry_time ) ) {
$expiration = time() + $expiry_time * DAY_IN_SECONDS;
update_user_meta( $user_id, 'account_secret_hash_expiry', $expiration );
// backward compatibility. @todo maybe uncomment it after some testing.
// UM()->user()->profile['account_secret_hash_expiry'] = $expiration;
}
/**
* Fires after user activation link hash is changed.
*
* @since 1.3.x
* @since 2.8.7 Added $user_id, $hash, $expiration
* @hook um_before_user_hash_is_changed
*
* @param {int} $user_id User ID. Since 2.8.7.
* @param {string} $hash Activation link hash. Since 2.8.7.
* @param {int} $expiration Expiration timestamp. Since 2.8.7.
*/
do_action( 'um_after_user_hash_is_changed', $user_id, $hash, $expiration );
}
/**
* @param WP_User $userdata
*
* @return string|WP_Error
*/
public function maybe_generate_password_reset_key( $userdata ) {
return get_password_reset_key( $userdata );
}
public function can_activation_send( $user_id ) {
$current_user_id = get_current_user_id();
if ( $current_user_id === $user_id ) {
return false;
}
// $rolename = UM()->roles()->get_priority_user_role( $current_user_id );
// $role = get_role( $rolename );
//
// if ( null === $role ) {
// return false;
// }
//
// // Make Ultimate Member bulk actions only when the current user has 'edit_users' capability.
// if ( ! current_user_can( 'edit_users' ) && ! $role->has_cap( 'edit_users' ) ) {
// return false;
// }
$status = $this->get_status( $user_id );
return 'awaiting_admin_review' !== $status;
}
public function send_activation( $user_id ) {
if ( ! $this->can_activation_send( $user_id ) ) {
return false;
}
/**
* Fires before User has been set as pending email confirmation.
*
* @since 2.8.7
* @hook um_before_user_is_set_as_awaiting_email_confirmation
*
* @param {int} $user_id User ID.
*/
do_action( 'um_before_user_is_set_as_awaiting_email_confirmation', $user_id );
$result = $this->set_status( $user_id, 'awaiting_email_confirmation' );
// It's `false` on failure or if the user already has rejected status.
if ( false !== $result ) {
//clear all sessions for email confirmation pending users
$user = WP_Session_Tokens::get_instance( $user_id );
$user->destroy_all();
// Set activation link hash.
$this->assign_secretkey( $user_id );
$userdata = get_userdata( $user_id );
add_filter( 'um_template_tags_patterns_hook', array( UM()->user(), 'add_activation_placeholder' ) );
add_filter( 'um_template_tags_replaces_hook', array( UM()->user(), 'add_activation_replace_placeholder' ) );
UM()->mail()->send( $userdata->user_email, 'checkmail_email' );
/**
* Fires after User has been set as pending email confirmation.
*
* @since 2.8.7
* @hook um_after_user_is_set_as_awaiting_email_confirmation
*
* @param {int} $user_id User ID.
*/
do_action( 'um_after_user_is_set_as_awaiting_email_confirmation', $user_id );
return true;
}
return false;
}
/**
* @param $user_id
*
* @return bool
*/
public function can_be_deactivated( $user_id ) {
$current_user_id = get_current_user_id();
if ( $current_user_id === $user_id ) {
return false;
}
// $rolename = UM()->roles()->get_priority_user_role( $current_user_id );
// $role = get_role( $rolename );
//
// if ( null === $role ) {
// return false;
// }
//
// // Make Ultimate Member bulk actions only when the current user has 'edit_users' capability.
// if ( ! current_user_can( 'edit_users' ) && ! $role->has_cap( 'edit_users' ) ) {
// return false;
// }
$status = $this->get_status( $user_id );
if ( 'inactive' === $status ) {
// Break if the user already approved
return false;
}
if ( 'approved' !== $status ) {
// Break if the user already doesn't approved yet
return false;
}
return true;
}
/**
* @param $user_id
*
* @return bool
*/
public function deactivate( $user_id ) {
if ( ! $this->can_be_deactivated( $user_id ) ) {
return false;
}
/**
* Fires before User has been deactivated.
*
* @since 2.8.7
* @hook um_before_user_is_deactivated
*
* @param {int} $user_id User ID.
*/
do_action( 'um_before_user_is_deactivated', $user_id );
$result = $this->set_status( $user_id, 'inactive' );
// It's `false` on failure or if the user already has approved status.
if ( false !== $result ) {
// Clear all sessions for inactive users
$user = WP_Session_Tokens::get_instance( $user_id );
$user->destroy_all();
$userdata = get_userdata( $user_id );
UM()->mail()->send( $userdata->user_email, 'inactive_email' );
/**
* Fires after User has been deactivated.
*
* @since 1.3.x
* @hook um_after_user_is_inactive
*
* @param {int} $user_id User ID.
*/
do_action( 'um_after_user_is_inactive', $user_id );
return true;
}
return false;
}
/**
* @param $user_id
*
* @return bool
*/
public function can_be_rejected( $user_id ) {
$current_user_id = get_current_user_id();
if ( $current_user_id === $user_id ) {
return false;
}
// $rolename = UM()->roles()->get_priority_user_role( $current_user_id );
// $role = get_role( $rolename );
//
// if ( null === $role ) {
// return false;
// }
//
// // Make Ultimate Member bulk actions only when the current user has 'edit_users' capability.
// if ( ! current_user_can( 'edit_users' ) && ! $role->has_cap( 'edit_users' ) ) {
// return false;
// }
$status = $this->get_status( $user_id );
if ( 'rejected' === $status ) {
// Break if the user already rejected
return false;
}
if ( 'approved' !== $status ) {
// Break if the user already doesn't approved yet
return false;
}
return true;
}
/**
* @param $user_id
*
* @return bool
*/
public function reject( $user_id ) {
if ( ! $this->can_be_rejected( $user_id ) ) {
return false;
}
/**
* Fires before User has been rejected.
*
* @since 2.8.7
* @hook um_before_user_is_rejected
*
* @param {int} $user_id User ID.
*/
do_action( 'um_before_user_is_rejected', $user_id );
$result = $this->set_status( $user_id, 'rejected' );
// It's `false` on failure or if the user already has rejected status.
if ( false !== $result ) {
// Clear all sessions for rejected users
$user = WP_Session_Tokens::get_instance( $user_id );
$user->destroy_all();
$userdata = get_userdata( $user_id );
UM()->mail()->send( $userdata->user_email, 'rejected_email' );
/**
* Fires after User has been rejected.
*
* @since 2.8.7
* @hook um_after_user_is_rejected
*
* @param {int} $user_id User ID.
*/
do_action( 'um_after_user_is_rejected', $user_id );
return true;
}
return false;
}
/**
* @param int $user_id
*
* @return bool
*/
public function can_be_set_as_pending( $user_id ) {
$current_user_id = get_current_user_id();
if ( $current_user_id === $user_id ) {
return false;
}
// $rolename = UM()->roles()->get_priority_user_role( $current_user_id );
// $role = get_role( $rolename );
//
// if ( null === $role ) {
// return false;
// }
//
// // Make Ultimate Member bulk actions only when the current user has 'edit_users' capability.
// if ( ! current_user_can( 'edit_users' ) && ! $role->has_cap( 'edit_users' ) ) {
// return false;
// }
$status = $this->get_status( $user_id );
return 'awaiting_admin_review' !== $status;
}
/**
* @param int $user_id
*
* @return bool
*/
public function set_as_pending( $user_id ) {
if ( ! $this->can_be_set_as_pending( $user_id ) ) {
return false;
}
/**
* Fires before User has been set as pending admin review.
*
* @since 2.8.7
* @hook um_before_user_is_set_as_pending
*
* @param {int} $user_id User ID.
*/
do_action( 'um_before_user_is_set_as_pending', $user_id );
$result = $this->set_status( $user_id, 'awaiting_admin_review' );
// It's `false` on failure or if the user already has rejected status.
if ( false !== $result ) {
// Clear all sessions for awaiting admin confirmation users
$user = WP_Session_Tokens::get_instance( $user_id );
$user->destroy_all();
$userdata = get_userdata( $user_id );
UM()->mail()->send( $userdata->user_email, 'pending_email' );
/**
* Fires after User has been set as pending admin review.
*
* @since 2.8.7
* @hook um_after_user_is_set_as_pending
*
* @param {int} $user_id User ID.
*/
do_action( 'um_after_user_is_set_as_pending', $user_id );
return true;
}
return false;
}
/**
* Check if the user can be approved.
*
* @param int $user_id User ID
*
* @return bool
*/
public function can_be_approved( $user_id ) {
$current_user_id = get_current_user_id();
if ( $current_user_id === $user_id ) {
return false;
}
// $rolename = UM()->roles()->get_priority_user_role( $current_user_id );
// $role = get_role( $rolename );
//
// if ( null === $role ) {
// return false;
// }
//
// // Make Ultimate Member bulk actions only when the current user has 'edit_users' capability.
// if ( ! current_user_can( 'edit_users' ) && ! $role->has_cap( 'edit_users' ) ) {
// return false;
// }
$status = $this->get_status( $user_id );
return 'approved' !== $status;
}
/**
* Approve user.
*
* @param int $user_id User ID.
*
* @return bool `true` if the user has been approved
* `false` on failure or if the user already has approved status.
*/
public function approve( $user_id ) {
if ( ! $this->can_be_approved( $user_id ) ) {
return false;
}
/**
* Fires before User has been approved.
*
* @since 2.8.7
* @hook um_before_user_is_approved
*
* @param {int} $user_id User ID.
*/
do_action( 'um_before_user_is_approved', $user_id );
$old_status = $this->get_status( $user_id );
$result = $this->set_status( $user_id, 'approved' );
// It's `false` on failure or if the user already has approved status.
if ( false !== $result ) {
$userdata = get_userdata( $user_id );
$this->reset_activation_link( $user_id );
$email_slug = 'welcome_email';
if ( 'awaiting_admin_review' === $old_status ) {
$email_slug = 'approved_email';
$this->maybe_generate_password_reset_key( $userdata );
}
add_filter( 'um_template_tags_patterns_hook', array( UM()->password(), 'add_placeholder' ) );
add_filter( 'um_template_tags_replaces_hook', array( UM()->password(), 'add_replace_placeholder' ) );
UM()->mail()->send( $userdata->user_email, $email_slug );
/**
* Fires after User has been approved.
*
* @since 1.3.x
* @hook um_after_user_is_approved
*
* @param {int} $user_id User ID.
*/
do_action( 'um_after_user_is_approved', $user_id );
return true;
}
return false;
}
/**
* @param int $user_id
*
* @return bool
*/
public function can_be_reactivated( $user_id ) {
$current_user_id = get_current_user_id();
if ( $current_user_id === $user_id ) {
return false;
}
// $rolename = UM()->roles()->get_priority_user_role( $current_user_id );
// $role = get_role( $rolename );
//
// if ( null === $role ) {
// return false;
// }
//
// // Make Ultimate Member bulk actions only when the current user has 'edit_users' capability.
// if ( ! current_user_can( 'edit_users' ) && ! $role->has_cap( 'edit_users' ) ) {
// return false;
// }
$status = $this->get_status( $user_id );
return 'inactive' === $status;
}
/**
* @param int $user_id
*
* @return bool
*/
public function reactivate( $user_id ) {
if ( ! $this->can_be_reactivated( $user_id ) ) {
return false;
}
/**
* Fires before User has been reactivated.
*
* @since 2.8.7
* @hook um_before_user_is_reactivated
*
* @param {int} $user_id User ID.
*/
do_action( 'um_before_user_is_reactivated', $user_id );
$result = $this->set_status( $user_id, 'approved' );
// It's `false` on failure or if the user already has approved status.
if ( false !== $result ) {
// Reset activation link hash.
$this->reset_activation_link( $user_id );
$userdata = get_userdata( $user_id );
add_filter( 'um_template_tags_patterns_hook', array( UM()->password(), 'add_placeholder' ) );
add_filter( 'um_template_tags_replaces_hook', array( UM()->password(), 'add_replace_placeholder' ) );
UM()->mail()->send( $userdata->user_email, 'welcome_email' );
/**
* Fires after User has been reactivated.
*
* @since 2.8.7
* @hook um_after_user_is_reactivated
*
* @param {int} $user_id User ID.
*/
do_action( 'um_after_user_is_reactivated', $user_id );
return true;
}
return false;
}
}
+1 -1
View File
@@ -129,7 +129,7 @@ if ( ! class_exists( 'um\core\Permalinks' ) ) {
$set_password_required = get_user_meta( $user_id, 'um_set_password_required', true );
um_fetch_user( $user_id );
UM()->user()->approve();
UM()->common()->users()->approve( $user_id );
if ( ! empty( $set_password_required ) ) {
$redirect = um_user( 'password_reset_link' );
}
+34 -303
View File
@@ -130,7 +130,6 @@ if ( ! class_exists( 'um\core\User' ) ) {
add_action( 'personal_options_update', array( &$this, 'remove_cache' ) );
//add_action('edit_user_profile_update', array(&$this, 'remove_cache') );
add_action( 'um_when_role_is_set', array( &$this, 'remove_cache' ) );
add_action( 'um_when_status_is_set', array( &$this, 'remove_cache' ) );
add_action( 'show_user_profile', array( $this, 'profile_form_additional_section' ), 10 );
add_action( 'user_new_form', array( $this, 'profile_form_additional_section' ), 10 );
@@ -1504,134 +1503,23 @@ if ( ! class_exists( 'um\core\User' ) ) {
/**
* Set user's account status
*
* @param $status
*/
function set_status( $status ) {
/**
* UM hook
* @deprecated 2.8.7
*
* @type action
* @title um_when_status_is_set
* @description Action on user status changed
* @input_vars
* [{"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_when_status_is_set', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_when_status_is_set', 'my_when_status_is_set', 10, 1 );
* function my_when_status_is_set( $user_id ) {
* // your code here
* }
* ?>
* @param string $status
*/
do_action( 'um_when_status_is_set', um_user( 'ID' ) );
$this->profile['account_status'] = $status;
$this->update_usermeta_info( 'account_status' );
/**
* UM hook
*
* @type action
* @title um_after_user_status_is_changed_hook
* @description Action after user status changed
* @input_vars
* [{"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_after_user_status_is_changed_hook', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_after_user_status_is_changed_hook', 'my_after_user_status_is_changed', 10 );
* function my_after_user_status_is_changed() {
* // your code here
* }
* ?>
*/
do_action( 'um_after_user_status_is_changed_hook', um_user( 'ID' ) );
/**
* UM hook
*
* @type action
* @title um_after_user_status_is_changed
* @description Action after user status changed
* @input_vars
* [{"var":"$status","type":"string","desc":"User Status"},
* {"var":"$user_id","type":"integer","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_after_user_status_is_changed', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_after_user_status_is_changed', 'my_after_user_status_is_changed', 10, 1 );
* function my_after_user_status_is_changed( $status ) {
* // your code here
* }
* ?>
*/
do_action( 'um_after_user_status_is_changed', $status, um_user( 'ID' ) );
public function set_status( $status ) {
_deprecated_function( __METHOD__, '2.8.7', 'UM()->common()->users()->set_status()' );
UM()->common()->users()->set_status( $status, um_user( 'ID' ) );
}
/**
* Set user's hash
*/
function assign_secretkey() {
/**
* UM hook
*
* @type action
* @title um_before_user_hash_is_changed
* @description Action before user hash is changed
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_before_user_hash_is_changed', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_before_user_hash_is_changed', 'my_before_user_hash_is_changed', 10 );
* function my_before_user_hash_is_changed() {
* // your code here
* }
* ?>
*/
do_action( 'um_before_user_hash_is_changed' );
$this->profile['account_secret_hash'] = UM()->validation()->generate();
$this->update_usermeta_info( 'account_secret_hash' );
$expiry_time = UM()->options()->get( 'activation_link_expiry_time' );
if ( ! empty( $expiry_time ) && is_numeric( $expiry_time ) ) {
$this->profile['account_secret_hash_expiry'] = time() + $expiry_time * DAY_IN_SECONDS;
$this->update_usermeta_info( 'account_secret_hash_expiry' );
public function assign_secretkey() {
_deprecated_function( __METHOD__, '2.8.7', 'UM()->common()->users()->assign_secretkey()' );
UM()->common()->users()->assign_secretkey( um_user( 'ID' ) );
}
/**
* UM hook
*
* @type action
* @title um_after_user_hash_is_changed
* @description Action after user hash is changed
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_after_user_hash_is_changed', 'function_name', 10 );
* @example
* <?php
* add_action( 'um_after_user_hash_is_changed', 'my_after_user_hash_is_changed', 10 );
* function my_after_user_hash_is_changed() {
* // your code here
* }
* ?>
*/
do_action( 'um_after_user_hash_is_changed' );
}
/**
* @param \WP_User $userdata
*
@@ -1677,186 +1565,53 @@ if ( ! class_exists( 'um\core\User' ) ) {
/**
* This method approves a user membership and sends them an optional welcome/approval email.
*
* @usage <?php UM()->user()->approve(); ?>
*
* @example Approve a pending user and allow him to sign-in to your site.
<?php
um_fetch_user( 352 );
UM()->user()->approve();
?>
*
* @param bool $repeat @deprecated
* @deprecated 2.8.7
*/
public function approve( $repeat = true ) {
$user_id = um_user( 'ID' );
if ( ! $repeat ) {
$status = get_user_meta( $user_id, 'account_status', true );
if ( 'approved' === $status ) {
return;
public function approve( $repeat = true ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- deprecated function
_deprecated_function( __METHOD__, '2.8.7', 'UM()->common()->users()->approve()' );
UM()->common()->users()->approve( um_user( 'ID' ) );
}
}
delete_option( "um_cache_userdata_{$user_id}" );
if ( 'awaiting_admin_review' === um_user( 'account_status' ) ) {
$userdata = get_userdata( $user_id );
$this->maybe_generate_password_reset_key( $userdata );
UM()->mail()->send( um_user( 'user_email' ), 'approved_email' );
} else {
//$userdata = get_userdata( $user_id );
//get_password_reset_key( $userdata );
UM()->mail()->send( um_user( 'user_email' ), 'welcome_email' );
}
$this->set_status( 'approved' );
$this->delete_meta( 'account_secret_hash' );
$this->delete_meta( 'account_secret_hash_expiry' );
/**
* UM hook
*
* @type action
* @title um_after_user_is_approved
* @description Action after user was approved
* @input_vars
* [{"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_after_user_is_approved', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_after_user_is_approved', 'my_after_user_is_approved', 10, 1 );
* function my_after_user_hash_is_changed( $user_id ) {
* // your code here
* }
* ?>
*/
do_action( 'um_after_user_is_approved', um_user( 'ID' ) );
}
/**
* Pending email
* @deprecated 2.8.7
*/
function email_pending() {
$this->assign_secretkey();
$this->set_status( 'awaiting_email_confirmation' );
//clear all sessions for email confirmation pending users
$user = \WP_Session_Tokens::get_instance( um_user( 'ID' ) );
$user->destroy_all();
UM()->mail()->send( um_user( 'user_email' ), 'checkmail_email' );
public function email_pending() {
_deprecated_function( __METHOD__, '2.8.7', 'UM()->common()->users()->send_activation()' );
UM()->common()->users()->send_activation( um_user( 'ID' ) );
}
/**
* This method puts a user under manual review by administrator and sends them an optional email.
*
* @usage <?php UM()->user()->pending(); ?>
*
* @example An example of putting a user pending manual review
<?php
um_fetch_user( 54 );
UM()->user()->pending();
?>
*
* @deprecated 2.8.7
* @return void
*/
function pending() {
$this->set_status( 'awaiting_admin_review' );
//clear all sessions for awaiting admin confirmation users
$user = \WP_Session_Tokens::get_instance( um_user( 'ID' ) );
$user->destroy_all();
UM()->mail()->send( um_user( 'user_email' ), 'pending_email' );
public function pending() {
_deprecated_function( __METHOD__, '2.8.7', 'UM()->common()->users()->set_as_pending()' );
UM()->common()->users()->set_as_pending( um_user( 'ID' ) );
}
/**
* This method rejects a user membership and sends them an optional email.
*
* @usage <?php UM()->user()->reject(); ?>
*
* @example Reject a user membership example
<?php
um_fetch_user( 114 );
UM()->user()->reject();
?>
*
* @deprecated 2.8.7
* @return void
*/
function reject() {
$this->set_status( 'rejected' );
//clear all sessions for rejected users
$user = \WP_Session_Tokens::get_instance( um_user( 'ID' ) );
$user->destroy_all();
UM()->mail()->send( um_user( 'user_email' ), 'rejected_email' );
public function reject() {
_deprecated_function( __METHOD__, '2.8.7', 'UM()->common()->users()->reject()' );
UM()->common()->users()->reject( um_user( 'ID' ) );
}
/**
* This method deactivates a user membership and sends them an optional email.
*
* @usage <?php UM()->user()->deactivate(); ?>
*
* @example Deactivate a user membership with the following example
<?php
um_fetch_user( 32 );
$ultimatemember->user->deactivate();
?>
*
* @deprecated 2.8.7
* @return void
*/
function deactivate() {
$this->set_status( 'inactive' );
//clear all sessions for inactive users
$user = \WP_Session_Tokens::get_instance( um_user( 'ID' ) );
$user->destroy_all();
/**
* UM hook
*
* @type action
* @title um_after_user_is_inactive
* @description Action after user was inactive
* @input_vars
* [{"var":"$user_id","type":"int","desc":"User ID"}]
* @change_log
* ["Since: 2.0"]
* @usage add_action( 'um_after_user_is_inactive', 'function_name', 10, 1 );
* @example
* <?php
* add_action( 'um_after_user_is_inactive', 'my_after_user_is_inactive', 10, 1 );
* function my_after_user_is_inactive( $user_id ) {
* // your code here
* }
* ?>
*/
do_action( 'um_after_user_is_inactive', um_user( 'ID' ) );
UM()->mail()->send( um_user( 'user_email' ), 'inactive_email' );
public function deactivate() {
_deprecated_function( __METHOD__, '2.8.7', 'UM()->common()->users()->deactivate()' );
UM()->common()->users()->deactivate( um_user( 'ID' ) );
}
/**
* Delete user
*
@@ -2522,7 +2277,6 @@ if ( ! class_exists( 'um\core\User' ) ) {
return $hash_email_address;
}
/**
* UM Placeholders for activation link in email
*
@@ -2530,12 +2284,11 @@ if ( ! class_exists( 'um\core\User' ) ) {
*
* @return array
*/
function add_activation_placeholder( $placeholders ) {
public function add_activation_placeholder( $placeholders ) {
$placeholders[] = '{account_activation_link}';
return $placeholders;
}
/**
* UM Replace Placeholders for activation link in email
*
@@ -2543,31 +2296,9 @@ if ( ! class_exists( 'um\core\User' ) ) {
*
* @return array
*/
function add_activation_replace_placeholder( $replace_placeholders ) {
public function add_activation_replace_placeholder( $replace_placeholders ) {
$replace_placeholders[] = um_user( 'account_activation_link' );
return $replace_placeholders;
}
/**
* Get pending users (in queue)
*
* @deprecated 2.4.2
*/
function get_pending_users_count() {
_deprecated_function( __METHOD__, '2.4.2', 'UM()->query()->get_pending_users_count()' );
return UM()->query()->get_pending_users_count();
}
/**
* Remove cached queue from Users backend
*
* @deprecated 2.4.2
*/
function remove_cached_queue() {
_deprecated_function( __METHOD__, '2.4.2', '' );
delete_option( 'um_cached_users_queue' );
}
}
}
+2 -1
View File
@@ -239,7 +239,8 @@ if ( ! class_exists( 'um\core\rest\API_v1' ) ) {
switch ( $data ) {
case 'status':
UM()->user()->set_status( $value );
//UM()->user()->set_status( $value );
UM()->common()->users()->set_status( $id, $value );
$response['success'] = __( 'User status has been changed.', 'ultimate-member' );
break;
case 'role':
+2 -1
View File
@@ -221,7 +221,8 @@ if ( ! class_exists( 'um\core\rest\API_v2' ) ) {
switch ( $data ) {
case 'status':
UM()->user()->set_status( $value );
// UM()->user()->set_status( $value );
UM()->common()->users()->set_status( $id, $value );
$response['success'] = __( 'User status has been changed.', 'ultimate-member' );
break;
case 'role':
+15 -11
View File
@@ -90,22 +90,29 @@ function um_action_request_process() {
}
um_fetch_user( $uid );
UM()->user()->reject();
UM()->common()->users()->reject( $uid );
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
case 'um_approve_membership':
case 'um_reenable':
if ( ! $can_edit_users ) {
wp_die( esc_html__( 'You do not have permission to make this action.', 'ultimate-member' ) );
}
um_fetch_user( $uid );
add_filter( 'um_template_tags_patterns_hook', array( UM()->password(), 'add_placeholder' ), 10, 1 );
add_filter( 'um_template_tags_replaces_hook', array( UM()->password(), 'add_replace_placeholder' ), 10, 1 );
UM()->common()->users()->approve( $uid );
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
UM()->user()->approve();
case 'um_reactivate':
if ( ! $can_edit_users ) {
wp_die( esc_html__( 'You do not have permission to make this action.', 'ultimate-member' ) );
}
um_fetch_user( $uid );
UM()->common()->users()->reactivate( $uid );
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
@@ -115,7 +122,7 @@ function um_action_request_process() {
}
um_fetch_user( $uid );
UM()->user()->pending();
UM()->common()->users()->set_as_pending( $uid );
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
@@ -124,11 +131,8 @@ function um_action_request_process() {
wp_die( esc_html__( 'You do not have permission to make this action.', 'ultimate-member' ) );
}
add_filter( 'um_template_tags_patterns_hook', array( UM()->user(), 'add_activation_placeholder' ), 10, 1 );
add_filter( 'um_template_tags_replaces_hook', array( UM()->user(), 'add_activation_replace_placeholder' ), 10, 1 );
um_fetch_user( $uid );
UM()->user()->email_pending();
UM()->common()->users()->send_activation( $uid );
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
@@ -138,7 +142,7 @@ function um_action_request_process() {
}
um_fetch_user( $uid );
UM()->user()->deactivate();
UM()->common()->users()->deactivate( $uid );
exit( wp_redirect( UM()->permalinks()->get_current_url( true ) ) );
break;
+5 -4
View File
@@ -11,7 +11,7 @@ if ( ! defined( 'ABSPATH' ) ) {
function um_post_registration_approved_hook( $user_id ) {
um_fetch_user( $user_id );
UM()->user()->approve();
UM()->common()->users()->approve( $user_id );
}
add_action( 'um_post_registration_approved_hook', 'um_post_registration_approved_hook' );
@@ -23,7 +23,7 @@ add_action( 'um_post_registration_approved_hook', 'um_post_registration_approved
function um_post_registration_checkmail_hook( $user_id ) {
um_fetch_user( $user_id );
UM()->user()->email_pending();
UM()->common()->users()->send_activation( $user_id );
}
add_action( 'um_post_registration_checkmail_hook', 'um_post_registration_checkmail_hook' );
@@ -35,7 +35,7 @@ add_action( 'um_post_registration_checkmail_hook', 'um_post_registration_checkma
function um_post_registration_pending_hook( $user_id ) {
um_fetch_user( $user_id );
UM()->user()->pending();
UM()->common()->users()->set_as_pending( $user_id );
}
add_action( 'um_post_registration_pending_hook', 'um_post_registration_pending_hook' );
@@ -64,7 +64,8 @@ function um_after_insert_user( $user_id, $args, $form_data = null ) {
um_fetch_user( $user_id );
$status = um_user( 'status' );
}
UM()->user()->set_status( $status );
// UM()->user()->set_status( $status );
UM()->common()->users()->set_status( $user_id, $status );
// Create user uploads directory.
UM()->uploader()->get_upload_user_base_dir( $user_id, true );
+1 -1
View File
@@ -42,7 +42,7 @@ function um_admin_user_actions_hook( $actions, $user_id ) {
}
if ( 'inactive' === $account_status ) {
$actions['um_reenable'] = array( 'label' => __( 'Reactivate this account', 'ultimate-member' ) );
$actions['um_reactivate'] = array( 'label' => __( 'Reactivate this account', 'ultimate-member' ) );
}
}
+20
View File
@@ -45,3 +45,23 @@ if ( ! defined( 'ABSPATH' ) ) {
* }
* add_filter( 'um_language_file', 'my_um_language_file' );
*/
/**
* Fires after user status changed.
*
* @param {int} $user_id User ID.
*
* @since 1.3.x
* @depecated 2.8.7 use action hook `um_after_user_status_is_changed` instead.
* @hook um_after_user_status_is_changed_hook
*/
/**
* Fires just before User status is changed.
*
* @since 1.3.x
* @depecated 2.8.7 use action hook `um_before_user_status_is_set` instead.
* @hook um_when_status_is_set
*
* @param {int} $user_id User ID. Since 2.0
*/
+1 -1
View File
@@ -1579,7 +1579,7 @@ function um_can_view_field( $data ) {
/**
* Checks if user can view profile
*
* @todo make the function review. Maybe rewrite it.
* @param int $user_id
*
* @return bool
+1 -1
View File
@@ -3,7 +3,7 @@
* Plugin Name: Ultimate Member
* Plugin URI: http://ultimatemember.com/
* Description: The easiest way to create powerful online communities and beautiful user profiles with WordPress
* Version: 2.8.7-alpha
* Version: 2.8.7
* Author: Ultimate Member
* Author URI: http://ultimatemember.com/
* Text Domain: ultimate-member