Make WordPress Core

Ticket #15871: levels.15871.diff

File levels.15871.diff, 7.2 KB (added by scribu, 14 years ago)

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-includes/meta.php

     
    386386        $i = 0;
    387387        foreach ( $meta_query as $q ) {
    388388                $meta_key = isset( $q['key'] ) ? trim( $q['key'] ) : '';
    389                 $meta_value = isset( $q['value'] ) ? $q['value'] : '';
     389
    390390                $meta_compare = isset( $q['compare'] ) ? strtoupper( $q['compare'] ) : '=';
    391                 $meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR';
    392 
    393                 if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) )
     391                if ( ! in_array( $meta_compare, array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
    394392                        $meta_compare = '=';
     393                }
    395394
    396                 if ( 'NUMERIC' == $meta_type )
     395                $meta_value = isset( $q['value'] ) ? $q['value'] : '';
     396                if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
     397                        if ( ! is_array( $meta_value ) )
     398                                $meta_value = preg_split( '/[,\s]+/', $meta_value );
     399                } else {
     400                        $meta_value = trim( $meta_value );
     401                }
     402
     403                $no_meta_value = ( '' === $meta_value || ( is_array( $meta_value ) && empty( $meta_value ) ) );
     404
     405                $meta_type = isset( $q['type'] ) ? strtoupper( $q['type'] ) : 'CHAR';
     406                if ( 'NUMERIC' == $meta_type ) {
    397407                        $meta_type = 'SIGNED';
    398                 elseif ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) )
     408                } elseif ( ! in_array( $meta_type, array( 'BINARY', 'CHAR', 'DATE', 'DATETIME', 'DECIMAL', 'SIGNED', 'TIME', 'UNSIGNED' ) ) ) {
    399409                        $meta_type = 'CHAR';
     410                }
    400411
    401                 if ( empty( $meta_key ) && empty( $meta_value ) )
     412                if ( empty( $meta_key ) && $no_meta_value )
    402413                        continue;
    403414
    404415                $alias = $i ? 'mt' . $i : $meta_table;
     
    412423                if ( !empty( $meta_key ) )
    413424                        $where .= $wpdb->prepare( " AND $alias.meta_key = %s", $meta_key );
    414425
    415                 if ( in_array( $meta_compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) {
    416                         if ( ! is_array( $meta_value ) )
    417                                 $meta_value = preg_split( '/[,\s]+/', $meta_value );
    418                 } else {
    419                         $meta_value = trim( $meta_value );
    420                 }
    421 
    422                 if ( empty( $meta_value ) )
     426                if ( $no_meta_value )
    423427                        continue;
    424428
    425429                if ( 'IN' == substr( $meta_compare, -2) ) {
     
    452456
    453457        // Simple query needs to be first for orderby=meta_value to work correctly
    454458        foreach ( array( 'key', 'value', 'compare', 'type' ) as $key ) {
    455                 if ( !empty( $qv[ "meta_$key" ] ) )
     459                if ( isset( $qv[ "meta_$key" ] ) )
    456460                        $meta_query[0][ $key ] = $qv[ "meta_$key" ];
    457461        }
    458462
  • 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_non_subscribers();
     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_non_subscribers(),
    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_non_subscribers() {
     2176        global $wpdb, $blog_id;
     2177
     2178        $args = array(
     2179                'fields' => array( 'ID', 'display_name' ),
     2180                'orderby' => 'display_name',
     2181                'order' => 'ASC'
     2182        );
     2183
     2184        if ( !is_multisite() ) { // super-admins don't have user_levels
     2185                $args = array_merge( $args, array(
     2186                        'meta_key' => $wpdb->get_blog_prefix( $blog_id ) . 'user_level',
     2187                        'meta_value' => '0',
     2188                        'meta_compare' => '!=',
     2189                        'blog_id' => 0, // avoid additional meta query
     2190                ) );
     2191        }
     2192
     2193        return get_users( $args );
     2194}
     2195