PluginProbe
Wishlist for WooCommerce / trunk
Wishlist for WooCommerce vtrunk
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 trunk, at th-wishlist.php

299 lines 8.2 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
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: 7.0
13 * Requires at least: 5.0
14 * Domain Path: /languages
15 * WC requires at least: 3.0
16 * WC tested up to: 10.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 /**
37 * Main THWL_Wishlist Class.
38 */
39 final class THWL_Wishlist {
40
41 /**
42 * @var string Plugin version.
43 */
44 public $version;
45
46 /**
47 * @var THWL_Wishlist The single instance of the class.
48 */
49 protected static $_instance = null;
50
51 /**
52 * Main Instance.
53 */
54 public static function instance() {
55 if ( is_null( self::$_instance ) ) {
56 self::$_instance = new self();
57 }
58 return self::$_instance;
59 }
60
61 /**
62 * Constructor.
63 */
64 public function __construct() {
65 $this->thwl_define_constants();
66 $this->thwl_set_version();
67 $this->thwl_includes();
68 $this->thwl_init_hooks();
69
70 // Ensure install runs if demo import skipped activation.
71 add_action( 'init', array( $this, 'thwl_maybe_run_install' ) );
72 }
73
74 /**
75 * Define constants.
76 */
77 private function thwl_define_constants() {
78 define( 'THWL_PLUGIN_FILE', __FILE__ );
79 define( 'THWL_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
80 define( 'THWL_VERSION', $this->version );
81 define( 'THWL_DIR', plugin_dir_path( __FILE__ ) );
82 define( 'THWL_URL', plugin_dir_url( __FILE__ ) );
83 }
84
85 /**
86 * Set plugin version.
87 */
88 private function thwl_set_version() {
89 $plugin_data = get_file_data( __FILE__, array( 'version' => 'version' ), false );
90 $this->version = $plugin_data['version'];
91 }
92
93 /**
94 * Include core files.
95 */
96 public function thwl_includes() {
97 require_once THWL_DIR . 'pricing.php';
98 require_once THWL_DIR . 'includes/admin/class-th-wishlist-list-table.php';
99 require_once THWL_DIR . 'includes/admin/class-th-wishlist-data.php';
100 require_once THWL_DIR . 'includes/admin/class-th-wishlist-admin.php';
101 require_once THWL_DIR . 'includes/admin/class-th-wishlist-install.php';
102 require_once THWL_DIR . 'includes/class-th-wishlist-settings-manager.php';
103 require_once THWL_DIR . 'includes/class-th-wishlist-frontend.php';
104 require_once THWL_DIR . 'includes/th-wishlist-function.php';
105 }
106
107 /**
108 * Hooks.
109 */
110 private function thwl_init_hooks() {
111 // Activation hook for installation.
112 register_activation_hook( THWL_PLUGIN_FILE, array( 'THWL_Install', 'install' ) );
113
114 // Initialize classes after plugins load.
115 add_action( 'plugins_loaded', array( $this, 'thwl_init' ) );
116
117 // Add settings link.
118 add_action( 'init', array( $this, 'thwl_add_plugin_action_links' ) );
119 }
120
121 /**
122 * Add plugin action links filter.
123 */
124 public function thwl_add_plugin_action_links() {
125 add_filter( 'plugin_action_links_' . THWL_PLUGIN_BASENAME, array( $this, 'thwl_wishlist_plugin_action_links' ), 10, 1 );
126 }
127
128 /**
129 * Init plugin when plugins are loaded.
130 */
131 public function thwl_init() {
132 add_action( 'init', array( $this, 'thwl_check_woocommerce' ) );
133 }
134
135 /**
136 * Check if WooCommerce is active.
137 */
138 public function thwl_check_woocommerce() {
139 if ( ! class_exists( 'WooCommerce' ) ) {
140 add_action( 'admin_notices', array( $this, 'thwl_woocommerce_missing_notice' ) );
141 return;
142 }
143 THWL_Manager::get_instance();
144 new THWL_Frontend();
145 new THWL_Admin();
146 }
147
148 /**
149 * Add settings link to plugin row.
150 */
151 public function thwl_wishlist_plugin_action_links( $links ) {
152 $settings_page = add_query_arg( array( 'page' => 'thwl-wishlist' ), admin_url( 'admin.php' ) );
153 $settings_link = '<a href="' . esc_url( $settings_page ) . '">' . esc_html__( 'Settings', 'th-wishlist' ) . '</a>';
154 array_unshift( $links, $settings_link );
155 return $links;
156 }
157
158 /**
159 * Display admin notice if WooCommerce is missing.
160 */
161
162 public function thwl_woocommerce_missing_notice() {
163 if ( ! is_admin() ) {
164 return;
165 }
166
167 $plugin_name = 'TH Wishlist';
168 $woo_link = '<a href="' . esc_url( 'https://woocommerce.com/' ) . '" target="_blank" rel="noopener noreferrer">' .
169 esc_html__( 'WooCommerce', 'th-wishlist' ) .
170 '</a>';
171
172 ?>
173 <div class="notice notice-error is-dismissible">
174 <p>
175 <?php
176 /* translators: 1: Plugin name. 2: WooCommerce link */
177 echo wp_kses_post(
178 sprintf(
179 // translators: %1$s: Plugin name, %2$s: WooCommerce link
180 __( '%1$s requires %2$s to be installed and active.', 'th-wishlist' ),
181 esc_html( $plugin_name ),
182 $woo_link
183 )
184 );
185 ?>
186 </p>
187 </div>
188 <?php
189 }
190
191
192
193 /**
194 * Re-run installer if demo import skipped activation.
195 */
196 public function thwl_maybe_run_install() {
197 // Run only in admin area to avoid slowing frontend.
198 if ( ! is_admin() ) {
199 return;
200 }
201
202 // Avoid running check too frequently.
203 if ( get_transient( 'thwl_install_checked' ) ) {
204 return;
205 }
206 set_transient( 'thwl_install_checked', true, 12 * HOUR_IN_SECONDS );
207
208 global $wpdb;
209 $table_name = $wpdb->prefix . 'thwl_wishlists';
210 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared
211 $table_exists = $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name ) );
212
213 $page_id = get_option( 'thwl_page_id' );
214
215 if ( ! $table_exists || ! $page_id ) {
216 if ( class_exists( 'THWL_Install' ) ) {
217 THWL_Install::install();
218 }
219 }
220 }
221 }
222
223 endif;
224
225 /**
226 * Main instance of THWL_Wishlist.
227 */
228 function THWL() {
229 return THWL_Wishlist::instance();
230 }
231
232 $GLOBALS['thwl_wishlist'] = THWL();
233
234
235
236 function thwl_astra_shop_card_wishlist( $markup, $product ) {
237
238
239
240 if ( ! $product instanceof WC_Product ) {
241 return $markup;
242 }
243
244 // Wishlist shortcode available hai ya nahi.
245 if ( ! shortcode_exists( 'thwl_add_to_wishlist' ) ) {
246 return $markup;
247 }
248
249 ob_start();
250 ?>
251 <div class="thunk-wishlist theme-compatible">
252 <span class="thunk-wishlist-inner">
253 <?php
254 echo do_shortcode(
255 sprintf(
256 '[thwl_add_to_wishlist
257 product_id="%d"
258 add_icon="th-icon th-icon-heart1"
259 add_text=""
260 add_browse_icon="th-icon th-icon-favorite"
261 browse_text=""
262 theme_style="yes"
263 icon_style="icon_only_no_style"
264 custom_class="th-wishlist-integrated"
265 ]',
266 $product->get_id()
267 )
268 );
269 ?>
270 </span>
271 </div>
272 <?php
273
274 $wishlist = ob_get_clean();
275
276 // Cart button ke baad wishlist.
277 return $markup . $wishlist;
278 }
279
280
281 add_action( 'after_setup_theme', 'thwl_astra_theme_integration' );
282
283 function thwl_astra_theme_integration() {
284
285 // Astra theme active hai?
286 if ( 'Astra' !== wp_get_theme()->get( 'Name' ) && 'astra' !== wp_get_theme()->get_template() ) {
287 return;
288 }
289
290 add_filter(
291 'astra_addon_shop_cards_buttons_html',
292 'thwl_astra_shop_card_wishlist',
293 10,
294 2
295 );
296
297 // Astra me default wishlist hook remove.
298 remove_action( 'wp', 'thwl_hook_wishlist_loop_button_position' );
299 }