From f409dbd3a67803679e0939f66e5ebd7af58094c6 Mon Sep 17 00:00:00 2001 From: Ian Dunn Date: Tue, 29 Oct 2019 10:08:26 -0700 Subject: [PATCH] XProfile: Return early when no contributors to avoid error. --- plugins/wporg-5ftf/includes/xprofile.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/wporg-5ftf/includes/xprofile.php b/plugins/wporg-5ftf/includes/xprofile.php index 8e22e27..9cc31af 100644 --- a/plugins/wporg-5ftf/includes/xprofile.php +++ b/plugins/wporg-5ftf/includes/xprofile.php @@ -46,14 +46,19 @@ function get_xprofile_contribution_data( array $user_ids ) { * * @param int $pledge_id * - * @return array + * @return array|false */ function get_aggregate_contributor_data_for_pledge( $pledge_id ) { - $contributors = Contributor\get_contributor_user_objects( - // TODO set to 'publish' when finished testing. - Contributor\get_pledge_contributors( $pledge_id, 'pending' ) - ); - $user_ids = wp_list_pluck( $contributors, 'ID' ); + // TODO set to 'publish' when finished testing. + $contributor_posts = Contributor\get_pledge_contributors( $pledge_id, 'pending' ); + + // All of their contributors might have declined the invitation and had their posts deleted. + if ( ! $contributor_posts ) { + return false; + } + + $contributor_users = Contributor\get_contributor_user_objects( $contributor_posts ); + $user_ids = wp_list_pluck( $contributor_users, 'ID' ); $data = get_xprofile_contribution_data( $user_ids );