Add filter hook to customize empty status user queries

Introduced the `um_get_empty_status_users_query_result` filter to allow customization of the query used for fetching users with empty statuses. This enhances flexibility and enables optimization for different website setups. Updated relevant documentation in the readme file.
This commit is contained in:
Mykyta Synelnikov
2025-09-05 12:17:15 +03:00
parent 58fdd9f943
commit 6ae2ec4ec8
2 changed files with 29 additions and 8 deletions
+20
View File
@@ -979,6 +979,25 @@ class Users {
public static function get_empty_status_users() {
global $wpdb;
/**
* Filters whitelisted usermeta keys that can be stored inside DB after UM Form submission.
*
* @param {int} $total_users Count of the users with empty status. Query result, by default is null.
*
* @return {int} Count of the users with empty status. Or null.
*
* @since 2.10.6
* @hook um_get_empty_status_users_query_result
*
* @example <caption>Customize the empty status users query.</caption>
* function my_get_empty_status_users_query( $total_users ) {
* $total_users = $wpdb->get_var( "your custom DB query here" );
* return $total_users;
* }
* add_filter( 'um_get_empty_status_users_query_result', 'my_get_empty_status_users_query' );
*/
$total_users = apply_filters( 'um_get_empty_status_users_query_result', null );
if ( is_null( $total_users ) ) {
$total_users = $wpdb->get_var(
"SELECT COUNT(DISTINCT u.ID)
FROM {$wpdb->users} u
@@ -987,6 +1006,7 @@ class Users {
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 );
if ( $total_users > 0 ) {
+1
View File
@@ -172,6 +172,7 @@ IMPORTANT: PLEASE UPDATE THE PLUGIN TO AT LEAST VERSION 2.6.7 IMMEDIATELY. VERSI
**Enhancements**
* Added: Avoid caching of the UM Forms on the mobile devices via adding the nocache headers to the screens with UM Forms.
* Added: Filter hook `um_get_empty_status_users_query_result` for changing default query on the different websites to optimize it.
**Bugfixes**