Support » Plugin: New User Approve » Get Number of Pending Users

  • Resolved Howdy_McGee

    (@howdy_mcgee)


    I’m trying to add a “Pending Users Count” onto the “Users” main menu via a bubble. The code looks like this (feel free to implement 😀 !). Now $numPending is supposed to hold the number of pending users so my question is: Do you have a function to get the number of pending users?

    /** Add Post Pending Bubble to CPT **/
    function pending_posts_bubble(){
        global $menu;
    
    	// Count Number of Pending Members
    	$numPending = 4;
    
    	// Make sure there are pending members
    	if ( $numPending > 0 ) {
    		// Locate the key of
    		$key = recursive_array_search_php_91365( "users.php", $menu );
    
    		// Not found, just in case
    		if( !$key )
    			return;
    
    		// Modify menu item
    		$menu[$key][0] .= sprintf(
    			'<span class="update-plugins count-%1$s" style="background-color:white;color:black;margin-left:5px;"><span class="plugin-count">%1$s</span></span>',
    			$numPending
    		);
    	}
    }
    add_action( 'admin_menu', 'pending_posts_bubble', 999 );
    
    // http://www.php.net/manual/en/function.array-search.php#91365
    function recursive_array_search_php_91365( $needle, $haystack ) {
        foreach( $haystack as $key => $value ) {
            $current_key = $key;
            if(
                $needle === $value
                OR (
                    is_array( $value )
                    && recursive_array_search_php_91365( $needle, $value ) !== false
                )
            )
            {
                return $current_key;
            }
        }
        return false;
    }

    https://wordpress.org/plugins/new-user-approve/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Howdy_McGee

    (@howdy_mcgee)

    I tried to use a WP_User_Query to get all the pending users but it broke my site (sorta, no image upload (wat?) and an error: Notice: Trying to get property of non-object in /httpdocs/wp-content/plugins/new-user-approve/includes/user-list.php on line 193)

    $userTotal = new WP_User_Query(array('meta_key' => 'pw_user_status', 'meta_value' => 'pending'));

    The function it’s in is a user query filter (filter_by_status( $query )). The code line which it errors out:

    $screen = get_current_screen();
    if ( 'users' != $screen->id ) {
    	return;
    }

    I comment out my query and everything works as expected. Need to make sure $screen isset or is_object() and everything works as expected, but as soon as the plugin updates my change will be lost T-T

    First off, let me thank you for this awesome new feature. I have added the code in github and will put it in the next major release.

    I am working on a minor release to fix the PHP notices.

    And to get the number of pending users you would do this:

    $users = pw_new_user_approve()->get_user_statuses();
    
    // Count Number of Pending Members
    $pending_users = count( $users['pending'] );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get Number of Pending Users’ is closed to new replies.