- 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
+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' );
}
+35 -304
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
* @deprecated 2.8.7
*
* @param string $status
*/
function set_status( $status ) {
/**
* UM hook
*
* @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
* }
* ?>
*/
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' );
}
/**
* 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' );
public function assign_secretkey() {
_deprecated_function( __METHOD__, '2.8.7', 'UM()->common()->users()->assign_secretkey()' );
UM()->common()->users()->assign_secretkey( um_user( 'ID' ) );
}
/**
* @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;
}
}
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' ) );
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' ) );
}
/**
* 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' ) );
}
}