From 4bd7ea9beedcdc7aed69878fa22764e991557735 Mon Sep 17 00:00:00 2001 From: Andrew Lima Date: Wed, 19 Oct 2022 15:48:51 +0200 Subject: [PATCH] Fix warning in admin * Fixes an issue in the admin when the $pmpro_membership_card_user is empty. --- pmpro-membership-card.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pmpro-membership-card.php b/pmpro-membership-card.php index 5b28dd6..6d2d974 100644 --- a/pmpro-membership-card.php +++ b/pmpro-membership-card.php @@ -313,6 +313,12 @@ function pmpro_membership_card_return_user_name( $pmpro_membership_card_user ){ * Returns the members most distant expiration date for their memberships. */ function pmpro_membership_card_return_end_date( $pmpro_membership_card_user ){ + + // Make sure the user exists. + if ( empty( $pmpro_membership_card_user ) ) { + return __( 'Never', 'pmpro-membership-card' ); + } + $furthest_enddate = null; foreach ( $pmpro_membership_card_user->membership_levels as $level ) { if ( $furthest_enddate == null || $level->enddate > $furthest_enddate ) { @@ -333,6 +339,12 @@ function pmpro_membership_card_return_end_date( $pmpro_membership_card_user ){ * @param object $pmpro_membership_card_user The membership user. */ function pmpro_membership_card_output_levels_for_user( $pmpro_membership_card_user ) { + + // Make sure the user exists. + if ( empty( $pmpro_membership_car_user ) ) { + return esc_html_e( 'None', 'pmpro-membership-card' ); + } + // Get the user's current levels. $levels = $pmpro_membership_card_user->membership_levels; if ( empty( $levels ) ) {