WordPress.org

Make WordPress Core

Changeset 15539


Ignore:
Timestamp:
08/27/2010 12:18:57 AM (10 years ago)
Author:
scribu
Message:

use get_users() in get_editable_user_ids() and cache result. See #14572

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-form-advanced.php

    r15183 r15539  
    150150
    151151if ( post_type_supports($post_type, 'author') ) {
    152     $authors = get_editable_user_ids( $current_user->id ); // TODO: ROLE SYSTEM
    153     if ( $post->post_author && !in_array($post->post_author, $authors) )
    154         $authors[] = $post->post_author;
    155     if ( ( $authors && count( $authors ) > 1 ) || is_super_admin() )
     152    $_editable_user_ids = get_editable_user_ids( $current_user->id, true, $post_type ); // TODO: ROLE SYSTEM
     153    if ( $post->post_author && !in_array($post->post_author, $_editable_user_ids) )
     154        $_editable_user_ids[] = $post->post_author;
     155
     156    if ( !empty($_editable_user_ids) || is_super_admin() )
    156157        add_meta_box('authordiv', __('Author'), 'post_author_meta_box', $post_type, 'normal', 'core');
    157158}
  • trunk/wp-admin/includes/meta-boxes.php

    r15528 r15539  
    506506 */
    507507function post_author_meta_box($post) {
    508     global $user_ID;
    509     $authors = get_editable_user_ids( get_current_user_id(), true, $post->post_type ); // TODO: ROLE SYSTEM
    510     if ( $post->post_author && !in_array($post->post_author, $authors) )
    511         $authors[] = $post->post_author;
     508    global $user_ID, $_editable_user_ids;
     509
    512510?>
    513511<label class="screen-reader-text" for="post_author_override"><?php _e('Author'); ?></label><?php wp_dropdown_users( array('include' => $authors, 'name' => 'post_author_override', 'selected' => empty($post->ID) ? $user_ID : $post->post_author) ); ?>
  • trunk/wp-admin/includes/user.php

    r15491 r15539  
    241241 *
    242242 * @param int $user_id User ID.
    243  * @param bool $exclude_zeros Optional, default is true. Whether to exclude zeros.
    244  * @return unknown
    245  */
    246 function get_editable_user_ids( $user_id, $exclude_zeros = true, $post_type = 'post' ) {
    247     global $wpdb;
     243 * @param bool $deprecated Not used.
     244 * @return array
     245 */
     246function get_editable_user_ids( $user_id, $deprecated = true, $post_type = 'post' ) {
     247    global $wpdb;
     248
     249    if ( !$deprecated )
     250        _deprecated_argument( __FUNCTION__, '3.1.0' );
    248251
    249252    $user = new WP_User( $user_id );
     
    257260    }
    258261
    259     if ( !is_multisite() )
    260         $level_key = $wpdb->get_blog_prefix() . 'user_level';
    261     else
    262         $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels
    263 
    264     $query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s", $level_key);
    265     if ( $exclude_zeros )
    266         $query .= " AND meta_value != '0'";
    267 
    268     return $wpdb->get_col( $query );
     262    return get_users( array('fields' => 'ids') );
    269263}
    270264
  • trunk/wp-includes/user.php

    r15491 r15539  
    435435
    436436        $role = trim( $qv['role'] );
     437
     438        if ( $role || is_multisite() ) {
     439            $this->query_from .= " INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id";
     440            $this->query_where .= $wpdb->prepare( " AND $wpdb->usermeta.meta_key = %s", $wpdb->prefix . 'capabilities' );
     441        }
     442
    437443        if ( $role ) {
    438             $this->query_from .= " INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id";
    439             $this->query_where .= $wpdb->prepare(" AND $wpdb->usermeta.meta_key = '{$wpdb->prefix}capabilities' AND $wpdb->usermeta.meta_value LIKE %s", '%' . $role . '%');
    440         } elseif ( is_multisite() ) {
    441             $level_key = $wpdb->prefix . 'capabilities'; // wpmu site admins don't have user_levels
    442             $this->query_from .= ", $wpdb->usermeta";
    443             $this->query_where .= " AND $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '{$level_key}'";
     444            $this->query_where .= $wpdb->prepare( " AND $wpdb->usermeta.meta_value LIKE %s", '%' . like_escape( $role ) . '%' );
    444445        }
    445446
Note: See TracChangeset for help on using the changeset viewer.