| @@ -22,13 +22,28 @@ | ||
| 22 | 22 | * Hook module initialization. |
| 23 | 23 | */ |
| 24 | 24 | public function __construct() |
| 25 | 25 | { |
| 26 | + add_action('send_headers', [$this, 'maybe_expire_cookie']); | |
| 26 | 27 | add_action('init', [$this, 'boot']); |
| 27 | 28 | add_action('wp_login', [$this, 'handle_login'], 10, 2); |
| 28 | 29 | } |
| 29 | 30 | |
| 30 | 31 | /** |
| 32 | + * Drop leftover guest cookies when wishlist is turned off in settings. | |
| 33 | + * | |
| 34 | + * @return void | |
| 35 | + */ | |
| 36 | + public function maybe_expire_cookie(): void | |
| 37 | + { | |
| 38 | + if (Wishlist_Settings::is_enabled() || is_admin()) { | |
| 39 | + return; | |
| 40 | + } | |
| 41 | + | |
| 42 | + Wishlist_Session::expire_if_present(); | |
| 43 | + } | |
| 44 | + | |
| 45 | + /** | |
| 31 | 46 | * Initialize wishlist module on init. |
| 32 | 47 | * |
| 33 | 48 | * @return void |
| 34 | 49 | */ |
| @@ -34,8 +49,9 @@ | ||
| 34 | 49 | */ |
| 35 | 50 | public function boot(): void |
| 36 | 51 | { |
| 37 | 52 | Wishlist_DB::maybe_create_tables(); |
| 53 | + Wishlist_Settings::maybe_disable_archive_buttons(); | |
| 38 | 54 | $this->service = new Wishlist_Service(); |
| 39 | 55 | $this->renderer = new Wishlist_Renderer($this->service); |
| 40 | 56 | $this->woocommerce = new Wishlist_WooCommerce($this->service, $this->renderer); |
| 41 | 57 | $this->woocommerce->hooks(); |
| @@ -58,10 +74,17 @@ | ||
| 58 | 74 | * @return void |
| 59 | 75 | */ |
| 60 | 76 | public function handle_login(string $user_login, WP_User $user): void |
| 61 | 77 | { |
| 78 | + if (!Wishlist_Settings::is_enabled()) { | |
| 79 | + return; | |
| 80 | + } | |
| 81 | + | |
| 62 | 82 | $session = new Wishlist_Session(); |
| 63 | - $session_key = $session->get_session_key(); | |
| 83 | + $session_key = $session->get_session_key(false); | |
| 84 | + if ($session_key === '') { | |
| 85 | + return; | |
| 86 | + } | |
| 64 | 87 | |
| 65 | 88 | $service = new Wishlist_Service($user->ID, $session_key); |
| 66 | 89 | $service->merge_guest_items($user->ID, $session_key); |
| 67 | 90 | } |