Browse: Home / Snippets /

ProPanel: Remove user role from Overview student count widget

Contents


Snippet #

Important: All snippets are provided as-is without support or guarantees. These snippets are provided as guidelines for advanced users looking to customize LearnDash. For any additional help or support with these snippets, we recommend reaching out to a LearnDash Expert.

/**
 * LD Propanel - Filter for the Overview widget student count
 *
 * @since v2.0.1
 *
 * @param array $user_query_args An array of elements to be passed into WP_User_Query 
 * @return array $user_query_args modified array.
 */
add_filter( 'ld_propanel_overview_students_count_args', function( $user_query_args = array() ) { 

	// For admin users only - We want to exclude 'group_leader' roles from the user search results.
	if ( learndash_is_admin_user() ) {
	
		// Ensure we have the 'role__not_in' array element. And it is an array.
		if ( !array_key_exists('role__not_in', $user_query_args ) ) {
			$user_query_args['role__not_in'] = array();
		}

		// Check the 'group_leader' role is not already present in the element values. 
		if ( !in_array( 'group_leader', $user_query_args['role__not_in'] ) ) {
			$user_query_args['role__not_in'][] = 'group_leader';
		}
	}

	// always return the $user_query_args array
	return $user_query_args;
}, 10, 1 );