From f0cec6e5a9d90bd362e18c42f5612122991e6263 Mon Sep 17 00:00:00 2001 From: Corey McKrill <916023+coreymckrill@users.noreply.github.com> Date: Thu, 24 Oct 2019 15:31:58 -0700 Subject: [PATCH] Plugin: Add helper function for getting contributor user objects --- plugins/wporg-5ftf/includes/contributor.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/wporg-5ftf/includes/contributor.php b/plugins/wporg-5ftf/includes/contributor.php index 2bb5099..d55ddfb 100644 --- a/plugins/wporg-5ftf/includes/contributor.php +++ b/plugins/wporg-5ftf/includes/contributor.php @@ -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 ); +}