PluginProbe
Whols – Wholesale Prices and B2B Store Solution for WooCommerce / 2.4.4
Whols – Wholesale Prices and B2B Store Solution for WooCommerce v2.4.4
2.4.12 2.4.11 trunk 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 All 55 releases
whols / whols.php

whols.php in Whols – Wholesale Prices and B2B Store Solution for WooCommerce 2.4.4, at whols.php

429 lines 14.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Whols - Wholesale Prices and B2B Store Solution for WooCommerce
4 * Plugin URI: https://wpwhols.com/
5 * Description: This plugin provides all the necessary features that you will ever need to sell wholesale products from your WooCommerce online store.
6 * Version: 2.4.4
7 * Author: HasThemes
8 * Author URI: https://hasthemes.com
9 * License: GPL v2 or later
10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
11 * Text Domain: whols
12 * Domain Path: /languages
13 */
14
15 use const Whols\PL_VERSION;
16 use const Whols\PL_FILE;
17 use const Whols\PL_PATH;
18 use const Whols\PL_URL;
19
20 // If this file is accessed directly, exit
21 if ( ! defined( 'ABSPATH' ) ) {
22 exit;
23 }
24
25 /**
26 * Main Whols class
27 *
28 * @since 1.0.0
29 */
30
31 final class Whols_Lite {
32
33 /**
34 * Whols version
35 *
36 * @since 1.0.0
37 */
38 public $version = '2.4.4';
39
40 /**
41 * The single instance of the class
42 *
43 * @since 1.0.0
44 */
45 protected static $_instance = null;
46
47 /**
48 * Main Whols Instance
49 *
50 * Ensures only one instance of Whols is loaded or can be loaded
51 *
52 * @since 1.0.0
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 * Whols Constructor
63 *
64 * @since 1.0.0
65 */
66 private function __construct() {
67 $this->define_constants();
68 $this->includes();
69 $this->run();
70 }
71
72 /**
73 * Define the required constants
74 *
75 * @since 1.0.0
76 */
77 private function define_constants() {
78 define( 'WHOLS_VERSION', $this->version );
79 define( 'WHOLS_FILE', __FILE__ );
80 define( 'WHOLS_PATH', __DIR__ );
81 define( 'WHOLS_URL', plugins_url( '', WHOLS_FILE ) );
82 define( 'WHOLS_ASSETS', WHOLS_URL . '/assets' );
83
84 define( 'Whols\PL_VERSION', $this->version );
85 define( 'Whols\PL_FILE', __FILE__ );
86 define( 'Whols\PL_PATH', __DIR__ );
87 define( 'Whols\PL_URL', plugins_url( '', PL_FILE ) );
88 define( 'Whols\PL_ASSETS', PL_URL . '/assets' );
89 }
90
91 /**
92 * Include files
93 *
94 * @since 1.0.0
95 */
96 public function includes() {
97 /**
98 * Including plugin file for secutiry purpose
99 */
100 if ( ! function_exists( 'is_plugin_active' ) ) {
101 include_once ABSPATH . 'wp-admin/includes/plugin.php';
102 }
103
104 if ( ! function_exists( 'get_current_screen' ) ) {
105 require_once ABSPATH . '/wp-admin/includes/screen.php';
106 }
107
108 /**
109 * Load files
110 */
111 require_once WHOLS_PATH . '/includes/functions.php';
112 require_once WHOLS_PATH . '/includes/ajax-actions.php';
113
114 if ( ! class_exists( 'CSF' ) ) {
115 require_once WHOLS_PATH .'/includes/Admin/csf-settings-custom/classes/setup.class.php';
116 require_once WHOLS_PATH . '/includes/Admin/csf-fields/CSF_Field_registration_details.php';
117 }
118
119 // Assets
120 require_once WHOLS_PATH . '/includes/class-assets-manager.php';
121
122 require_once WHOLS_PATH . '/includes/Admin.php';
123
124 require_once WHOLS_PATH . '/includes/Admin/Custom_Posts.php';
125 require_once WHOLS_PATH . '/includes/Admin/Custom_Taxonomies.php';
126 require_once WHOLS_PATH . '/includes/Admin/Wholesaler_Request_Metabox.php';
127 require_once WHOLS_PATH . '/includes/Admin/Product_Metabox.php';
128 require_once WHOLS_PATH . '/includes/Admin/User_Metabox.php';
129 require_once WHOLS_PATH . '/includes/Admin/Role_Cat_Metabox.php';
130 require_once WHOLS_PATH . '/includes/Admin/Product_Category_Metabox.php';
131 require_once WHOLS_PATH . '/includes/Admin/Role_Manager.php';
132 require_once WHOLS_PATH . '/includes/Admin/Custom_Columns.php';
133 require_once WHOLS_PATH . '/includes/Admin/class-polylang-integration.php';
134 require_once WHOLS_PATH . '/includes/Admin/CSF_Field_whols_image.php';
135 require_once WHOLS_PATH . '/includes/Admin/recommended-plugins/class.recommended-plugins.php';
136 require_once WHOLS_PATH . '/includes/Admin/recommended-plugins/recommendations.php';
137 require_once WHOLS_PATH . '/includes/Admin/install-manager/class-install-manager.php';
138 require_once WHOLS_PATH . '/includes/Admin/Diagnostic_Data.php';
139 // require_once WHOLS_PATH . '/includes/Admin/Trial.php';
140 require_once WHOLS_PATH . '/includes/Admin/class-menu-manager.php';
141 require_once WHOLS_PATH . '/includes/Admin/Notice_Handler.php';
142
143 require_once WHOLS_PATH . '/includes/Frontend.php';
144 require_once WHOLS_PATH . '/includes/Frontend/Wholesaler_Login_Register.php';
145 require_once WHOLS_PATH . '/includes/Frontend/Woo_Config.php';
146
147 whols_include_plugin_file('includes/class-wholesale-product-pricing.php');
148
149 // Popup
150 whols_include_plugin_file('includes/popup/class-whols-popup.php');
151
152 // Quote
153 require_once WHOLS_PATH . '/includes/request-a-quote/class-request-quote.php';
154
155 // Save Order List
156 whols_include_plugin_file('includes/save-order-list/class-save-order-list.php');
157
158 // Product Quick Edit Fields
159 whols_include_plugin_file('includes/Admin/class-product-quick-edit-fields.php');
160
161 require_once WHOLS_PATH . '/includes/Email_Notifications.php';
162 require_once WHOLS_PATH . '/includes/Manage_Order.php';
163 require_once WHOLS_PATH . '/includes/Compatibility.php';
164
165 // Vue settings
166 require_once PL_PATH . '/includes/vue-settings/class-init.php';
167 }
168
169 /**
170 * First initialization of the plugin
171 *
172 * @since 1.0.0
173 */
174 private function run() {
175 register_activation_hook( __FILE__, array( $this, 'register_activation_hook_cb' ) );
176
177 if ( ! is_plugin_active( 'woocommerce/woocommerce.php' ) ) {
178 add_action( 'admin_notices', array( $this, 'build_dependencies_notice' ) );
179 } else {
180 // Set up localisation.
181 add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
182
183 // Finally initialize this plugin
184 add_action( 'plugins_loaded', array( $this, 'plugins_loaded_cb' ) );
185
186 // Redirect to welcome page after activate the plugin
187 // $plugin_file = 'woolentor-addons/woolentor_addons_elementor.php';
188 // if ( file_exists( WP_PLUGIN_DIR . '/' . $plugin_file ) && is_plugin_inactive( $plugin_file ) ) {
189 // add_action('admin_init', array( $this, 'redirect_after_activate') );
190 // }
191
192 // Redirect after activation
193 add_action('admin_init', array( $this, 'do_activation_redirect') );
194 }
195 }
196
197 /**
198 * Do stuff upon plugin activation
199 *
200 * @since 1.0.0
201 */
202 public function register_activation_hook_cb() {
203 // deactivate the pro plugin if active
204 if ( ! function_exists('is_plugin_active') ){
205 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
206 }
207
208 if( is_plugin_active('whols-pro/whols-pro.php') ){
209 add_action('update_option_active_plugins', function(){
210 deactivate_plugins('whols-pro/whols-pro.php');
211 });
212 }
213
214 $installed = get_option( 'whols_installed' );
215
216 if ( ! $installed ) {
217 update_option( 'whols_installed', time() );
218 }
219
220 update_option( 'whols_version', WHOLS_VERSION );
221 update_option( 'whols_do_activation_redirect', 'yes' );
222
223 // Save initial settings if not already.
224 $existing_settings = get_option('whols_options');
225 if ( empty($existing_settings) ) {
226 $defaults = Whols\Vue_Settings\Settings_Defaults::get_defaults();
227 update_option( 'whols_options', $defaults );
228 }
229 }
230
231 /**
232 * Maybe redirect to the admin page
233 *
234 * Checks if the activation redirect flag is set and redirects to the admin page if needed
235 *
236 * @return void
237 */
238 public function do_activation_redirect() {
239 // Only run on admin page load
240 if ( ! is_admin() || wp_doing_ajax() ) {
241 return;
242 }
243
244 // Check if we should redirect
245 $redirect = get_option( 'whols_do_activation_redirect' );
246
247 if ( 'yes' === $redirect ) {
248 // Delete the redirect option to prevent multiple redirects
249 delete_option( 'whols_do_activation_redirect' );
250
251 $redirect_link = admin_url( 'admin.php?page=whols-admin' );
252
253 if( whols_should_show_onboarding() ){
254 $redirect_link = admin_url( 'admin.php?page=whols-admin#onboarding' );
255 }
256
257 // Redirect to the admin page
258 wp_safe_redirect( $redirect_link );
259 exit;
260 }
261 }
262
263 /**
264 * Load the plugin textdomain
265 *
266 * @since 1.0.0
267 */
268 public function load_plugin_textdomain() {
269 load_plugin_textdomain( 'whols', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
270 }
271
272 /**
273 * Initialize this plugin
274 *
275 * @since 1.0.0
276 */
277 public function plugins_loaded_cb() {
278 // Both admin + frontend
279 new Whols\Assets_Manager();
280 new Whols\Manage_Order();
281 new Whols\Compatibility();
282 new Whols\Admin\Custom_Posts();
283
284 // Prior this was instantiate only in the Frontend.php file
285 // The reason why moved it here is to load it on both frontend & admin because for using the has_shortcode function in the admin area too.
286 new Whols\Frontend\Wholesaler_Login_Register();
287
288 // Frontend
289 new Whols\Frontend();
290 new Whols\Frontend\Woo_Config();
291 new Whols\Request_Quote();
292
293 if ( is_admin() ) {
294 new Whols\Admin();
295 new Whols\Admin\Menu_Manager();
296 }
297
298 // Insert default role
299 add_action('init', array( $this, 'insert_default_term'), 12);
300
301 // Test mode
302 $this->init_test_mode();
303
304 // Notice
305 add_action( 'admin_head', function(){
306 $remote_banner_data = whols_get_plugin_remote_data();
307
308 if (!empty($remote_banner_data) && is_array($remote_banner_data)) {
309 foreach ($remote_banner_data as $banner) {
310 if (empty($banner['disable'])) {
311 Whols\Admin\Notice_Handler::set_notice($banner);
312 }
313 }
314 }
315 } );
316
317 // Halloween Promotion
318 add_action( 'admin_head', function(){
319 $plugins = get_plugins();
320 if(!empty($plugins['whols-pro/whols-pro.php'])) {
321 return;
322 }
323 $url = 'https://wpwhols.com/pricing/?utm_source=onedollar&utm_medium=topbar';
324 $image = WHOLS_URL . '/assets/images/halloween-2025.png';
325 Whols\Admin\Notice_Handler::set_notice(
326 [
327 'id' => 'halloween-notice',
328 'type' => 'notice',
329 'dismissible' => true,
330 'message_type' => 'banner',
331 'banner' => [
332 'url' => esc_url_raw($url),
333 'image' => '<img src="'.esc_url_raw($image).'" alt="Whols" style="max-width:100%"/>'
334 ],
335 'close_by' => 'transient'
336 ]
337 );
338 } );
339 }
340
341 /**
342 * Output a admin notice when build dependencies not met
343 *
344 * @since 1.0.0
345 */
346 public function build_dependencies_notice() {
347 $message = sprintf(
348 /*
349 * translators:
350 * 1: Whols.
351 * 2: WooCommerce.
352 */
353 esc_html__( '%1$s plugin requires the %2$s plugin to be installed and activated in order to work.', 'whols' ),
354 '<strong>' . esc_html__( 'Whols', 'whols' ) . '</strong>',
355 '<strong>' . esc_html__( 'WooCommerce', 'whols' ) . '</strong>'
356 );
357
358 printf( '<div class="notice notice-warning"><p>%1$s</p></div>', wp_kses_post($message) );
359 }
360
361 /**
362 * Create and set default role
363 */
364 public function insert_default_term(){
365 // check if category(term) exists
366 $cat_exists = term_exists('whols_default_role', 'whols_role_cat');
367
368 if ( !$cat_exists ) {
369 // if term is not exist, insert it
370 $new_cat = wp_insert_term(
371 esc_html__( 'Default Role', 'whols' ),
372 'whols_role_cat',
373 array(
374 'description' => esc_html__( 'Default Wholesale Role', 'whols' ),
375 'slug' => 'whols_default_role',
376 )
377 );
378 // wp_insert_term returns an array on success so we need to get the term_id from it
379 $default_cat_id = ($new_cat && is_array($new_cat)) ? $new_cat['term_id'] : false;
380 } else {
381 //if default category is already inserted, term_exists will return it's term_id
382 $default_cat_id = $cat_exists;
383 }
384
385 // Setting default_{$taxonomy} option value as our default term_id to make them default and non-removable (like default uncategorized WP category)
386 $stored_default_cat = get_option( 'whols_default_role' );
387
388 if ( empty( $stored_default_cat ) && $default_cat_id )
389 update_option( 'whols_default_role', $default_cat_id );
390 }
391
392 /**
393 * Implement test mode feature
394 * If test mode is enabled, it adds whols_default_role to the current logged in administrator user
395 * and if the test mode is disabled, it removes the whols_default_role from the administrator
396 */
397 public function init_test_mode(){
398 if( is_user_logged_in() && current_user_can('manage_options') ){
399
400 $current_user = wp_get_current_user();
401 $is_test_mode = whols_get_option('show_wholesale_price_for') === 'administrator' ? true : false;
402
403 $test_mode_meta = get_user_meta(get_current_user_id(), 'whols_test_mode', true );
404
405 if( $is_test_mode && !$test_mode_meta && !array_intersect($current_user->roles, array('whols_default_role')) ){
406 $current_user->add_role('whols_default_role');
407 update_user_meta( get_current_user_id(), 'whols_test_mode', 1 );
408 } elseif( !$is_test_mode && $test_mode_meta && array_intersect($current_user->roles, array('whols_default_role') ) ){
409 $current_user->remove_role('whols_default_role');
410 delete_user_meta( get_current_user_id(), 'whols_test_mode' );
411 }
412 }
413 }
414
415 }
416
417 /**
418 * Returns the main instance of Whols
419 *
420 * @since 1.0.0
421 */
422
423 function whols_lite() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
424 return Whols_Lite::instance();
425 }
426
427 // Kick-off the plugin
428 whols_lite();
429