Skip to content

Commit

Permalink
Merge pull request #429 from addonify/development
Browse files Browse the repository at this point in the history
Fix PHP error and added loader icon on wishlist button
  • Loading branch information
Asok17 authored Jan 26, 2024
2 parents e8002f3 + 6b2e5aa commit 9c9f576
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 101 deletions.
13 changes: 10 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Contributors: addonify
Tags: wishlist, woocommerce wishlist, product wishlist, woocommerce, ecommerce, e-commerce
Requires at least: 5.9
Tested up to: 6.4.0
Stable tag: 2.0.8
Requires at least: 6.3
Tested up to: 6.4.2
Stable tag: 2.0.9
Requires PHP: 7.4
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -140,6 +140,13 @@ You can use this `[addonify_wishlist]` shortcode to display the wishlist table i

== Changelog ==

= 2.0.9 - 26 January, 2024 =

- Fixed: PHP error, `Creation of dynamic property Addonify_Wishlist_Public::$added_to_wishlist_button_label is deprecated`.
- Added: Loading icon to wishlist button while product is added into or removed from the wishlist.
- Tested: WooCommerce version 8.5.2.
- Tested: WordPress version 6.4.2.

= 2.0.8 - 09 November, 2023 =

- Tested: WordPress v6.4.0
Expand Down
7 changes: 4 additions & 3 deletions addonify-wishlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
* Plugin Name: Addonify - WooCommerce Wishlist
* Plugin URI: https://wordpress.org/plugins/addonify-wishlist
* Description: Addonify WooCommerce Wishlist is a light-weight yet powerful tool that adds a wishlist functionality to your e-commerce shop.
* Version: 2.0.8
* Requires at least: 5.9
* Version: 2.0.9
* Requires at least: 6.3
* Tested up to: 6.4.2
* Requires PHP: 7.4
* Author: Addonify
* Author URI: https://www.addonify.com
Expand All @@ -26,7 +27,7 @@
die;
}

define( 'ADDONIFY_WISHLIST_VERSION', '2.0.8' );
define( 'ADDONIFY_WISHLIST_VERSION', '2.0.9' );
define( 'ADDONIFY_WISHLIST_DB_INITIALS', 'addonify_wishlist_' );
define( 'ADDONIFY_WISHLIST_PLUGIN_PATH', dirname( __FILE__ ) );
define( 'ADDONIFY_WISHLIST_PLUGIN_FILE', __FILE__ );
Expand Down
8 changes: 5 additions & 3 deletions includes/addonify-wishlist-database-trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static function get_rows( $fields, $order_by = 'DESC', $limit = false, $o
if ( null === $field_value ) {
$where .= "{$field_id} IS NULL";
} else {
$where .= "{$field_id} = '{$field_value}' ";
$where .= "{$field_id} = '{$field_value}'";
}

if ( $counter < $fields_count ) {
Expand All @@ -158,11 +158,13 @@ public static function get_rows( $fields, $order_by = 'DESC', $limit = false, $o
}
}

$query_statement = "SELECT * FROM {$table_name} {$where} {$order_by_}";

if ( ! empty( $limit_ ) ) {
return $wpdb->get_results( "SELECT * FROM {$table_name} {$where} {$order_by_} {$limit_}" ); //phpcs:ignore
$query_statement = "SELECT * FROM {$table_name} {$where} {$order_by_} {$limit_}";
}

return $wpdb->get_results( "SELECT * FROM {$table_name} {$where} {$order_by_}" ); //phpcs:ignore
return $wpdb->get_results( $query_statement ); //phpcs:ignore
}

