mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-04 10:05:43 +03:00
parent
152964f5cf
commit
fda5842e86
4 changed files with 284 additions and 1 deletions
|
@ -281,7 +281,9 @@ function get_pledge_contributors_data( $pledge_id ) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the user objects that correspond with pledge contributor posts.
|
||||
* Get the user objects that correspond with contributor posts.
|
||||
*
|
||||
* @see `get_contributor_user_ids()` for a similar function.
|
||||
*
|
||||
* @param WP_Post[] $contributor_posts
|
||||
*
|
||||
|
@ -293,6 +295,43 @@ function get_contributor_user_objects( array $contributor_posts ) {
|
|||
}, $contributor_posts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user IDs for the given `CPT_ID` posts.
|
||||
*
|
||||
* This is similar to `get_contributor_user_objects()`, but returns more specific data, and is more performant
|
||||
* with large data sets (e.g., with `get_snapshot_data()`) because there is 1 query instead of
|
||||
* `count( $contributor_posts )`.
|
||||
*
|
||||
* @param WP_Post[] $contributor_posts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_contributor_user_ids( $contributor_posts ) {
|
||||
global $wpdb;
|
||||
|
||||
$usernames = wp_list_pluck( $contributor_posts, 'post_title' );
|
||||
|
||||
/*
|
||||
* Generate placeholders dynamically, so that each username will be quoted individually rather than as a
|
||||
* single string.
|
||||
*
|
||||
* @see https://developer.wordpress.org/reference/classes/wpdb/prepare/#comment-1557
|
||||
*/
|
||||
$usernames_placeholders = implode( ', ', array_fill( 0, count( $usernames ), '%s' ) );
|
||||
|
||||
$query = "
|
||||
SELECT id
|
||||
FROM $wpdb->users
|
||||
WHERE user_login IN( $usernames_placeholders )
|
||||
";
|
||||
|
||||
$user_ids = $wpdb->get_col(
|
||||
$wpdb->prepare( $query, $usernames )
|
||||
);
|
||||
|
||||
return $user_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Only show the My Pledges menu to users who are logged in.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue