use get_users() in get_editable_user_ids() and cache result. See #14572
git-svn-id: https://develop.svn.wordpress.org/trunk@15539 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
072ea8728b
commit
8993abd1be
@ -149,10 +149,11 @@ if ( !( 'pending' == $post->post_status && !current_user_can( $post_type_object-
|
||||
add_meta_box('slugdiv', __('Slug'), 'post_slug_meta_box', $post_type, 'normal', 'core');
|
||||
|
||||
if ( post_type_supports($post_type, 'author') ) {
|
||||
$authors = get_editable_user_ids( $current_user->id ); // TODO: ROLE SYSTEM
|
||||
if ( $post->post_author && !in_array($post->post_author, $authors) )
|
||||
$authors[] = $post->post_author;
|
||||
if ( ( $authors && count( $authors ) > 1 ) || is_super_admin() )
|
||||
$_editable_user_ids = get_editable_user_ids( $current_user->id, true, $post_type ); // TODO: ROLE SYSTEM
|
||||
if ( $post->post_author && !in_array($post->post_author, $_editable_user_ids) )
|
||||
$_editable_user_ids[] = $post->post_author;
|
||||
|
||||
if ( !empty($_editable_user_ids) || is_super_admin() )
|
||||
add_meta_box('authordiv', __('Author'), 'post_author_meta_box', $post_type, 'normal', 'core');
|
||||
}
|
||||
|
||||
|
@ -505,10 +505,8 @@ function post_slug_meta_box($post) {
|
||||
* @param object $post
|
||||
*/
|
||||
function post_author_meta_box($post) {
|
||||
global $user_ID;
|
||||
$authors = get_editable_user_ids( get_current_user_id(), true, $post->post_type ); // TODO: ROLE SYSTEM
|
||||
if ( $post->post_author && !in_array($post->post_author, $authors) )
|
||||
$authors[] = $post->post_author;
|
||||
global $user_ID, $_editable_user_ids;
|
||||
|
||||
?>
|
||||
<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) ); ?>
|
||||
<?php
|
||||
|
@ -240,12 +240,15 @@ function get_editable_authors( $user_id ) {
|
||||
* @since unknown
|
||||
*
|
||||
* @param int $user_id User ID.
|
||||
* @param bool $exclude_zeros Optional, default is true. Whether to exclude zeros.
|
||||
* @return unknown
|
||||
* @param bool $deprecated Not used.
|
||||
* @return array
|
||||
*/
|
||||
function get_editable_user_ids( $user_id, $exclude_zeros = true, $post_type = 'post' ) {
|
||||
function get_editable_user_ids( $user_id, $deprecated = true, $post_type = 'post' ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( !$deprecated )
|
||||
_deprecated_argument( __FUNCTION__, '3.1.0' );
|
||||
|
||||
$user = new WP_User( $user_id );
|
||||
$post_type_obj = get_post_type_object($post_type);
|
||||
|
||||
@ -256,16 +259,7 @@ function get_editable_user_ids( $user_id, $exclude_zeros = true, $post_type = 'p
|
||||
return array();
|
||||
}
|
||||
|
||||
if ( !is_multisite() )
|
||||
$level_key = $wpdb->get_blog_prefix() . 'user_level';
|
||||
else
|
||||
$level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels
|
||||
|
||||
$query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s", $level_key);
|
||||
if ( $exclude_zeros )
|
||||
$query .= " AND meta_value != '0'";
|
||||
|
||||
return $wpdb->get_col( $query );
|
||||
return get_users( array('fields' => 'ids') );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -434,13 +434,14 @@ class WP_User_Query {
|
||||
}
|
||||
|
||||
$role = trim( $qv['role'] );
|
||||
if ( $role ) {
|
||||
|
||||
if ( $role || is_multisite() ) {
|
||||
$this->query_from .= " INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id";
|
||||
$this->query_where .= $wpdb->prepare(" AND $wpdb->usermeta.meta_key = '{$wpdb->prefix}capabilities' AND $wpdb->usermeta.meta_value LIKE %s", '%' . $role . '%');
|
||||
} elseif ( is_multisite() ) {
|
||||
$level_key = $wpdb->prefix . 'capabilities'; // wpmu site admins don't have user_levels
|
||||
$this->query_from .= ", $wpdb->usermeta";
|
||||
$this->query_where .= " AND $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '{$level_key}'";
|
||||
$this->query_where .= $wpdb->prepare( " AND $wpdb->usermeta.meta_key = %s", $wpdb->prefix . 'capabilities' );
|
||||
}
|
||||
|
||||
if ( $role ) {
|
||||
$this->query_where .= $wpdb->prepare( " AND $wpdb->usermeta.meta_value LIKE %s", '%' . like_escape( $role ) . '%' );
|
||||
}
|
||||
|
||||
$meta_key = trim( $qv['meta_key'] );
|
||||
|
Loading…
Reference in New Issue
Block a user