diff --git a/wp-admin/includes/class-wp-posts-list-table.php b/wp-admin/includes/class-wp-posts-list-table.php index 3782ba61b..ca59392b6 100644 --- a/wp-admin/includes/class-wp-posts-list-table.php +++ b/wp-admin/includes/class-wp-posts-list-table.php @@ -757,7 +757,6 @@ class WP_Posts_List_Table extends WP_List_Table {
- post_type, 'author' ) ) : @@ -765,6 +764,8 @@ class WP_Posts_List_Table extends WP_List_Table { if ( is_super_admin() || current_user_can( $post_type_object->cap->edit_others_posts ) ) : $users_opt = array( + 'hide_if_only_one_author' => true, + 'who' => 'authors', 'name' => 'post_author', 'class'=> 'authors', 'multi' => 1, @@ -772,10 +773,13 @@ class WP_Posts_List_Table extends WP_List_Table { ); if ( $bulk ) $users_opt['show_option_none'] = __( '— No Change —' ); - $authors_dropdown = ''; + + if ( $authors = wp_dropdown_users( $users_opt ) ) : + $authors_dropdown = ''; + endif; endif; // authors ?> diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php index 96466b574..f7fcc9604 100644 --- a/wp-admin/includes/meta-boxes.php +++ b/wp-admin/includes/meta-boxes.php @@ -530,11 +530,11 @@ function post_slug_meta_box($post) { */ function post_author_meta_box($post) { global $user_ID; - ?> 'authors', 'name' => 'post_author_override', 'selected' => empty($post->ID) ? $user_ID : $post->post_author ) ); diff --git a/wp-includes/meta.php b/wp-includes/meta.php index ca243da11..cfbaf20d7 100644 --- a/wp-includes/meta.php +++ b/wp-includes/meta.php @@ -433,6 +433,11 @@ function get_meta_sql( $meta_query, $meta_type, $primary_table, $primary_id_colu } else { $meta_compare_string = '%s'; } + + // @todo Temporary hack to support empty values. Do not use outside of core. + if ( '_wp_zero_value' == $meta_value ) + $meta_value = 0; + $where .= $wpdb->prepare( " AND CAST($alias.meta_value AS {$meta_type}) {$meta_compare} {$meta_compare_string}", $meta_value ); } diff --git a/wp-includes/user.php b/wp-includes/user.php index aab7a51a8..4d7ea4a2c 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -481,10 +481,18 @@ class WP_User_Query { $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild ); } + $blog_id = absint( $qv['blog_id'] ); + + if ( 'authors' == $qv['who'] && $blog_id ) { + $qv['meta_key'] = $wpdb->get_blog_prefix( $blog_id ) . 'user_level'; + $qv['meta_value'] = '_wp_zero_value'; // Hack to pass '0' + $qv['meta_compare'] = '!='; + $qv['blog_id'] = $blog_id = 0; // Prevent extra meta query + } + _parse_meta_query( $qv ); $role = trim( $qv['role'] ); - $blog_id = absint( $qv['blog_id'] ); if ( $blog_id && ( $role || is_multisite() ) ) { $cap_meta_query = array(); @@ -929,6 +937,7 @@ function setup_userdata($for_user_id = '') { *
    *
  1. show_option_all - Text to show all and whether HTML option exists.
  2. *
  3. show_option_none - Text for show none and whether HTML option exists.
  4. + *
  5. hide_if_only_one_author - Don't create the dropdown if there is only one user.
  6. *
  7. orderby - SQL order by clause for what order the users appear. Default is 'display_name'.
  8. *
  9. order - Default is 'ASC'. Can also be 'DESC'.
  10. *
  11. include - User IDs to include.
  12. @@ -941,6 +950,7 @@ function setup_userdata($for_user_id = '') { *
  13. id - Default is the value of the 'name' parameter. ID attribute of select element.
  14. *
  15. class - Class attribute of select element.
  16. *
  17. blog_id - ID of blog (Multisite only). Defaults to ID of current blog.
  18. + *
  19. who - Which users to query. Currently only 'authors' is supported. Default is all users.
  20. *
* * @since 2.3.0 @@ -950,14 +960,13 @@ function setup_userdata($for_user_id = '') { * @return string|null Null on display. String of HTML content on retrieve. */ function wp_dropdown_users( $args = '' ) { - global $wpdb; $defaults = array( - 'show_option_all' => '', 'show_option_none' => '', + 'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '', 'orderby' => 'display_name', 'order' => 'ASC', 'include' => '', 'exclude' => '', 'multi' => 0, 'show' => 'display_name', 'echo' => 1, - 'selected' => 0, 'name' => 'user', 'class' => '', 'blog_id' => $GLOBALS['blog_id'], - 'id' => '', + 'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '', + 'blog_id' => $GLOBALS['blog_id'], 'who' => '' ); $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0; @@ -965,13 +974,12 @@ function wp_dropdown_users( $args = '' ) { $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); - $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order' ) ); + $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) ); $query_args['fields'] = array( 'ID', $show ); - $users = get_users( $query_args ); $output = ''; - if ( !empty($users) ) { + if ( !empty($users) && ( empty($hide_if_only_one_author) || count($users) > 1 ) ) { $name = esc_attr( $name ); if ( $multi && ! $id ) $id = '';