Make WordPress Core

Ticket #15871: 15871.3.diff

File 15871.3.diff, 5.5 KB (added by ryan, 14 years ago)
  • wp-includes/user.php

     
    481481                        $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild );
    482482                }
    483483
     484                $blog_id = absint( $qv['blog_id'] );
     485
     486                // @todo This should use get_meta_sql() once it handles 0 as a meta_value. See #15871
     487                if ( 'authors' == $qv['who'] && $blog_id ) {
     488                        $qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level';
     489                        $qv['meta_value'] = '_wp_zero_value'; // Hack to pass '0'
     490                        $qv['meta_compare'] = '!=';
     491                        $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query
     492                }
     493
    484494                _parse_meta_query( $qv );
    485495
    486496                $role = trim( $qv['role'] );
    487                 $blog_id = absint( $qv['blog_id'] );
    488497
    489498                if ( $blog_id && ( $role || is_multisite() ) ) {
    490499                        $cap_meta_query = array();
     
    949958 * <ol>
    950959 * <li>show_option_all - Text to show all and whether HTML option exists.</li>
    951960 * <li>show_option_none - Text for show none and whether HTML option exists.</li>
     961 * <li>show_option_gt_one - Generate the dropdown only if more than one user is listed.</li>
    952962 * <li>orderby - SQL order by clause for what order the users appear. Default is 'display_name'.</li>
    953963 * <li>order - Default is 'ASC'. Can also be 'DESC'.</li>
    954964 * <li>include - User IDs to include.</li>
     
    961971 * <li>id - Default is the value of the 'name' parameter. ID attribute of select element.</li>
    962972 * <li>class - Class attribute of select element.</li>
    963973 * <li>blog_id - ID of blog (Multisite only). Defaults to ID of current blog.</li>
     974 * <li>who - Which users to query.  Currently only 'authors' is supported. Default is all users.</li>
    964975 * </ol>
    965976 *
    966977 * @since 2.3.0
     
    970981 * @return string|null Null on display. String of HTML content on retrieve.
    971982 */
    972983function wp_dropdown_users( $args = '' ) {
    973         global $wpdb;
    974984        $defaults = array(
    975                 'show_option_all' => '', 'show_option_none' => '',
     985                'show_option_all' => '', 'show_option_none' => '', 'show_option_gt_one' => '',
    976986                'orderby' => 'display_name', 'order' => 'ASC',
    977987                'include' => '', 'exclude' => '', 'multi' => 0,
    978988                'show' => 'display_name', 'echo' => 1,
    979                 'selected' => 0, 'name' => 'user', 'class' => '', 'blog_id' => $GLOBALS['blog_id'],
    980                 'id' => '',
     989                'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '',
     990                'blog_id' => $GLOBALS['blog_id'], 'who' => ''
    981991        );
    982992
    983993        $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
     
    985995        $r = wp_parse_args( $args, $defaults );
    986996        extract( $r, EXTR_SKIP );
    987997
    988         $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order' ) );
     998        $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
    989999        $query_args['fields'] = array( 'ID', $show );
    990 
    9911000        $users = get_users( $query_args );
    9921001
    9931002        $output = '';
    994         if ( !empty($users) ) {
     1003        if ( !empty($users) && ( empty($show_option_gt_one) || count($users) > 1 ) ) {
    9951004                $name = esc_attr( $name );
    9961005                if ( $multi && ! $id )
    9971006                        $id = '';
  • wp-includes/meta.php

     
    433433                } else {
    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        }
    438443
  • wp-admin/includes/class-wp-posts-list-table.php

     
    757757                                <?php touch_time( 1, 1, 4, 1 ); ?>
    758758                        </div>
    759759                        <br class="clear" />
    760 
    761760        <?php endif; // $bulk
    762761
    763762                if ( post_type_supports( $screen->post_type, 'author' ) ) :
     
    765764
    766765                        if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) :
    767766                                $users_opt = array(
     767                                        'show_option_gt_one' => true,
     768                                        'who' => 'authors',
    768769                                        'name' => 'post_author',
    769770                                        'class'=> 'authors',
    770771                                        'multi' => 1,
     
    772773                                );
    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        ?>
    781785
  • wp-admin/includes/meta-boxes.php

     
    530530 */
    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
    540540        ) );