mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-11 18:56:10 +09:00
Merge pull request #1670 from ultimatemember/feature/schedule_account_status_check
account_status schedule action
This commit is contained in:
@@ -350,9 +350,6 @@ if ( ! class_exists( 'um\admin\Users_Columns' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Set default statuses if not already done.
|
||||
UM()->setup()->set_default_user_status();
|
||||
|
||||
$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
|
||||
|
||||
@@ -47,6 +47,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
|
||||
|
||||
$this->lock_registration();
|
||||
|
||||
$this->empty_status_users();
|
||||
|
||||
$this->extensions_page();
|
||||
|
||||
$this->child_theme_required();
|
||||
@@ -204,17 +206,17 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
|
||||
|
||||
ob_start(); ?>
|
||||
|
||||
<div class="<?php echo esc_attr( $class ) ?> um-admin-notice notice <?php echo $dismissible ? 'is-dismissible' : '' ?>" data-key="<?php echo esc_attr( $key ) ?>">
|
||||
<?php echo ! empty( $notice_data['message'] ) ? $notice_data['message'] : '' ?>
|
||||
<div class="<?php echo esc_attr( $class ); ?> um-admin-notice notice <?php echo $dismissible ? 'is-dismissible' : ''; ?>" data-key="<?php echo esc_attr( $key ); ?>">
|
||||
<?php echo ! empty( $notice_data['message'] ) ? $notice_data['message'] : ''; ?>
|
||||
</div>
|
||||
|
||||
<?php $notice = ob_get_clean();
|
||||
<?php
|
||||
$notice = ob_get_clean();
|
||||
if ( $echo ) {
|
||||
echo $notice;
|
||||
return;
|
||||
} else {
|
||||
return $notice;
|
||||
}
|
||||
return $notice;
|
||||
}
|
||||
|
||||
|
||||
@@ -246,6 +248,37 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checking if the "Membership - Anyone can register" WordPress general setting is active
|
||||
*/
|
||||
public function empty_status_users() {
|
||||
$empty_status_users = get_option( '_um_log_empty_status_users', array( 0, 0 ) );
|
||||
if ( ! is_array( $empty_status_users ) ) {
|
||||
$empty_status_users = array( 0, 0 );
|
||||
}
|
||||
|
||||
if ( array( 0, 0 ) === $empty_status_users ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$allowed_html = array(
|
||||
'a' => array(
|
||||
'href' => array(),
|
||||
),
|
||||
'strong' => array(),
|
||||
);
|
||||
|
||||
$this->add_notice(
|
||||
'empty_status_users',
|
||||
array(
|
||||
'class' => 'info',
|
||||
// translators: %1$d: Background update for users is complete; %2$d: Total users for background update.
|
||||
'message' => '<p>' . wp_kses( sprintf( __( 'Background process is running: Setting user statuses %1$d/%2$d.', 'ultimate-member' ), $empty_status_users[0], $empty_status_users[1] ), $allowed_html ) . '</p>',
|
||||
'dismissible' => false,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checking if the "Membership - Anyone can register" WordPress general setting is active
|
||||
*/
|
||||
@@ -256,11 +289,11 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
|
||||
?>
|
||||
|
||||
<p>
|
||||
<?php _e( '<strong>All Access Pass</strong> – Get access to all Ultimate Member extensions at a significant discount with our All Access Pass.', 'ultimate-member' ) ?>
|
||||
<?php _e( '<strong>All Access Pass</strong> – Get access to all Ultimate Member extensions at a significant discount with our All Access Pass.', 'ultimate-member' ); ?>
|
||||
</p>
|
||||
<p>
|
||||
<a href="https://ultimatemember.com/pricing/" class="button button-primary" target="_blank">
|
||||
<?php _e( 'View Pricing', 'ultimate-member' ) ?>
|
||||
<?php esc_html_e( 'View Pricing', 'ultimate-member' ); ?>
|
||||
</a>
|
||||
</p>
|
||||
|
||||
@@ -290,7 +323,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
|
||||
$path = str_replace( '//', '/', $path );
|
||||
|
||||
if ( ! file_exists( $path ) ) {
|
||||
$old = umask(0);
|
||||
$old = umask( 0 );
|
||||
@mkdir( $path, 0777, true );
|
||||
umask( $old );
|
||||
}
|
||||
@@ -326,9 +359,12 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
|
||||
'woocommerce',
|
||||
);
|
||||
|
||||
$slugs = array_map( function( $item ) {
|
||||
return 'um-' . $item . '/um-' . $item . '.php';
|
||||
}, $old_extensions );
|
||||
$slugs = array_map(
|
||||
function ( $item ) {
|
||||
return 'um-' . $item . '/um-' . $item . '.php';
|
||||
},
|
||||
$old_extensions
|
||||
);
|
||||
|
||||
$active_plugins = UM()->dependencies()->get_active_plugins();
|
||||
foreach ( $slugs as $slug ) {
|
||||
@@ -622,7 +658,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
|
||||
$arr_inactive_license_keys[] = $license->item_name;
|
||||
}
|
||||
|
||||
$invalid_license++;
|
||||
++$invalid_license;
|
||||
}
|
||||
|
||||
if ( ! empty( $arr_inactive_license_keys ) ) {
|
||||
@@ -676,34 +712,41 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="<?php echo esc_url( $url ) ?>" class="button button-primary"><?php esc_html_e( 'Visit Upgrade Page', 'ultimate-member' ); ?></a>
|
||||
<a href="<?php echo esc_url( $url ); ?>" class="button button-primary"><?php esc_html_e( 'Visit Upgrade Page', 'ultimate-member' ); ?></a>
|
||||
|
||||
</p>
|
||||
|
||||
<?php $message = ob_get_clean();
|
||||
<?php
|
||||
$message = ob_get_clean();
|
||||
|
||||
$this->add_notice( 'upgrade', array(
|
||||
'class' => 'error',
|
||||
'message' => $message,
|
||||
), 4 );
|
||||
} else {
|
||||
if ( isset( $_GET['msg'] ) && 'updated' === sanitize_key( $_GET['msg'] ) ) {
|
||||
if ( isset( $_GET['page'] ) && 'um_options' === sanitize_key( $_GET['page'] ) ) {
|
||||
$this->add_notice( 'settings_upgrade', array(
|
||||
'class' => 'updated',
|
||||
'message' => '<p>' . __( 'Settings successfully upgraded', 'ultimate-member' ) . '</p>',
|
||||
), 4 );
|
||||
} else {
|
||||
$this->add_notice(
|
||||
'upgrade',
|
||||
array(
|
||||
'class' => 'updated',
|
||||
// translators: %1$s is a plugin name title; %2$s is a plugin version.
|
||||
'message' => '<p>' . sprintf( __( '<strong>%1$s %2$s</strong> Successfully Upgraded', 'ultimate-member' ), UM_PLUGIN_NAME, UM_VERSION ) . '</p>',
|
||||
),
|
||||
4
|
||||
);
|
||||
}
|
||||
$this->add_notice(
|
||||
'upgrade',
|
||||
array(
|
||||
'class' => 'error',
|
||||
'message' => $message,
|
||||
),
|
||||
4
|
||||
);
|
||||
} elseif ( isset( $_GET['msg'] ) && 'updated' === sanitize_key( $_GET['msg'] ) ) {
|
||||
if ( isset( $_GET['page'] ) && 'um_options' === sanitize_key( $_GET['page'] ) ) {
|
||||
$this->add_notice(
|
||||
'settings_upgrade',
|
||||
array(
|
||||
'class' => 'updated',
|
||||
'message' => '<p>' . __( 'Settings successfully upgraded', 'ultimate-member' ) . '</p>',
|
||||
),
|
||||
4
|
||||
);
|
||||
} else {
|
||||
$this->add_notice(
|
||||
'upgrade',
|
||||
array(
|
||||
'class' => 'updated',
|
||||
// translators: %1$s is a plugin name title; %2$s is a plugin version.
|
||||
'message' => '<p>' . sprintf( __( '<strong>%1$s %2$s</strong> Successfully Upgraded', 'ultimate-member' ), UM_PLUGIN_NAME, UM_VERSION ) . '</p>',
|
||||
),
|
||||
4
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -734,18 +777,18 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
|
||||
?>
|
||||
</p>
|
||||
<p>
|
||||
<a href="javascript:void(0);" id="um_add_review_love"><?php _e( 'I love it!', 'ultimate-member' ) ?></a> |
|
||||
<a href="javascript:void(0);" id="um_add_review_good"><?php _e('It\'s good but could be better', 'ultimate-member' ) ?></a> |
|
||||
<a href="javascript:void(0);" id="um_add_review_bad"><?php _e('I don\'t like the plugin', 'ultimate-member' ) ?></a>
|
||||
<a href="javascript:void(0);" id="um_add_review_love"><?php _e( 'I love it!', 'ultimate-member' ); ?></a> |
|
||||
<a href="javascript:void(0);" id="um_add_review_good"><?php _e( 'It\'s good but could be better', 'ultimate-member' ); ?></a> |
|
||||
<a href="javascript:void(0);" id="um_add_review_bad"><?php _e( 'I don\'t like the plugin', 'ultimate-member' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
<div class="um-hidden-notice" data-key="love">
|
||||
<p>
|
||||
<?php printf( __( 'Great! We\'re happy to hear that you love the plugin. It would be amazing if you could let others know why you like %s by leaving a review of the plugin. This will help %s to grow and become more popular and would be massively appreciated by us!' ), UM_PLUGIN_NAME, UM_PLUGIN_NAME ); ?>
|
||||
<?php printf( __( 'Great! We\'re happy to hear that you love the plugin. It would be amazing if you could let others know why you like %1$s by leaving a review of the plugin. This will help %2$s to grow and become more popular and would be massively appreciated by us!' ), UM_PLUGIN_NAME, UM_PLUGIN_NAME ); ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="https://wordpress.org/support/plugin/ultimate-member/reviews/?rate=5#new-post" target="_blank" class="button button-primary um_review_link"><?php _e( 'Leave Review', 'ultimate-member' ) ?></a>
|
||||
<a href="https://wordpress.org/support/plugin/ultimate-member/reviews/?rate=5#new-post" target="_blank" class="button button-primary um_review_link"><?php _e( 'Leave Review', 'ultimate-member' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
<div class="um-hidden-notice" data-key="good">
|
||||
@@ -754,7 +797,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="https://ultimatemember.com/feedback/" target="_blank" class="button button-primary um_review_link"><?php _e( 'Provide Feedback', 'ultimate-member' ) ?></a>
|
||||
<a href="https://ultimatemember.com/feedback/" target="_blank" class="button button-primary um_review_link"><?php _e( 'Provide Feedback', 'ultimate-member' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
<div class="um-hidden-notice" data-key="bad">
|
||||
@@ -763,17 +806,22 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<a href="https://ultimatemember.com/feedback/" target="_blank" class="button button-primary um_review_link"><?php _e( 'Provide Feedback', 'ultimate-member' ) ?></a>
|
||||
<a href="https://ultimatemember.com/feedback/" target="_blank" class="button button-primary um_review_link"><?php _e( 'Provide Feedback', 'ultimate-member' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<?php $message = ob_get_clean();
|
||||
<?php
|
||||
$message = ob_get_clean();
|
||||
|
||||
$this->add_notice( 'reviews_notice', array(
|
||||
'class' => 'updated',
|
||||
'message' => $message,
|
||||
'dismissible' => true
|
||||
), 1 );
|
||||
$this->add_notice(
|
||||
'reviews_notice',
|
||||
array(
|
||||
'class' => 'updated',
|
||||
'message' => $message,
|
||||
'dismissible' => true,
|
||||
),
|
||||
1
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -782,7 +830,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
|
||||
*/
|
||||
function future_changed() {
|
||||
|
||||
ob_start(); ?>
|
||||
ob_start();
|
||||
?>
|
||||
|
||||
<p>
|
||||
<?php
|
||||
@@ -791,12 +840,17 @@ if ( ! class_exists( 'um\admin\core\Admin_Notices' ) ) {
|
||||
?>
|
||||
</p>
|
||||
|
||||
<?php $message = ob_get_clean();
|
||||
<?php
|
||||
$message = ob_get_clean();
|
||||
|
||||
$this->add_notice( 'future_changes', array(
|
||||
'class' => 'updated',
|
||||
'message' => $message,
|
||||
), 2 );
|
||||
$this->add_notice(
|
||||
'future_changes',
|
||||
array(
|
||||
'class' => 'updated',
|
||||
'message' => $message,
|
||||
),
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
namespace um\common\actions;
|
||||
|
||||
use WP_User_Query;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'um\common\actions\Users' ) ) {
|
||||
|
||||
/**
|
||||
* Class Users
|
||||
*
|
||||
* @since 2.10.3
|
||||
*
|
||||
* @package um\common\actions
|
||||
*/
|
||||
class Users {
|
||||
|
||||
const INTERVAL = 3600;
|
||||
|
||||
const SCHEDULE_ACTION = 'um_schedule_empty_account_status_check';
|
||||
|
||||
const BATCH_SIZE = 50;
|
||||
|
||||
const BATCH_ACTION = 'um_set_default_account_status';
|
||||
|
||||
public function __construct() {
|
||||
add_action( 'init', array( &$this, 'add_recurring_action' ) );
|
||||
add_action( self::SCHEDULE_ACTION, array( &$this, 'status_check' ) );
|
||||
add_action( self::BATCH_ACTION, array( &$this, 'batch_check' ), 10, 3 );
|
||||
}
|
||||
|
||||
public function add_recurring_action() {
|
||||
if ( UM()->maybe_action_scheduler()->next_scheduled_action( self::SCHEDULE_ACTION ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
UM()->maybe_action_scheduler()->schedule_recurring_action(
|
||||
time() + 60,
|
||||
self::INTERVAL,
|
||||
self::SCHEDULE_ACTION
|
||||
);
|
||||
}
|
||||
|
||||
public function status_check() {
|
||||
$total_users = UM()->common()->users()::get_empty_status_users();
|
||||
if ( empty( $total_users ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
UM()->maybe_action_scheduler()->enqueue_async_action(
|
||||
self::BATCH_ACTION,
|
||||
array(
|
||||
'page' => 1,
|
||||
'total' => $total_users,
|
||||
'pages' => ceil( $total_users / self::BATCH_SIZE ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform batch checking for users based on specific conditions.
|
||||
* Ignore users with `_um_registration_in_progress` that can be in the process of the registration.
|
||||
* Get users with empty `account_status` meta.
|
||||
*
|
||||
* @param int $page The current page number.
|
||||
* @param int $total The total number of users to process.
|
||||
* @param int $pages The total number of pages to process.
|
||||
*/
|
||||
public function batch_check( $page, $total, $pages ) {
|
||||
$users = new WP_User_Query(
|
||||
array(
|
||||
'number' => self::BATCH_SIZE,
|
||||
'fields' => 'ids',
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'key' => '_um_registration_in_progress',
|
||||
'compare' => 'NOT EXISTS',
|
||||
),
|
||||
array(
|
||||
'key' => '_um_registration_in_progress',
|
||||
'value' => '1',
|
||||
'compare' => '!=',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'key' => 'account_status',
|
||||
'compare' => 'NOT EXISTS',
|
||||
),
|
||||
array(
|
||||
'key' => 'account_status',
|
||||
'value' => '',
|
||||
'compare' => '=',
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$results = $users->get_results();
|
||||
|
||||
if ( ! empty( $results ) ) {
|
||||
$um_empty_status_users = get_option( '_um_log_empty_status_users', array( 0, 0 ) );
|
||||
if ( ! is_array( $um_empty_status_users ) ) {
|
||||
$um_empty_status_users = array( 0, count( $results ) );
|
||||
}
|
||||
|
||||
foreach ( $results as $user_id ) {
|
||||
$res = UM()->common()->users()->approve( $user_id, true, true );
|
||||
if ( $res ) {
|
||||
++$um_empty_status_users[0];
|
||||
}
|
||||
}
|
||||
|
||||
if ( $um_empty_status_users[0] < $um_empty_status_users[1] ) {
|
||||
update_option( '_um_log_empty_status_users', $um_empty_status_users );
|
||||
} else {
|
||||
delete_option( '_um_log_empty_status_users' );
|
||||
}
|
||||
|
||||
$next_page = $page + 1;
|
||||
if ( $next_page <= $pages ) {
|
||||
UM()->maybe_action_scheduler()->enqueue_async_action(
|
||||
self::BATCH_ACTION,
|
||||
array(
|
||||
'page' => $next_page,
|
||||
'total' => $total,
|
||||
'pages' => $pages,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,10 @@ if ( ! class_exists( 'um\common\Init' ) ) {
|
||||
if ( empty( UM()->classes['um\common\actions\emails'] ) ) {
|
||||
UM()->classes['um\common\actions\emails'] = new actions\Emails();
|
||||
}
|
||||
|
||||
if ( empty( UM()->classes['um\common\actions\users'] ) ) {
|
||||
UM()->classes['um\common\actions\users'] = new actions\Users();
|
||||
}
|
||||
// Other classes init here as soon as possible.
|
||||
}
|
||||
|
||||
|
||||
@@ -658,11 +658,12 @@ class Users {
|
||||
*
|
||||
* @param int $user_id User ID.
|
||||
* @param bool $force If true - ignore current user condition.
|
||||
* @param bool $silent If true - don't send email notification. E.g. case when user already exists, but doesn't have a status.
|
||||
*
|
||||
* @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, $force = false ) {
|
||||
public function approve( $user_id, $force = false, $silent = false ) {
|
||||
if ( ! $this->can_be_approved( $user_id, $force ) ) {
|
||||
return false;
|
||||
}
|
||||
@@ -683,25 +684,27 @@ class Users {
|
||||
|
||||
// It's `false` on failure or if the user already has approved status.
|
||||
if ( false !== $result ) {
|
||||
$userdata = get_userdata( $user_id );
|
||||
if ( false === $silent ) {
|
||||
$userdata = get_userdata( $user_id );
|
||||
|
||||
$this->reset_activation_link( $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 );
|
||||
$email_slug = 'welcome_email';
|
||||
if ( 'awaiting_admin_review' === $old_status ) {
|
||||
$email_slug = 'approved_email';
|
||||
$this->maybe_generate_password_reset_key( $userdata );
|
||||
}
|
||||
|
||||
$current_user_id = get_current_user_id();
|
||||
um_fetch_user( $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()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $userdata->user_email, $email_slug, array( 'fetch_user_id' => $user_id ) ) );
|
||||
|
||||
um_fetch_user( $current_user_id );
|
||||
}
|
||||
|
||||
$current_user_id = get_current_user_id();
|
||||
um_fetch_user( $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()->maybe_action_scheduler()->enqueue_async_action( 'um_dispatch_email', array( $userdata->user_email, $email_slug, array( 'fetch_user_id' => $user_id ) ) );
|
||||
|
||||
um_fetch_user( $current_user_id );
|
||||
/**
|
||||
* Fires after User has been approved.
|
||||
*
|
||||
@@ -827,4 +830,29 @@ class Users {
|
||||
$user = WP_Session_Tokens::get_instance( $user_id );
|
||||
$user->destroy_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the number of users with empty `account_status` usermeta.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function get_empty_status_users() {
|
||||
global $wpdb;
|
||||
|
||||
$total_users = $wpdb->get_var(
|
||||
"SELECT COUNT(u.ID)
|
||||
FROM {$wpdb->users} u
|
||||
LEFT JOIN {$wpdb->usermeta} um ON u.ID = um.user_id AND um.meta_key = 'account_status'
|
||||
LEFT JOIN {$wpdb->usermeta} um2 ON u.ID = um2.user_id AND um2.meta_key = '_um_registration_in_progress'
|
||||
WHERE ( um.meta_value IS NULL OR um.meta_value = '' ) AND
|
||||
um2.meta_value IS NULL OR um2.meta_value != '1'"
|
||||
);
|
||||
|
||||
$total_users = absint( $total_users );
|
||||
// In WordPress, an underscore prefix before the option name (e.g., _my_option_name) is commonly used to indicate that the option is private.
|
||||
// This option has a format: {updated_users}/{total_users_for_update}.
|
||||
update_option( '_um_log_empty_status_users', array( 0, $total_users ) );
|
||||
|
||||
return $total_users;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,37 +310,21 @@ KEY meta_value_indx (um_value(191))
|
||||
* @since 2.4.2
|
||||
*/
|
||||
public function set_default_user_status() {
|
||||
$result = get_transient( 'um_count_users_unassigned' );
|
||||
if ( false === $result ) {
|
||||
$args = array(
|
||||
'fields' => 'ids',
|
||||
'number' => 0,
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'account_status',
|
||||
'compare' => 'NOT EXISTS',
|
||||
),
|
||||
),
|
||||
'um_custom_user_query' => true,
|
||||
);
|
||||
|
||||
$users = new WP_User_Query( $args );
|
||||
if ( empty( $users ) || is_wp_error( $users ) ) {
|
||||
$result = array();
|
||||
} else {
|
||||
$result = $users->get_results();
|
||||
}
|
||||
|
||||
set_transient( 'um_count_users_unassigned', $result, DAY_IN_SECONDS );
|
||||
}
|
||||
|
||||
if ( empty( $result ) ) {
|
||||
$total_users = UM()->common()->users()::get_empty_status_users();
|
||||
if ( empty( $total_users ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $result as $user_id ) {
|
||||
update_user_meta( $user_id, 'account_status', 'approved' );
|
||||
}
|
||||
// If there are some users without `account_status` then run the first async batch for update.
|
||||
$batch_size = 50; // See the class constant value `\um\common\actions\Users::BATCH_ACTION`.
|
||||
UM()->maybe_action_scheduler()->enqueue_async_action(
|
||||
$batch_size,
|
||||
array(
|
||||
'page' => 1,
|
||||
'total' => $total_users,
|
||||
'pages' => ceil( $total_users / $batch_size ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -640,7 +640,6 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
UM()->files()->remove_dir( UM()->files()->upload_temp );
|
||||
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_dot' );
|
||||
}
|
||||
|
||||
@@ -959,8 +958,6 @@ if ( ! class_exists( 'um\core\User' ) ) {
|
||||
/** This action is documented in ultimate-member/includes/common/um-actions-register.php */
|
||||
do_action( 'um_user_register', $user_id, $_POST, null );
|
||||
}
|
||||
|
||||
delete_transient( 'um_count_users_unassigned' );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -179,6 +179,8 @@ function um_check_user_status( $user_id, $args, $form_data = null ) {
|
||||
*/
|
||||
do_action( "um_post_registration_{$registration_status}_hook", $user_id, $args, $form_data );
|
||||
|
||||
delete_user_meta( $user_id, '_um_registration_in_progress' ); // Status is set. We can delete this marker.
|
||||
|
||||
if ( is_null( $form_data ) || is_admin() ) {
|
||||
return;
|
||||
}
|
||||
@@ -513,6 +515,11 @@ function um_submit_form_register( $args, $form_data ) {
|
||||
'user_pass' => $user_password,
|
||||
'user_email' => $user_email,
|
||||
'role' => $user_role,
|
||||
'meta_input' => array(
|
||||
// It's used to ignore users who cannot finish the registration process in the scheduled tasks
|
||||
// to set 'approved' status to the users without `account_status` meta.
|
||||
'_um_registration_in_progress' => true,
|
||||
),
|
||||
);
|
||||
|
||||
$user_id = wp_insert_user( $userdata );
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
require_once '../../../../wp-load.php';
|
||||
|
||||
function um_test_generate_random_string( $length = 10 ) {
|
||||
return substr( str_shuffle( str_repeat( $x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil( $length / strlen( $x ) ) ) ), 1, $length );
|
||||
}
|
||||
|
||||
for ( $i = 0; $i < 1000; $i++ ) {
|
||||
$random_user_name = um_test_generate_random_string( 8 ); // Generate a random user name
|
||||
$random_user_email = $random_user_name . '@example.com'; // Append the user name to a dummy email domain
|
||||
$random_user_pass = um_test_generate_random_string( 12 ); // Generate a random user password
|
||||
$random_first_name = um_test_generate_random_string( 5 ); // Generate a random first name
|
||||
$random_last_name = um_test_generate_random_string( 8 ); // Generate a random last name
|
||||
|
||||
$userdata = array(
|
||||
'user_login' => $random_user_name,
|
||||
'user_pass' => 'q1q2q1q2',
|
||||
'user_email' => $random_user_email,
|
||||
'first_name' => $random_first_name,
|
||||
'last_name' => $random_last_name,
|
||||
'role' => 'subscriber',
|
||||
);
|
||||
|
||||
$user_id = wp_insert_user( $userdata );
|
||||
|
||||
if ( is_wp_error( $user_id ) ) {
|
||||
// Something went wrong, handle the error
|
||||
var_dump( 'User creation failed: ' . $user_id->get_error_message() );
|
||||
} else {
|
||||
var_dump( 'User creation complete: ID:' . $user_id . ' Username:' . $userdata['user_login'] );
|
||||
}
|
||||
}
|
||||
|
||||
exit;
|
||||
+1
-1
@@ -127,7 +127,7 @@ if ( ! empty( $delete_options ) ) {
|
||||
delete_transient( "um_count_users_{$status}" );
|
||||
}
|
||||
delete_transient( 'um_count_users_pending_dot' );
|
||||
delete_transient( 'um_count_users_unassigned' );
|
||||
delete_transient( 'um_count_users_unassigned' ); // legacy but still need to delete while uninstall.
|
||||
|
||||
//remove all users cache
|
||||
UM()->user()->remove_cache_all_users();
|
||||
|
||||
Reference in New Issue
Block a user