From d87cd1743685b0a7ebb70a31bf8f22ee796e810f Mon Sep 17 00:00:00 2001 From: Govinda Sapkota <60061411+ptsl-admin@users.noreply.github.com> Date: Tue, 24 Sep 2024 09:50:15 +0200 Subject: [PATCH 1/4] Update class-lp-cart.php protected __cart_content has no key "items". Hence the remove_item method in LP_Cart never actually worked. Now the remove_item() method of _cart_content takes $cart_id as parameter and removes item if cart_id exists in _cart_content --- inc/cart/class-lp-cart.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/inc/cart/class-lp-cart.php b/inc/cart/class-lp-cart.php index c427497e4..522af8233 100644 --- a/inc/cart/class-lp-cart.php +++ b/inc/cart/class-lp-cart.php @@ -203,24 +203,25 @@ public function add_to_cart( int $item_id = 0, int $quantity = 1, array $item_da /** * Remove an item from cart * - * @param $item_id + * @param $cart_id * * @return bool */ - public function remove_item( $item_id ) { - if ( isset( $this->_cart_content['items'][ $item_id ] ) ) { + public function remove_item( $cart_id ) { + + if ( isset( $this->_cart_content[ $cart_id ] ) ) { + + do_action( 'learn_press_remove_cart_item', $cart_id, $this ); - do_action( 'learn_press_remove_cart_item', $item_id, $this ); + unset( $this->_cart_content[$cart_id] ); - unset( $this->_cart_content['items'][ $item_id ] ); - - do_action( 'learn_press_cart_item_removed', $item_id, $this ); + do_action( 'learn_press_cart_item_removed', $cart_id, $this ); $this->update_session( $this->_cart_content ); return true; } - + return false; } From 819ae9f57e41b0366d16cc3782385503458f4f7a Mon Sep 17 00:00:00 2001 From: Govinda Sapkota <60061411+ptsl-admin@users.noreply.github.com> Date: Thu, 26 Sep 2024 15:41:06 +0200 Subject: [PATCH 2/4] Update class-lp-session-handler.php In cases if customer id is not set then run $this->init() once. It becomes necessary when this function is invoked while doing ajax. While doing ajax $this->_customer_id is always '' which is sorted using ->init() --- inc/class-lp-session-handler.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/inc/class-lp-session-handler.php b/inc/class-lp-session-handler.php index 6c2f89bae..e38eb65ba 100644 --- a/inc/class-lp-session-handler.php +++ b/inc/class-lp-session-handler.php @@ -383,6 +383,11 @@ public function get( string $key, $default = null ) { * @param bool $force_change */ public function set( string $key, $value, bool $force_change = false ) { + // if customer id is not set then run $this->init() once. It is necessary when this function is invoked while doing ajax. While doing ajax $this->_customer_id is always '' + if (strlen( $this->_customer_id ) ===0 ) { + $this->init(); + } + $this->_data[ sanitize_key( $key ) ] = maybe_serialize( $value ); if ( $force_change ) { From f4a9ff28695b593aaec1a8492a3d2d6e17cafe1e Mon Sep 17 00:00:00 2001 From: Govinda Sapkota <60061411+ptsl-admin@users.noreply.github.com> Date: Tue, 1 Oct 2024 23:23:33 +0200 Subject: [PATCH 3/4] Update abstract-lp-user.php the $src_only argument was not being used to get the profile picture URL only --- inc/user/abstract-lp-user.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/user/abstract-lp-user.php b/inc/user/abstract-lp-user.php index 72201a5f8..980490a6e 100644 --- a/inc/user/abstract-lp-user.php +++ b/inc/user/abstract-lp-user.php @@ -1236,8 +1236,8 @@ public function get_upload_profile_src( $size = '' ) { * * @return false|string */ - public function get_profile_picture( $type = '', $size = 96, $src_only = false ) { - return LP_Profile::instance( $this->get_id() )->get_profile_picture( $type, $size ); + public function get_profile_picture( $src_only = false, $type = '', $size = 96 ) { + return LP_Profile::instance( $this->get_id() )->get_profile_picture( $src_only, $type, $size ); } /** From f7fea0fe5b1360c68f8b62779f01c32410e7432d Mon Sep 17 00:00:00 2001 From: Govinda Sapkota <60061411+ptsl-admin@users.noreply.github.com> Date: Tue, 1 Oct 2024 23:25:42 +0200 Subject: [PATCH 4/4] Update class-lp-profile.php the $src_only argument was not being used to get the profile picture URL only --- inc/user/class-lp-profile.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/inc/user/class-lp-profile.php b/inc/user/class-lp-profile.php index 60769a557..d3c6dea0b 100644 --- a/inc/user/class-lp-profile.php +++ b/inc/user/class-lp-profile.php @@ -892,7 +892,7 @@ public function get_upload_profile_src( $size = '' ) { * * @return string */ - public function get_profile_picture( $type = '', $size = 96 ): string { + public function get_profile_picture($src_only = false, $type = '', $size = 96 ): string { $avatar = ''; try { @@ -915,18 +915,24 @@ public function get_profile_picture( $type = '', $size = 96 ): string { } } - $avatar = apply_filters( - 'learn-press/user-profile/avatar', - sprintf( - '%s', - esc_attr__( 'User Avatar', 'learnpress' ), + if ( $src_only ) { + $avatar = $avatar_url; + } + + else { + $avatar = apply_filters( + 'learn-press/user-profile/avatar', + sprintf( + '%s', + esc_attr__( 'User Avatar', 'learnpress' ), + $avatar_url, + $args['width'] ?? 96, + $args['height'] ?? 96 + ), $avatar_url, - $args['width'] ?? 96, - $args['height'] ?? 96 - ), - $avatar_url, - $args - ); + $args + ); + } } catch ( Throwable $e ) { error_log( $e->getMessage() ); }