PluginProbe
Wishlist for WooCommerce / 1.1
Wishlist for WooCommerce v1.1
1.1.7 trunk 1.0.0 1.0.6 1.0.7 1.0.8 1.0.9 1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6
th-wishlist / th-wishlist.php

th-wishlist.php in Wishlist for WooCommerce 1.1, at th-wishlist.php

196 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: TH Wishlist for WooCommerce
4 * Plugin URI: https://themehunk.com/wishlist
5 * Description: TH Wishlist is a powerful and user-friendly wishlist plugin for WooCommerce that lets your customers save their favorite products for later and helps boost conversions by keeping users engaged with the products they love.
6 * Version: 1.1
7 * Author: themehunk
8 * Author URI: https://www.themehunk.com
9 * License: GPLv2 or later
10 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
11 * Text Domain: th-wishlist
12 * Tested up to: 6.8
13 * Requires at least: 5.0
14 * Domain Path: /languages
15 * WC requires at least: 3.0
16 * WC tested up to: 8.9
17 * Requires Plugins: woocommerce
18 */
19
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit; // Exit if accessed directly.
22 }
23
24 /**
25 * Declare compatibility with WooCommerce High-Performance Order Storage (HPOS).
26 */
27 function thwl_hpos_compatibility() {
28 if ( defined( 'THWL_PLUGIN_FILE' ) && class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
29 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', THWL_PLUGIN_FILE, true );
30 }
31 }
32 add_action( 'before_woocommerce_init', 'thwl_hpos_compatibility' );
33
34 if ( ! class_exists( 'THWL_Wishlist' ) ) :
35 /**
36 * Main THWL_Wishlist Class.
37 *
38 * @class THWL_Wishlist
39 */
40 final class THWL_Wishlist {
41
42 /**
43 * @var string Plugin version.
44 */
45 public $version;
46
47 /**
48 * @var THWL_Wishlist The single instance of the class
49 */
50 protected static $_instance = null;
51
52 /**
53 * Main TH_Wishlist Instance.
54 * Ensures only one instance of the class is loaded.
55 */
56 public static function instance() {
57 if ( is_null( self::$_instance ) ) {
58 self::$_instance = new self();
59 }
60 return self::$_instance;
61 }
62
63 /**
64 * TH_Wishlist Constructor.
65 */
66 public function __construct() {
67 $this->thwl_define_constants();
68 $this->thwl_set_version();
69 $this->thwl_includes();
70 $this->thwl_init_hooks();
71 }
72
73 /**
74 * Define Constants.
75 */
76 private function thwl_define_constants() {
77 define( 'THWL_PLUGIN_FILE', __FILE__ );
78 define( 'THWL_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
79 define( 'THWL_VERSION', $this->version );
80 define( 'THWL_DIR', plugin_dir_path( __FILE__ ) );
81 define( 'THWL_URL', plugin_dir_url( __FILE__ ) );
82 }
83
84 /**
85 * Set the plugin version from the plugin header.
86 */
87 private function thwl_set_version() {
88 $plugin_data = get_file_data( __FILE__, array( 'version' => 'version' ), false );
89 $this->version = $plugin_data['version'];
90 }
91
92 /**
93 * Include required core files.
94 */
95 public function thwl_includes() {
96 require_once THWL_DIR . 'includes/admin/class-th-wishlist-list-table.php';
97 require_once THWL_DIR . 'includes/admin/class-th-wishlist-data.php';
98 require_once THWL_DIR . 'includes/admin/class-th-wishlist-admin.php';
99 require_once THWL_DIR . 'includes/admin/class-th-wishlist-install.php';
100 require_once THWL_DIR . 'includes/class-th-wishlist-settings-manager.php';
101 require_once THWL_DIR . 'includes/class-th-wishlist-frontend.php';
102 require_once THWL_DIR . 'includes/th-wishlist-function.php';
103 }
104
105 /**
106 * Hook into actions and filters.
107 */
108 private function thwl_init_hooks() {
109 // Activation hook for installation
110 register_activation_hook( THWL_PLUGIN_FILE, array( 'THWL_Install', 'install' ) );
111
112 // Initialize classes
113 add_action( 'plugins_loaded', array( $this, 'thwl_init' ) );
114
115 // Add plugin action links on init
116 add_action( 'init', array( $this, 'thwl_add_plugin_action_links' ) );
117 }
118
119 /**
120 * Add plugin action links filter on init.
121 */
122 public function thwl_add_plugin_action_links() {
123 add_filter( 'plugin_action_links_' . THWL_PLUGIN_BASENAME, array( $this, 'thwl_wishlist_plugin_action_links' ), 10, 1 );
124 }
125
126 /**
127 * Init plugin when plugins are loaded.
128 */
129 public function thwl_init() {
130 // Move WooCommerce check to init hook
131 add_action( 'init', array( $this, 'thwl_check_woocommerce' ) );
132 }
133
134 /**
135 * Check if WooCommerce is active and set up admin notice if not.
136 */
137 public function thwl_check_woocommerce() {
138 if ( ! class_exists( 'WooCommerce' ) ) {
139 add_action( 'admin_notices', array( $this, 'thwl_woocommerce_missing_notice' ) );
140 return;
141 }
142 // Instantiate classes only if WooCommerce is active
143 THWL_Manager::get_instance();
144 new THWL_Frontend();
145 new THWL_Admin();
146 }
147
148 /**
149 * Add the settings link to the plugin row.
150 *
151 * @param array $links - Links for the plugin
152 * @return array - Links
153 */
154 public function thwl_wishlist_plugin_action_links( $links ) {
155 $settings_page = add_query_arg( array( 'page' => 'thwl-wishlist' ), admin_url( 'admin.php' ) );
156 $settings_link = '<a href="' . esc_url( $settings_page ) . '">' . esc_html__( 'Settings', 'th-wishlist' ) . '</a>';
157 array_unshift( $links, $settings_link );
158 return $links;
159 }
160
161 /**
162 * Displays an admin notice if WooCommerce is not installed or active.
163 */
164 public function thwl_woocommerce_missing_notice() {
165 if ( ! is_admin() ) {
166 return;
167 }
168 ?>
169 <div class="notice notice-error is-dismissible">
170 <p>
171 <?php
172 printf(
173 /* translators: 1: Plugin name, 2: woocommerce link. */
174 esc_html__( '%1$s requires %2$s to be installed and active.', 'th-wishlist' ),
175 esc_html__( 'TH Wishlist', 'th-wishlist' ),
176 '<a href="' . esc_url( 'https://woocommerce.com/' ) . '" target="_blank">' . esc_html__( 'WooCommerce', 'th-wishlist' ) . '</a>'
177 );
178 ?>
179 </p>
180 </div>
181 <?php
182 }
183 }
184
185 endif;
186
187 /**
188 * Main instance of THWL_Wishlist.
189 * Returns the main instance of THW.
190 */
191 function THWL() {
192 return THWL_Wishlist::instance();
193 }
194
195 // Global for backwards compatibility.
196 $GLOBALS['thwl_wishlist'] = THWL();