PluginProbe
Whols – Wholesale Prices and B2B Store Solution for WooCommerce / 2.4.6
Whols – Wholesale Prices and B2B Store Solution for WooCommerce v2.4.6
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.6, at whols.php

406 lines 13.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: 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.6
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.6';
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
318 /**
319 * Output a admin notice when build dependencies not met
320 *
321 * @since 1.0.0
322 */
323 public function build_dependencies_notice() {
324 $message = sprintf(
325 /*
326 * translators:
327 * 1: Whols.
328 * 2: WooCommerce.
329 */
330 esc_html__( '%1$s plugin requires the %2$s plugin to be installed and activated in order to work.', 'whols' ),
331 '<strong>' . esc_html__( 'Whols', 'whols' ) . '</strong>',
332 '<strong>' . esc_html__( 'WooCommerce', 'whols' ) . '</strong>'
333 );
334
335 printf( '<div class="notice notice-warning"><p>%1$s</p></div>', wp_kses_post($message) );
336 }
337
338 /**
339 * Create and set default role
340 */
341 public function insert_default_term(){
342 // check if category(term) exists
343 $cat_exists = term_exists('whols_default_role', 'whols_role_cat');
344
345 if ( !$cat_exists ) {
346 // if term is not exist, insert it
347 $new_cat = wp_insert_term(
348 esc_html__( 'Default Role', 'whols' ),
349 'whols_role_cat',
350 array(
351 'description' => esc_html__( 'Default Wholesale Role', 'whols' ),
352 'slug' => 'whols_default_role',
353 )
354 );
355 // wp_insert_term returns an array on success so we need to get the term_id from it
356 $default_cat_id = ($new_cat && is_array($new_cat)) ? $new_cat['term_id'] : false;
357 } else {
358 //if default category is already inserted, term_exists will return it's term_id
359 $default_cat_id = $cat_exists;
360 }
361
362 // Setting default_{$taxonomy} option value as our default term_id to make them default and non-removable (like default uncategorized WP category)
363 $stored_default_cat = get_option( 'whols_default_role' );
364
365 if ( empty( $stored_default_cat ) && $default_cat_id )
366 update_option( 'whols_default_role', $default_cat_id );
367 }
368
369 /**
370 * Implement test mode feature
371 * If test mode is enabled, it adds whols_default_role to the current logged in administrator user
372 * and if the test mode is disabled, it removes the whols_default_role from the administrator
373 */
374 public function init_test_mode(){
375 if( is_user_logged_in() && current_user_can('manage_options') ){
376
377 $current_user = wp_get_current_user();
378 $is_test_mode = whols_get_option('show_wholesale_price_for') === 'administrator' ? true : false;
379
380 $test_mode_meta = get_user_meta(get_current_user_id(), 'whols_test_mode', true );
381
382 if( $is_test_mode && !$test_mode_meta && !array_intersect($current_user->roles, array('whols_default_role')) ){
383 $current_user->add_role('whols_default_role');
384 update_user_meta( get_current_user_id(), 'whols_test_mode', 1 );
385 } elseif( !$is_test_mode && $test_mode_meta && array_intersect($current_user->roles, array('whols_default_role') ) ){
386 $current_user->remove_role('whols_default_role');
387 delete_user_meta( get_current_user_id(), 'whols_test_mode' );
388 }
389 }
390 }
391
392 }
393
394 /**
395 * Returns the main instance of Whols
396 *
397 * @since 1.0.0
398 */
399
400 function whols_lite() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
401 return Whols_Lite::instance();
402 }
403
404 // Kick-off the plugin
405 whols_lite();
406