/**
Expand Down
6 changes: 2 additions & 4 deletions includes/class-addonify-wishlist-database-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,12 @@ public function migrate_wishlist_data( $user_id = 0 ) {
/**
* Seeding wishlist table.
*
* @param int $user_id WP user ID.
*
* @return int|false Returns wishlist row id on success, false otherwise.
*/
public function seed_wishlist_table( $user_id ) {
public function seed_wishlist_table() {

$insert_data = array(
'user_id' => $user_id,
'user_id' => get_current_user_id(),
'site_url' => get_site_url(),
'wishlist_name' => apply_filters( 'addonify_wishist_default_wishlist_name', esc_html__( 'Default Wishlist', 'addonify-wishlist' ) ),
'wishlist_visibility' => 'private',
Expand Down
148 changes: 85 additions & 63 deletions includes/class-addonify-wishlist-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,47 @@ class Addonify_Wishlist_Handler {
* Wishlist database handler class object.
*
* @access protected
* @var object $wishlist
*
* @var object $database_handler
*/
protected $database_handler;

/**
* Stores this Object instance.
*
* @access protected
* @var array
*
* @var array $instance
*/
protected static $instance;

/**
* Stores current user id.
*
* @access protected
*
* @var int $current_user_id
*/
protected $current_user_id;

/**
* Stores current site url.
*
* @access protected
*
* @var string $current_site_url
*/
protected $current_site_url;

/**
* Stores user's default wishlist ID.
*
* @access protected
*
* @var string $default_wishlist_id
*/
protected $default_wishlist_id;

/**
* Class constructor.
*/
Expand All @@ -38,6 +67,10 @@ public function __construct() {
$this->database_handler = new Addonify_Wishlist_Database_Handler();

$this->maybe_generate_share_key();

$this->current_user_id = get_current_user_id();
$this->current_site_url = get_site_url();
$this->default_wishlist_id = $this->get_default_wishlist_id();
}

/**
Expand All @@ -50,22 +83,21 @@ public static function get_instance() {
if ( ! ( is_array( self::$instance ) && array_key_exists( 'instance', self::$instance ) ) ) {
self::$instance['instance'] = new Addonify_Wishlist_Handler();
}

return self::$instance['instance'];
}

/**
* Get all wishlists data associated to a user.
*
* @since 1.0.0
*
* @param int $user_id User ID.
*/
public function get_user_wishlists_data( $user_id = 0 ) {
public function get_user_wishlists_data() {

$query_results = $this->database_handler->get_rows(
array(
'user_id' => ( ! $user_id ) ? get_current_user_id() : $user_id,
'site_url' => get_site_url(),
'user_id' => $this->current_user_id,
'site_url' => $this->current_site_url,
)
);

Expand Down Expand Up @@ -100,40 +132,28 @@ public function add_to_wishlist( $product_id = 0, $wishlist_id = 0 ) {
return false;
}

if ( ! $wishlist_id ) {
$wishlist_id = $this->get_default_wishlist_id();
if ( 0 === $wishlist_id ) {
$wishlist_id = $this->default_wishlist_id;
}

// If there is no default wishlist set for a user.
if ( ! $wishlist_id ) {
if ( 0 === $wishlist_id ) {
return false;
}

$return_boolean = false;

$user_wishlists = $this->get_user_wishlists();

// If given wishlist exists in the database, then insert the given product into the wishlist.
if ( in_array( (int) $wishlist_id, $user_wishlists, true ) ) {

$current_user_id = get_current_user_id();
$site_url = get_site_url();

$save = array();

$save['user_id'] = $current_user_id;
$save['site_url'] = $site_url;
$save['parent_wishlist_id'] = $wishlist_id;
$save['product_id'] = (int) $product_id;

do_action( 'addonify_wishlist_before_adding_to_wishlist', $save );

$insert_id = $this->database_handler->insert_row( $save );
if ( $insert_id ) {
$return_boolean = true;
}
$insert_id = $this->database_handler->insert_row(
array(
'user_id' => $this->current_user_id,
'site_url' => $this->current_site_url,
'parent_wishlist_id' => $wishlist_id,
'product_id' => (int) $product_id,
)
);

do_action( 'addonify_wishlist_after_adding_to_wishlist', $save );
if ( $insert_id ) {
$return_boolean = true;
}

return $return_boolean;
Expand All @@ -152,8 +172,8 @@ public function remove_from_wishlist( $product_id, $parent_wishlist_id = 0 ) {
return false;
}

if ( ! $parent_wishlist_id ) {
$parent_wishlist_id = $this->get_default_wishlist_id();
if ( 0 === $parent_wishlist_id ) {
$parent_wishlist_id = $this->default_wishlist_id;
}

$wishlist_items = $this->get_wishlist_items( $parent_wishlist_id );
Expand All @@ -164,8 +184,8 @@ public function remove_from_wishlist( $product_id, $parent_wishlist_id = 0 ) {
array(
'parent_wishlist_id' => $parent_wishlist_id,
'product_id' => $product_id,
'user_id' => get_current_user_id(),
'site_url' => get_site_url(),
'user_id' => $this->current_user_id,
'site_url' => $this->current_site_url,
)
);
}
Expand All @@ -176,22 +196,20 @@ public function remove_from_wishlist( $product_id, $parent_wishlist_id = 0 ) {
/**
* Get default wishlist id.
*
* @param int $current_user_id Current user ID.
* @return int|boolean If found, wishlist ID. Else, false.
*/
public function get_default_wishlist_id( $current_user_id = 0 ) {

if ( 0 === $current_user_id ) {
$current_user_id = get_current_user_id();
}
public function get_default_wishlist_id() {

$user_wishlists = $this->get_user_wishlists( $current_user_id );
$user_wishlists = $this->get_wishlists();

if ( ! empty( $user_wishlists ) && isset( $user_wishlists[0] ) ) {
if (
! empty( $user_wishlists ) &&
isset( $user_wishlists[0] )
) {
return (int) $user_wishlists[0];
}

return false;
return 0;
}


Expand All @@ -200,21 +218,24 @@ public function get_default_wishlist_id( $current_user_id = 0 ) {
*
* @since 2.0.6
*
* @param int $user_id User ID.
* @return array|boolean Lists of wishlists if found. Else false.
*/
public function get_user_wishlists( $user_id = 0 ) {
public function get_wishlists() {

$user_wishlists = $this->database_handler->get_rows(
array(
'user_id' => ( ! $user_id ) ? get_current_user_id() : $user_id,
'site_url' => get_site_url(),
'user_id' => $this->current_user_id,
'site_url' => $this->current_site_url,
'parent_wishlist_id' => NULL, // phpcs:ignore
)
);

$wishlist_ids = array();

if ( is_array( $user_wishlists ) && ! empty( $user_wishlists ) ) {
if (
is_array( $user_wishlists ) &&
! empty( $user_wishlists )
) {
foreach ( $user_wishlists as $user_wishlist ) {
$wishlist_ids[] = (int) $user_wishlist->id;
}
Expand All @@ -228,28 +249,29 @@ public function get_user_wishlists( $user_id = 0 ) {
/**
* Get wishlist items.
*
* @param int $wishlist_id Wishlist ID.
* @param int $user_id User ID.
* @param string $site_url Site URL.
* @param int $wishlist_id Wishlist ID.
* @return array Wishlist items.
*/
public function get_wishlist_items( $wishlist_id = 0, $user_id = 0, $site_url = '' ) {
public function get_wishlist_items( $wishlist_id = 0 ) {

if ( ! $wishlist_id ) {
$wishlist_id = $this->get_default_wishlist_id();
if ( 0 === $wishlist_id ) {
$wishlist_id = $this->default_wishlist_id;
}

$wishlist_items = $this->database_handler->get_rows(
array(
'user_id' => ( ! $user_id ) ? get_current_user_id() : $user_id,
'site_url' => ( ! $site_url ) ? get_site_url() : $site_url,
'user_id' => $this->current_user_id,
'site_url' => $this->current_site_url,
'parent_wishlist_id' => $wishlist_id,
)
);

$items = array();

if ( is_array( $wishlist_items ) && ! empty( $wishlist_items ) ) {
if (
is_array( $wishlist_items ) &&
! empty( $wishlist_items )
) {
foreach ( $wishlist_items as $wishlist_item ) {
$items[] = (int) $wishlist_item->product_id;
}
Expand All @@ -266,14 +288,14 @@ public function get_wishlist_items( $wishlist_id = 0, $user_id = 0, $site_url =
*/
public function empty_wishlist( $wishlist_id = 0 ) {

if ( ! $wishlist_id ) {
$wishlist_id = $this->get_default_wishlist_id();
if ( 0 === $wishlist_id ) {
$wishlist_id = $this->default_wishlist_id;
}

$delete_where = array(
'parent_wishlist_id' => $wishlist_id,
'user_id' => get_current_user_id(),
'site_url' => get_site_url(),
'user_id' => $this->current_user_id,
'site_url' => $this->current_site_url,
);

return $this->database_handler->delete_where( $delete_where );
Expand Down
2 changes: 1 addition & 1 deletion public/assets/build/css/addonify-wishlist-public-rtl.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/assets/build/css/addonify-wishlist-public.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/assets/build/css/addonify-wishlist-public.css.map

Large diffs are not rendered by default.

Loading

0 comments on commit 9c9f576

Please sign in to comment.