Make WordPress Core

Ticket #15871: levels.15871.2.diff

File levels.15871.2.diff, 4.6 KB (added by scribu, 14 years ago)

Direct query for user_level != 0

  • wp-includes/user.php

     
    961961 * <li>id - Default is the value of the 'name' parameter. ID attribute of select element.</li>
    962962 * <li>class - Class attribute of select element.</li>
    963963 * <li>blog_id - ID of blog (Multisite only). Defaults to ID of current blog.</li>
     964 * <li>users - Raw array of users.</li>
    964965 * </ol>
    965966 *
    966967 * @since 2.3.0
     
    970971 * @return string|null Null on display. String of HTML content on retrieve.
    971972 */
    972973function wp_dropdown_users( $args = '' ) {
    973         global $wpdb;
    974974        $defaults = array(
    975975                'show_option_all' => '', 'show_option_none' => '',
    976976                'orderby' => 'display_name', 'order' => 'ASC',
    977977                'include' => '', 'exclude' => '', 'multi' => 0,
    978978                'show' => 'display_name', 'echo' => 1,
    979                 'selected' => 0, 'name' => 'user', 'class' => '', 'blog_id' => $GLOBALS['blog_id'],
    980                 'id' => '',
     979                'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '',
     980                'blog_id' => $GLOBALS['blog_id'], 'users' => null
    981981        );
    982982
    983983        $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
     
    985985        $r = wp_parse_args( $args, $defaults );
    986986        extract( $r, EXTR_SKIP );
    987987
    988         $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order' ) );
    989         $query_args['fields'] = array( 'ID', $show );
     988        if ( is_null( $users ) ) {
     989                $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order' ) );
     990                $query_args['fields'] = array( 'ID', $show );
     991                $users = get_users( $query_args );
     992        }
    990993
    991         $users = get_users( $query_args );
    992 
    993994        $output = '';
    994995        if ( !empty($users) ) {
    995996                $name = esc_attr( $name );
  • 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' ) ) :
    764763                        $authors_dropdown = '';
    765764
    766765                        if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) :
    767                                 $users_opt = array(
    768                                         'name' => 'post_author',
    769                                         'class'=> 'authors',
    770                                         'multi' => 1,
    771                                         'echo' => 0
    772                                 );
    773                                 if ( $bulk )
    774                                         $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>';
     766                                $users = _get_potential_authors();
     767
     768                                if ( count( $users ) > 1 ) :   
     769                                        $users_opt = array(
     770                                                'users' => $users,
     771                                                'name' => 'post_author',
     772                                                'class'=> 'authors',
     773                                                'multi' => 1,
     774                                                'echo' => 0
     775                                        );
     776                                        if ( $bulk )
     777                                                $users_opt['show_option_none'] = __( '&mdash; No Change &mdash;' );
     778                                        $authors_dropdown  = '<label>';
     779                                        $authors_dropdown .= '<span class="title">' . __( 'Author' ) . '</span>';
     780                                        $authors_dropdown .= wp_dropdown_users( $users_opt );
     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                'users' => _get_potential_authors(),
    538538                'name' => 'post_author_override',
    539539                'selected' => empty($post->ID) ? $user_ID : $post->post_author
    540540        ) );
  • wp-admin/includes/template.php

     
    21712171        return $button;
    21722172}
    21732173
     2174// Get list of users for the author metabox and quick edit dropdowns
     2175function _get_potential_authors() {
     2176        global $wpdb, $blog_id;
     2177
     2178        return $wpdb->get_results("
     2179                SELECT ID, display_name FROM $wpdb->users
     2180                INNER JOIN $wpdb->usermeta ON ($wpdb->users.ID = $wpdb->usermeta.user_id)
     2181                WHERE $wpdb->usermeta.meta_key = '" . $wpdb->get_blog_prefix( $blog_id ) . "user_level'
     2182                AND $wpdb->usermeta.meta_value != '0'
     2183                ORDER BY display_name ASC
     2184        ");
     2185}
     2186