From c1b3b0d3c470d263d35378959e42e1c4235352a1 Mon Sep 17 00:00:00 2001 From: Nikita Sinelnikov Date: Fri, 12 Aug 2022 23:07:16 +0300 Subject: [PATCH] - fixed issues related to the registration users with awaiting admin review or email confirmation; --- includes/admin/class-admin.php | 2 + includes/core/class-query.php | 4 +- includes/core/class-user.php | 84 ++++++++++++++++++++-------------- uninstall.php | 2 +- 4 files changed, 55 insertions(+), 37 deletions(-) diff --git a/includes/admin/class-admin.php b/includes/admin/class-admin.php index bb6431fd..2d3879ad 100644 --- a/includes/admin/class-admin.php +++ b/includes/admin/class-admin.php @@ -1710,6 +1710,8 @@ if ( ! class_exists( 'um\admin\Admin' ) ) { delete_transient( "um_count_users_{$status}" ); } + do_action( 'um_flush_user_status_cache' ); + $url = add_query_arg( array( 'page' => 'ultimatemember', diff --git a/includes/core/class-query.php b/includes/core/class-query.php index 2320ecd0..ef19440a 100644 --- a/includes/core/class-query.php +++ b/includes/core/class-query.php @@ -270,7 +270,7 @@ if ( ! class_exists( 'um\core\Query' ) ) { * @return int */ function get_pending_users_count() { - $users_count = get_transient( 'um_count_users_pending' ); + $users_count = get_transient( 'um_count_users_pending_dot' ); if ( false === $users_count ) { $args = array( 'fields' => 'ids', @@ -321,7 +321,7 @@ if ( ! class_exists( 'um\core\Query' ) ) { $users_count = $users->get_total(); } - set_transient( 'um_count_users_pending', $users_count ); + set_transient( 'um_count_users_pending_dot', $users_count ); } return $users_count; diff --git a/includes/core/class-user.php b/includes/core/class-user.php index 870025fe..864787a4 100644 --- a/includes/core/class-user.php +++ b/includes/core/class-user.php @@ -127,6 +127,11 @@ if ( ! class_exists( 'um\core\User' ) ) { return; } + // related to the User role > Registration Options Metabox > Registration status 2nd and 3rd option + if ( in_array( $_meta_value, array( 'checkmail', 'pending' ), true ) ) { + return; + } + $pending_statuses = array( 'awaiting_email_confirmation', 'awaiting_admin_review', @@ -138,34 +143,37 @@ if ( ! class_exists( 'um\core\User' ) ) { return; } - // deduct old transient count - $count = get_transient( "um_count_users_{$old}" ); - if ( false !== $count ) { - if ( ! is_numeric( $count ) ) { - delete_transient( "um_count_users_{$old}" ); - } else { - if ( 0 < $count ) { - $count--; - } else { - $count = 0; - } - set_transient( "um_count_users_{$old}", $count ); - } - } - - if ( in_array( $old, $pending_statuses, true ) && ! in_array( $_meta_value, $pending_statuses, true ) ) { + // related to the User role > Registration Options Metabox > Registration status 2nd and 3rd option + if ( ! in_array( $old, array( 'checkmail', 'pending' ), true ) ) { // deduct old transient count - $count = get_transient( 'um_count_users_pending' ); + $count = get_transient( "um_count_users_{$old}" ); if ( false !== $count ) { if ( ! is_numeric( $count ) ) { - delete_transient( 'um_count_users_pending' ); + delete_transient( "um_count_users_{$old}" ); } else { if ( 0 < $count ) { $count--; } else { $count = 0; } - set_transient( 'um_count_users_pending', $count ); + set_transient( "um_count_users_{$old}", $count ); + } + } + + if ( in_array( $old, $pending_statuses, true ) && ! in_array( $_meta_value, $pending_statuses, true ) ) { + // deduct old transient count + $count = get_transient( 'um_count_users_pending_dot' ); + if ( false !== $count ) { + if ( ! is_numeric( $count ) ) { + delete_transient( 'um_count_users_pending_dot' ); + } else { + if ( 0 < $count ) { + $count--; + } else { + $count = 0; + } + set_transient( 'um_count_users_pending_dot', $count ); + } } } } @@ -185,7 +193,7 @@ if ( ! class_exists( 'um\core\User' ) ) { if ( in_array( $_meta_value, $pending_statuses, true ) && ! in_array( $old, $pending_statuses, true ) ) { // add new transient count - $count = get_transient( 'um_count_users_pending' ); + $count = get_transient( 'um_count_users_pending_dot' ); if ( false !== $count ) { if ( is_numeric( $count ) ) { $count++; @@ -195,7 +203,7 @@ if ( ! class_exists( 'um\core\User' ) ) { } else { $count = 1; } - set_transient( 'um_count_users_pending', $count ); + set_transient( 'um_count_users_pending_dot', $count ); } } @@ -211,6 +219,11 @@ if ( ! class_exists( 'um\core\User' ) ) { return; } + // related to the User role > Registration Options Metabox > Registration status 2nd and 3rd option + if ( in_array( $_meta_value, array( 'checkmail', 'pending' ), true ) ) { + return; + } + $pending_statuses = array( 'awaiting_email_confirmation', 'awaiting_admin_review', @@ -231,17 +244,17 @@ if ( ! class_exists( 'um\core\User' ) ) { if ( in_array( $_meta_value, $pending_statuses, true ) ) { // add new transient count - $count = get_transient( 'um_count_users_pending' ); - if ( false !== $count ) { - if ( is_numeric( $count ) ) { - $count++; + $pending_count = get_transient( 'um_count_users_pending_dot' ); + if ( false !== $pending_count ) { + if ( is_numeric( $pending_count ) ) { + $pending_count++; } else { - $count = 1; + $pending_count = 1; } } else { - $count = 1; + $pending_count = 1; } - set_transient( 'um_count_users_pending', $count ); + set_transient( 'um_count_users_pending_dot', $pending_count ); } } @@ -259,6 +272,11 @@ if ( ! class_exists( 'um\core\User' ) ) { $value = ( '' !== $_meta_value ) ? $_meta_value : get_user_meta( $object_id, $meta_key, true ); + // related to the User role > Registration Options Metabox > Registration status 2nd and 3rd option + if ( in_array( $value, array( 'checkmail', 'pending' ), true ) ) { + return; + } + $pending_statuses = array( 'awaiting_email_confirmation', 'awaiting_admin_review', @@ -281,17 +299,17 @@ if ( ! class_exists( 'um\core\User' ) ) { if ( in_array( $value, $pending_statuses, true ) ) { // deduct old transient count - $count = get_transient( 'um_count_users_pending' ); + $count = get_transient( 'um_count_users_pending_dot' ); if ( false !== $count ) { if ( ! is_numeric( $count ) ) { - delete_transient( 'um_count_users_pending' ); + delete_transient( 'um_count_users_pending_dot' ); } else { if ( 0 < $count ) { $count--; } else { $count = 0; } - set_transient( 'um_count_users_pending', $count ); + set_transient( 'um_count_users_pending_dot', $count ); } } } @@ -510,7 +528,7 @@ if ( ! class_exists( 'um\core\User' ) ) { UM()->files()->remove_dir( UM()->uploader()->get_upload_base_dir() . um_user( 'ID' ) . DIRECTORY_SEPARATOR ); delete_transient( 'um_count_users_unassigned' ); - delete_transient( 'um_count_users_pending' ); + delete_transient( 'um_count_users_pending_dot' ); } @@ -730,7 +748,6 @@ if ( ! class_exists( 'um\core\User' ) ) { * @param $user_id */ function user_register_via_admin( $user_id ) { - if ( empty( $user_id ) ) { return; } @@ -768,7 +785,6 @@ if ( ! class_exists( 'um\core\User' ) ) { } delete_transient( 'um_count_users_unassigned' ); - delete_transient( 'um_count_users_pending' ); } diff --git a/uninstall.php b/uninstall.php index 70ad4733..63e24f8b 100644 --- a/uninstall.php +++ b/uninstall.php @@ -126,7 +126,7 @@ if ( ! empty( $delete_options ) ) { foreach ( $statuses as $status ) { delete_transient( "um_count_users_{$status}" ); } - delete_transient( 'um_count_users_pending' ); + delete_transient( 'um_count_users_pending_dot' ); delete_transient( 'um_count_users_unassigned' ); //remove all users cache