Make WordPress Core

Changeset 17088


Ignore:
Timestamp:
12/20/2010 05:25:39 PM (16 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

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-posts-list-table.php

    r16992 r17088  
    758758                        </div>
    759759                        <br class="clear" />
    760 
    761760        <?php endif; // $bulk
    762761
     
    766765                        if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) :
    767766                                $users_opt = array(
     767                                        'hide_if_only_one_author' => true,
     768                                        'who' => 'authors',
    768769                                        'name' => 'post_author',
    769770                                        'class'=> 'authors',
     
    773774                                if ( $bulk )
    774775                                        $users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
    775                                 $authors_dropdown  = '<label>';
    776                                 $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
    777                                 $authors_dropdown .= wp_dropdown_users( $users_opt );
    778                                 $authors_dropdown .= '</label>';
     776
     777                                if ( $authors = wp_dropdown_users( $users_opt ) ) :
     778                                        $authors_dropdown  = '<label>';
     779                                        $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
     780                                        $authors_dropdown .= $authors;
     781                                        $authors_dropdown .= '</label>';
     782                                endif;
    779783                        endif; // authors
    780784        ?>
  • trunk/wp-admin/includes/meta-boxes.php

    r17062 r17088  
    531531function post_author_meta_box($post) {
    532532        global $user_ID;
    533 
    534533?>
    535534<label class="screen-reader-text" for="post_author_override"><?php _e('Author'); ?></label>
    536535<?php
    537536        wp_dropdown_users( array(
     537                'who' => 'authors',
    538538                'name' => 'post_author_override',
    539539                'selected' => empty($post->ID) ? $user_ID : $post->post_author
  • trunk/wp-includes/meta.php

    r17009 r17088  
    434434                        $meta_compare_string = '%s';
    435435                }
     436
     437                // @todo Temporary hack to support empty values. Do not use outside of core.
     438                if ( '_wp_zero_value' == $meta_value )
     439                        $meta_value = 0;
     440
    436441                $where .= $wpdb->prepare( " AND CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string}", $meta_value );
    437442        }
  • 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.