-
Notifications
You must be signed in to change notification settings - Fork 0
/
maximum-products-per-user-for-woocommerce.php
92 lines (84 loc) · 2.91 KB
/
maximum-products-per-user-for-woocommerce.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/*
Plugin Name: Maximum Products per User for WooCommerce
Plugin URI: https://wpfactory.com/item/maximum-products-per-user-for-woocommerce/
Description: Limit number of items your WooCommerce customers can buy (lifetime or in selected date range).
Version: 4.3.4
Author: WPFactory
Author URI: https://wpfactory.com
Text Domain: maximum-products-per-user-for-woocommerce
Domain Path: /langs
Copyright: © 2024 WPFactory
WC tested up to: 9.4
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
// Handle is_plugin_active function
if ( ! function_exists( 'alg_wc_mppu_is_plugin_active' ) ) {
/**
* alg_wc_cog_is_plugin_active.
*
* @version 3.5.7
* @since 3.5.7
*/
function alg_wc_mppu_is_plugin_active( $plugin ) {
return ( function_exists( 'is_plugin_active' ) ? is_plugin_active( $plugin ) :
(
in_array( $plugin, apply_filters( 'active_plugins', ( array ) get_option( 'active_plugins', array() ) ) ) ||
( is_multisite() && array_key_exists( $plugin, ( array ) get_site_option( 'active_sitewide_plugins', array() ) ) )
)
);
}
}
// Check for active plugins
if (
! alg_wc_mppu_is_plugin_active( 'woocommerce/woocommerce.php' ) ||
( 'maximum-products-per-user-for-woocommerce.php' === basename( __FILE__ ) && alg_wc_mppu_is_plugin_active( 'maximum-products-per-user-for-woocommerce-pro/maximum-products-per-user-for-woocommerce-pro.php' ) )
) {
if ( function_exists( 'alg_wc_mppu' ) ) {
$plugin = alg_wc_mppu();
if ( method_exists( $plugin, 'set_free_version_filesystem_path' ) ) {
$plugin->set_free_version_filesystem_path( __FILE__ );
}
}
return;
}
if ( ! class_exists( 'Alg_WC_MPPU' ) ) :
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
endif;
require_once( 'includes/class-alg-wc-mppu-dynamic-properties-obj.php' );
require_once( 'includes/class-alg-wc-mppu.php' );
if ( ! function_exists( 'alg_wc_mppu' ) ) {
/**
* Returns the main instance of Alg_WC_MPPU to prevent the need to use globals.
*
* @version 2.0.0
* @since 1.0.0
* @return Alg_WC_MPPU
*/
function alg_wc_mppu() {
return Alg_WC_MPPU::instance();
}
}
// Initializes the plugin.
add_action( 'plugins_loaded', function () {
$plugin = alg_wc_mppu();
$plugin->set_filesystem_path( __FILE__ );
$plugin->init();
} );
// Custom deactivation/activation hooks.
$activation_hook = 'alg_wc_mppu_on_activation';
$deactivation_hook = 'alg_wc_mppu_on_deactivation';
register_activation_hook( __FILE__, function () use ( $activation_hook ) {
add_option( $activation_hook, 'yes' );
} );
register_deactivation_hook( __FILE__, function () use ( $deactivation_hook ) {
do_action( $deactivation_hook );
} );
add_action( 'admin_init', function () use ( $activation_hook ) {
if ( is_admin() && get_option( $activation_hook ) === 'yes' ) {
delete_option( $activation_hook );
do_action( $activation_hook );
}
} );