Make WordPress Core


Ignore:
Timestamp:
12/20/2010 05:25:39 PM (13 years ago)
Author:
ryan
Message:

Add 'who' arg to wp_dropdown_users() and get_users(). Add' hide_if_only_one_author' argument to get_users(). Query only authors (user level greater than 0) when who => author is passed. Query only authors for author meta box and quick edit dropdowns. Props scribu. fixes #15871

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/user.php

    r17084 r17088  
    482482        }
    483483
     484        $blog_id = absint( $qv['blog_id'] );
     485
     486        if ( 'authors' == $qv['who'] && $blog_id ) {
     487            $qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level';
     488            $qv['meta_value'] = '_wp_zero_value'; // Hack to pass '0'
     489            $qv['meta_compare'] = '!=';
     490            $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query
     491        }
     492
    484493        _parse_meta_query( $qv );
    485494
    486495        $role = trim( $qv['role'] );
    487         $blog_id = absint( $qv['blog_id'] );
    488496
    489497        if ( $blog_id && ( $role || is_multisite() ) ) {
     
    930938 * <li>show_option_all - Text to show all and whether HTML option exists.</li>
    931939 * <li>show_option_none - Text for show none and whether HTML option exists.</li>
     940 * <li>hide_if_only_one_author - Don't create the dropdown if there is only one user.</li>
    932941 * <li>orderby - SQL order by clause for what order the users appear. Default is 'display_name'.</li>
    933942 * <li>order - Default is 'ASC'. Can also be 'DESC'.</li>
     
    942951 * <li>class - Class attribute of select element.</li>
    943952 * <li>blog_id - ID of blog (Multisite only). Defaults to ID of current blog.</li>
     953 * <li>who - Which users to query.  Currently only 'authors' is supported. Default is all users.</li>
    944954 * </ol>
    945955 *
     
    951961 */
    952962function wp_dropdown_users( $args = '' ) {
    953     global $wpdb;
    954963    $defaults = array(
    955         'show_option_all' => '', 'show_option_none' => '',
     964        'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '',
    956965        'orderby' => 'display_name', 'order' => 'ASC',
    957966        'include' => '', 'exclude' => '', 'multi' => 0,
    958967        'show' => 'display_name', 'echo' => 1,
    959         'selected' => 0, 'name' => 'user', 'class' => '', 'blog_id' => $GLOBALS['blog_id'],
    960         'id' => '',
     968        'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '',
     969        'blog_id' => $GLOBALS['blog_id'], 'who' => ''
    961970    );
    962971
     
    966975    extract( $r, EXTR_SKIP );
    967976
    968     $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order' ) );
     977    $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
    969978    $query_args['fields'] = array( 'ID', $show );
    970 
    971979    $users = get_users( $query_args );
    972980
    973981    $output = '';
    974     if ( !empty($users) ) {
     982    if ( !empty($users) && ( empty($hide_if_only_one_author) || count($users) > 1 ) ) {
    975983        $name = esc_attr( $name );
    976984        if ( $multi && ! $id )
Note: See TracChangeset for help on using the changeset viewer.