From bbeb3f901df32b9126c1b8364f4c3a7604c7e689 Mon Sep 17 00:00:00 2001 From: E2E Environment Date: Mon, 9 Dec 2024 18:14:31 +0100 Subject: [PATCH] Remove magic method and use setter method for user data --- classes/User/User.php | 54 +++++++++++-------------------------------- 1 file changed, 14 insertions(+), 40 deletions(-) diff --git a/classes/User/User.php b/classes/User/User.php index cfc16777..01436210 100755 --- a/classes/User/User.php +++ b/classes/User/User.php @@ -1,7 +1,6 @@ id)) { - return; - } - - $cached_user = get_transient( $this->cache_key ); - - if ( $cached_user ) { - $this->set_user_properties( $cached_user ); - + if ( $this->initialized ) { return; } @@ -162,10 +154,8 @@ public function init_user() { return; } - // Store user data in cache. - set_transient( $this->cache_key, $user, $this->cache_duration ); - $this->set_user_properties( $user ); + $this->initialized = true; } private function set_user_properties( $user ) { @@ -182,27 +172,6 @@ private function set_user_properties( $user ) { $this->is_monthly = $user->is_monthly; } - /** - * A magic call method. - * Added this method to avoid calling init_user for every method in this class. - * The init_user method is lazy call here. - * @param $method - * @param $args - * - */ - public function __call( $method, $args ) { - if( ! $this->initialized ) { - $this->init_user(); - $this->initialized = true; - } - - if ( method_exists( $this, $method ) ) { - return call_user_func_array( [ $this, $method ], $args ); - } - - throw new BadMethodCallException( "Method {$method} does not exist"); - } - /** * Get the possible error returned when fetching user data. * @@ -210,6 +179,8 @@ public function __call( $method, $args ) { * @since 1.9.9 */ public function get_error() { + $this->init_user(); + return $this->error; } @@ -295,6 +266,7 @@ public function get_percent_consumed_quota() { * @return float|int */ public function get_percent_unconsumed_quota() { + $this->init_user(); return 100 - $this->get_percent_consumed_quota(); } @@ -306,6 +278,7 @@ public function get_percent_unconsumed_quota() { * @return bool */ public function is_free() { + $this->init_user(); return 1 === $this->plan_id; } @@ -315,6 +288,7 @@ public function is_free() { * @return bool */ public function is_growth() { + $this->init_user(); return ( 16 === $this->plan_id || 18 === $this->plan_id ); } @@ -324,6 +298,7 @@ public function is_growth() { * @return bool */ public function is_infinite() { + $this->init_user(); return ( 15 === $this->plan_id || 17 === $this->plan_id ); } @@ -349,8 +324,7 @@ public function is_over_quota() { /** * Get user Id - * - */ + */ public function get_id() { $this->init_user();