Skip to content

Commit

Permalink
Fix bug where a warning was being generated by a missing cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-sg-pacheco committed Mar 20, 2017
1 parent fb7faa4 commit 127505f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
15 changes: 11 additions & 4 deletions includes/class-alg-wc-wish-list-cookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Wish List for WooCommerce - Cookies
*
* @version 1.1.5
* @version 1.2.1
* @since 1.1.5
* @author Algoritmika Ltd.
*/
Expand All @@ -22,15 +22,21 @@ class Alg_WC_Wish_List_Cookies {
*/
const VAR_UNLOGGED_USER_ID = 'alg-wc-wl-user-id';

public static $unlogged_user_id = '';

/**
* Gets the user id from unlogged user
*
* @version 1.1.6
* @version 1.2.1
* @since 1.1.5
* @return array|mixed|object
*/
public static function get_unlogged_user_id( $create_if_empty = true ) {
$user_id = isset( $_COOKIE[ self::VAR_UNLOGGED_USER_ID ] ) ? $_COOKIE[ self::VAR_UNLOGGED_USER_ID ] : '';
if(empty(self::$unlogged_user_id)){
$user_id = isset( $_COOKIE[ self::VAR_UNLOGGED_USER_ID ] ) ? $_COOKIE[ self::VAR_UNLOGGED_USER_ID ] : '';
}else{
$user_id = self::$unlogged_user_id;
}

if ( empty( $user_id ) ) {
if ( $create_if_empty ) {
Expand All @@ -45,13 +51,14 @@ public static function get_unlogged_user_id( $create_if_empty = true ) {
/**
* Sets the user id from unlogged user
*
* @version 1.1.5
* @version 1.2.1
* @since 1.1.5
*
* @param $user_id
* @param int $timeout
*/
public static function set_user_id( $user_id, $timeout = 1 ) {
self::$unlogged_user_id = $user_id;
setcookie( self::VAR_UNLOGGED_USER_ID, $user_id, time() + ( $timeout * DAY_IN_SECONDS ), COOKIEPATH, COOKIE_DOMAIN );
}

Expand Down
9 changes: 6 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: algoritmika,karzin,anbinder
Tags: woocommerce,wishlist,wish list
Requires at least: 4.4
Tested up to: 4.7
Stable tag: 1.2.0
Stable tag: 1.2.1
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -71,6 +71,9 @@ http://coder.fm/item/wish-list-woocommerce/

== Changelog ==

= 1.2.1 - 20/03/2017 =
* Fix bug where a warning was being generated by a missing cookie

= 1.2.0 - 14/03/2017 =
* Fix German translation
* Improve thumb button position
Expand Down Expand Up @@ -144,5 +147,5 @@ http://coder.fm/item/wish-list-woocommerce/

== Upgrade Notice ==

= 1.2.0 - 14/03/2017 =
Improve thumb position, fix German translation and other minor improvements
= 1.2.1 =
* Fix bug where a warning was being generated by a missing cookie
2 changes: 1 addition & 1 deletion wish-list-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
Plugin Name: Wish List for WooCommerce
Description: Let your visitors save and share the products they love on your WooCommerce store with a Wish List.
Version: 1.2.0
Version: 1.2.1
Author: Algoritmika Ltd
Copyright: © 2017 Algoritmika Ltd.
License: GNU General Public License v3.0
Expand Down

0 comments on commit 127505f

Please sign in to comment.