| 1 |
<?php |
| 2 |
|
| 3 |
namespace RadiusTheme\SB\Modules\WishList; |
| 4 |
|
| 5 |
use RadiusTheme\SB\Helpers\Fns; |
| 6 |
use RadiusTheme\SB\Traits\SingletonTrait; |
| 7 |
|
| 8 |
// Do not allow directly accessing this file. |
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit( 'This script cannot be accessed directly.' ); |
| 11 |
} |
| 12 |
|
| 13 |
final class Wishlist { |
| 14 |
|
| 15 |
const KEY = 'rtsb_wishlist'; |
| 16 |
|
| 17 |
private $wishlist_db_key = 'rtsb_wishlist_db_version'; |
| 18 |
|
| 19 |
private $wishlist_db_version = '1.0.0'; |
| 20 |
|
| 21 |
/** |
| 22 |
* @var array |
| 23 |
*/ |
| 24 |
public $settings = []; |
| 25 |
|
| 26 |
/** |
| 27 |
* SingleTon |
| 28 |
*/ |
| 29 |
use SingletonTrait; |
| 30 |
|
| 31 |
private function __construct() { |
| 32 |
|
| 33 |
if ( ! get_option( $this->wishlist_db_key, '' ) ) { |
| 34 |
add_action( 'wp_loaded', [ $this, 'activate' ] ); |
| 35 |
update_option( $this->wishlist_db_key, $this->wishlist_db_version ); |
| 36 |
} |
| 37 |
|
| 38 |
new WishlistRouteV1(); |
| 39 |
|
| 40 |
WishlistFrontEnd::instance(); |
| 41 |
|
| 42 |
if ( is_user_logged_in() ) { |
| 43 |
$cookie_name = WishlistFns::instance()->get_cookie_name(); |
| 44 |
if ( isset( $_COOKIE[ $cookie_name ] ) && is_array( json_decode( wp_unslash( $_COOKIE[ $cookie_name ] ), true ) ) ) { |
| 45 |
$ids = WishlistFns::instance()->get_wishlist_ids(); |
| 46 |
$product_ids = []; |
| 47 |
foreach ( $ids as $pid ) { |
| 48 |
$product_ids[ $pid ] = $pid; |
| 49 |
} |
| 50 |
WishlistFns::instance()->update_user_wishlist_ids( $product_ids ); |
| 51 |
setcookie( self::KEY, '', time() - 3600, '/' ); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
if ( is_admin() ) { |
| 57 |
WishlistAdmin::instance(); |
| 58 |
} |
| 59 |
|
| 60 |
do_action( 'rtsb/module/wishlist/loaded' ); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Do stuff upon plugin activation |
| 65 |
* |
| 66 |
* @return void |
| 67 |
*/ |
| 68 |
public function activate() { |
| 69 |
( new WishlistInstaller() )->run(); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
} |
| 74 |
|