mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-21 23:11:53 +01:00
Introduce 'has_published_posts'
parameter for WP_User_Query
.
This allows user query results to be limited to those users who have published posts in at least one of the specified post types. Props joehoyle, boonebgorges. Fixes #32250. Built from https://develop.svn.wordpress.org/trunk@32683 git-svn-id: http://core.svn.wordpress.org/trunk@32653 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5e787a900a
commit
6db02371ec
@ -569,6 +569,9 @@ class WP_User_Query {
|
||||
* 'url', 'registered'. Use 'all' for all fields and 'all_with_meta' to
|
||||
* include meta fields. Default 'all'.
|
||||
* @type string $who Type of users to query. Accepts 'authors'. Default empty (all users).
|
||||
* @type bool|array $has_published_posts Pass an array of post types to filter results to users who have
|
||||
* published posts in those post types. `true` is an alias for all
|
||||
* public post types.
|
||||
* }
|
||||
*/
|
||||
public function prepare_query( $query = array() ) {
|
||||
@ -592,7 +595,8 @@ class WP_User_Query {
|
||||
'number' => '',
|
||||
'count_total' => true,
|
||||
'fields' => 'all',
|
||||
'who' => ''
|
||||
'who' => '',
|
||||
'has_published_posts' => null,
|
||||
) );
|
||||
}
|
||||
|
||||
@ -651,6 +655,21 @@ class WP_User_Query {
|
||||
$qv['blog_id'] = $blog_id = 0; // Prevent extra meta query
|
||||
}
|
||||
|
||||
if ( $qv['has_published_posts'] && $blog_id ) {
|
||||
if ( true === $qv['has_published_posts'] ) {
|
||||
$post_types = get_post_types( array( 'public' => true ) );
|
||||
} else {
|
||||
$post_types = (array) $qv['has_published_posts'];
|
||||
}
|
||||
|
||||
foreach ( $post_types as &$post_type ) {
|
||||
$post_type = $wpdb->prepare( '%s', $post_type );
|
||||
}
|
||||
|
||||
$posts_table = $wpdb->get_blog_prefix( $blog_id ) . 'posts';
|
||||
$this->query_where .= " AND $wpdb->users.ID IN ( SELECT DISTINCT $posts_table.post_author FROM $posts_table WHERE $posts_table.post_status = 'publish' AND $posts_table.post_type IN ( " . join( ", ", $post_types ) . " ) )";
|
||||
}
|
||||
|
||||
// Meta query.
|
||||
$this->meta_query = new WP_Meta_Query();
|
||||
$this->meta_query->parse_query_vars( $qv );
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.3-alpha-32682';
|
||||
$wp_version = '4.3-alpha-32683';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user