Plugin: Add helper function for getting contributor user objects

This commit is contained in:
Corey McKrill 2019-10-24 15:31:58 -07:00
parent 9ea44532c2
commit f0cec6e5a9
No known key found for this signature in database
GPG key ID: C2C0746F7BF17E38

View file

@ -3,7 +3,7 @@ namespace WordPressDotOrg\FiveForTheFuture\Contributor;
use WordPressDotOrg\FiveForTheFuture;
use WordPressDotOrg\FiveForTheFuture\Pledge;
use WP_Error, WP_Post;
use WP_Error, WP_Post, WP_User;
defined( 'WPINC' ) || die();
@ -175,3 +175,16 @@ function get_pledge_contributors( $pledge_id, $status = 'publish' ) {
return $posts;
}
/**
* Get the user objects that correspond with pledge contributor posts.
*
* @param WP_Post[] $contributor_posts
*
* @return WP_User[]
*/
function get_contributor_user_objects( array $contributor_posts ) {
return array_map( function( WP_Post $post ) {
return get_user_by( 'login', $post->post_title );
}, $contributor_posts );
}