From f756e2663741d40871fcff51724d484bff82db9e Mon Sep 17 00:00:00 2001 From: Evan Mullins Date: Tue, 26 Jul 2022 15:27:32 -0400 Subject: [PATCH] get username form plan object if it exists also separate plan values into their own assignments --- includes/Customer.php | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/includes/Customer.php b/includes/Customer.php index 4cb3cf6..1d5cdc2 100644 --- a/includes/Customer.php +++ b/includes/Customer.php @@ -22,7 +22,7 @@ public static function collect() { $guapi = self::get_account_info(); $mole = array( 'meta' => self::get_onboarding_info() ); $bh_cdata = array_merge( $guapi, $mole ); - Transient::set( 'bh_cdata', $bh_cdata, WEEK_IN_SECONDS ); + Transient::set( 'bh_cdata', $bh_cdata, WEEK_IN_SECONDS ); } return $bh_cdata; @@ -105,19 +105,27 @@ public static function get_account_info(){ } - if ( - isset( $response->plan ) && - is_object( $response->plan ) && + if ( isset( $response->plan ) && is_object( $response->plan ) ) { + // using property_exists in case of null value - property_exists( $response->plan, 'term' ) && - property_exists( $response->plan, 'type' ) && - property_exists( $response->plan, 'subtype' ) - ) { - $info['plan_term'] = $response->plan->term; - $info['plan_type'] = $response->plan->type; - $info['plan_subtype'] = $response->plan->subtype; + if ( property_exists( $response->plan, 'term' ) { + $info['plan_term'] = $response->plan->term; + } + + if ( property_exists( $response->plan, 'type' ) ) { + $info['plan_type'] = $response->plan->type; + } + + if ( property_exists( $response->plan, 'subtype' ) ) { + $info['plan_subtype'] = $response->plan->subtype; + } + + if ( property_exists( $response->plan, 'username' ) ) { + $info['username'] = $response->plan->username; + } + } - + return $info; }