apply_filters( 'wp_dropdown_users_args', array $query_args, array $parsed_args )

Filters the query arguments for the list of users in the dropdown.


Parameters Parameters

$query_args

(array) The query arguments for get_users().

$parsed_args

(array) The arguments passed to wp_dropdown_users() combined with the defaults.


Top ↑

Source Source

File: wp-includes/user.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
4.4.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Jonathan Goldford

    This filter allows you to set subscribers as authors of blog posts within the admin without giving them additional privileges. Here’s the code:

    add_filter( 'wp_dropdown_users_args', 'add_subscribers_to_dropdown', 10, 2 );
    function add_subscribers_to_dropdown( $query_args, $r ) {
    
        $query_args['who'] = '';
        return $query_args;
    
    }
    
  2. Skip to note 2 content
    Contributed by RiseOfLex88

    In addition to Jonathan’s contribution, you can also expand it further by specifying the role. This is undocumented on wp codex. But does work e.g.

    function wpdocs_add_subscribers_to_dropdown( $query_args, $r ) {
     
    	$query_args['role'] = array('contributor');
    
    	// Unset the 'who' as this defaults to the 'author' role
    	unset( $query_args['who'] );
    
    	return $query_args;
    }
    add_filter( 'wp_dropdown_users_args', 'wpdocs_add_subscribers_to_dropdown', 10, 2 );
    
  3. Skip to note 3 content
    Contributed by pgDarkness

    In addition to RiseOfLex88’s contribution, you can also specify multiple roles.

    function wpdocs_add_subscribers_to_dropdown( $query_args ) {
    
    	// Use this array to specify multiple roles to show in dropdown
        $query_args['role__in'] = array( 'contributor', 'administrator' );
    
    	// Use this array to specify multiple roles to hide in dropdown
        $query_args['role__not_in'] = array( 'editor' );
    
        // Unset the 'who' as this defaults to the 'author' role
        unset( $query_args['who'] );
     
        return $query_args;
    }
    add_filter( 'wp_dropdown_users_args', 'wpdocs_add_subscribers_to_dropdown' );
    

    If you dump variable “$query_args” inside this function, this is what you will get:

    array(10) { 
      ["blog_id"]=> int(1) 
      ["include"]=> string(0) "" 
      ["exclude"]=> string(0) "" 
      ["orderby"]=> string(12) "display_name" 
      ["order"]=> string(3) "ASC" 
      ["who"]=> string(7) "authors" 
      ["role"]=> string(0) "" 
      ["role__in"]=> array(0) { } 
      ["role__not_in"]=> array(0) { } 
      ["fields"]=> array(3) { 
        [0]=> string(2) "ID" 
        [1]=> string(10) "user_login" 
        [2]=> string(12) "display_name" 
      } 
    }
    

You must log in before being able to contribute a note or feedback.