PluginProbe ʕ •ᴥ•ʔ
Discount Rules for WooCommerce / 1.9.12
Discount Rules for WooCommerce v1.9.12
1.4.39 1.4.4 1.4.40 1.4.41 1.4.42 1.4.43 1.4.44 1.4.45 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.11 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.10 1.6.11 1.6.12 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.10 1.7.11 1.7.12 1.7.13 1.7.14 1.7.15 1.7.16 1.7.17 1.7.18 1.7.19 1.7.2 1.7.20 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.10 2.3.11 2.3.12 2.3.13 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.4 2.4.5 2.5.0 2.5.2 2.5.3 2.5.4 2.6.0 2.6.1 2.6.10 2.6.11 2.6.12 2.6.13 2.6.14 2.6.15 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 trunk 1.1 1.2 1.3 1.4 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.16 1.4.17 1.4.18 1.4.19 1.4.2 1.4.20 1.4.21 1.4.22 1.4.23 1.4.24 1.4.25 1.4.26 1.4.27 1.4.28 1.4.29 1.4.3 1.4.30 1.4.31 1.4.32 1.4.33 1.4.34 1.4.35 1.4.36 1.4.37 1.4.38
woo-discount-rules / common.php
woo-discount-rules Last commit date
i18n 6 years ago v1 6 years ago v2 6 years ago common.php 6 years ago readme.txt 6 years ago woo-discount-rules.php 6 years ago
common.php
211 lines
1 <?php
2 if (!defined('ABSPATH')) exit; // Exit if accessed directly
3
4 add_action('wp_ajax_awdr_auto_install_pro_plugin', function (){
5 FlycartWooDiscountRulesExistingPROUpdater::installProPlugin();
6 exit;
7 });
8 add_action('wp_ajax_awdr_switch_version', function (){
9 $version = isset($_REQUEST['version'])? $_REQUEST['version']: '';
10 $page = isset($_REQUEST['page'])? $_REQUEST['page']: '';
11 $return['status'] = false;
12 $return['message'] = esc_html__('Invalid request', WDR_TEXT_DOMAIN);
13 if($version !== '' && $page !== ''){
14 $url = admin_url('admin.php?page=' . $page . '&awdr_switch_plugin_to=' . $version);
15 $do_switch = true;
16 if (!isAWDREnvironmentCompatible()) {
17 $return['message'] = __('Discount Rules 2.0 requires minimum PHP version of ', WDR_TEXT_DOMAIN) . ' ' . WDR_REQUIRED_PHP_VERSION;
18 wp_send_json_success($return);
19 }
20 if (!isAWDRWooCompatible()) {
21 $return['message'] = __('Discount Rules 2.0 requires at least Woocommerce', WDR_TEXT_DOMAIN) . ' ' . WDR_WC_REQUIRED_VERSION;
22 wp_send_json_success($return);
23 }
24 if (defined('WDR_BACKWARD_COMPATIBLE')) {
25 if(WDR_BACKWARD_COMPATIBLE == true){
26 if ($version == "v2") {
27 if (!defined('WDR_PRO')) {
28 $do_switch = false;
29 }
30 }
31 }
32 }
33 if($do_switch){
34 $return['status'] = true;
35 $return['message'] = '';
36 $return['url'] = $url;
37 } else {
38 $has_auto_update = false;
39 if (!is_multisite()) {
40 if(class_exists('FlycartWooDiscountRulesExistingPROUpdater')){
41 if(FlycartWooDiscountRulesExistingPROUpdater::availableAutoInstall()){
42 $has_auto_update = true;
43 }
44 }
45 }
46 if($has_auto_update){
47 $return['type'] = 'auto_install';
48 $message = __('<p>Since 2.0, you need BOTH Core and Pro (2.0) packages installed and activated.</p>', WDR_TEXT_DOMAIN);
49 $message .= __('<p><b>Why we made this change?</b></p>', WDR_TEXT_DOMAIN);
50 $message .= __('<p>This arrangement is to avoid the confusion in the installation and upgrade process. Many users first install the core free version. Then purchase the PRO version and try to install it over the free version. Since both free and pro packages have same names, wordpress asks them to uninstall free and then install pro. As you can see, this is quite confusing for the end users.</p>', WDR_TEXT_DOMAIN);
51 $message .= __('<p>As a result, starting from 2.0, we now have two packs: 1. Core 2. PRO.</p>', WDR_TEXT_DOMAIN);
52 $message .= '<p><button type="button" class="awdr_auto_install_pro_plugin btn btn-info">'.__('Download and Install', WDR_TEXT_DOMAIN).'</button></p>';
53 $return['message'] = $message;
54 } else {
55 $return['message'] = __('Since 2.0, you need BOTH Core and Pro (2.0) packages installed and activated. Please download the Pro 2.0 pack from My Downloads page in our site, install and activate it. <a href="https://docs.flycart.org/en/articles/4006520-switching-to-2-0-from-v1-x-versions?utm_source=woo-discount-rules-v2&utm_campaign=doc&utm_medium=text-click&utm_content=switch_to_v2" target="_blank">Here is a guide and video tutorial</a>', WDR_TEXT_DOMAIN);
56 $return['type'] = 'manual_install';
57 }
58 }
59 }
60
61 wp_send_json_success($return);
62 });
63
64
65 /**
66 * Action sto show the toggle button
67 */
68 add_action('advanced_woo_discount_rules_on_settings_head', function () {
69 $has_switch = true;
70 $page = NULL;
71 if (isset($_GET['page'])) {
72 $page = sanitize_text_field($_GET['page']);
73 }
74 global $awdr_load_version;
75 $version = ($awdr_load_version == "v1") ? "v2" : "v1";
76 $url = admin_url('admin.php?page=' . $page . '&awdr_switch_plugin_to=' . $version);
77 $message = __('Switch to Discount Rules 2.0 which comes with a better UI and advanced rules. (You can switch back any time. Your settings and rules in V1 are kept as is)', WDR_TEXT_DOMAIN);
78 $button_text = __("Switch to 2.0 <span style='background-color: #FF8C00 ; padding: 3px; border-radius: 4px'>Public beta</span>", WDR_TEXT_DOMAIN);
79 if($version == "v1"){
80 $has_switch = \Wdr\App\Helpers\Migration::hasSwitchBackOption();
81 $message = __('Would you like to switch to older Woo Discount Rules?', WDR_TEXT_DOMAIN);
82 $button_text = __("Click here to Switch back", WDR_TEXT_DOMAIN);
83 }
84 if($has_switch){
85 echo '<div style="background: #fff;padding: 20px;font-size: 13px;font-weight: bold;">' . $message . ' <button class="btn btn-info awdr-switch-version-button" data-version="' . $version . '" data-page="'.$page.'">' . $button_text . '</button></div>';
86 echo "<div class='wdr_switch_message' style='color:#a00;font-weight: bold;'></div>";
87 echo '<div class="modal" id="wdr_switch_popup">
88 <div class="modal-sandbox"></div>
89 <div class="modal-box">
90 <div class="modal-header">
91 <div class="close-modal"><span class="wdr-close-modal-box">&#10006;</span></div>
92 <h1 class="wdr-modal-header-title">'.__("Install 2.0 Pro package", WDR_TEXT_DOMAIN).'</h1>
93 </div>
94 <div class="modal-body">
95 <div class=\'wdr_pro_install_message\'></div>
96 </div>
97 </div>
98 </div>';
99 }
100 });
101
102 add_action('advanced_woo_discount_rules_content_next_to_tabs', function () {
103 $has_switch = true;
104 $page = NULL;
105 if (isset($_GET['page'])) {
106 $page = sanitize_text_field($_GET['page']);
107 }
108 global $awdr_load_version;
109 $version = ($awdr_load_version == "v1") ? "v2" : "v1";
110 if($version == "v1"){
111 $has_switch = \Wdr\App\Helpers\Migration::hasSwitchBackOption();
112 }
113 if($has_switch){
114 $button_text = __("Switch back to Discount Rules 1.x", WDR_TEXT_DOMAIN);
115 echo '<button class="btn btn-info awdr-switch-version-button awdr-switch-version-button-on-tab" data-version="' . $version . '" data-page="'.$page.'">' . $button_text . '</button>';
116 }
117 });
118
119 /**
120 * Determines if the server environment is compatible with this plugin.
121 *
122 * @return bool
123 * @since 1.0.0
124 *
125 */
126 if(!function_exists('isAWDREnvironmentCompatible')){
127 function isAWDREnvironmentCompatible()
128 {
129 return version_compare(PHP_VERSION, WDR_REQUIRED_PHP_VERSION, '>=');
130 }
131 }
132
133 /**
134 * Check the woocommerce is active or not
135 * @return bool
136 */
137 if(!function_exists('isAWDRWooActive')){
138 function isAWDRWooActive()
139 {
140 $active_plugins = apply_filters('active_plugins', get_option('active_plugins', array()));
141 if (is_multisite()) {
142 $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
143 }
144 return in_array('woocommerce/woocommerce.php', $active_plugins, false) || array_key_exists('woocommerce/woocommerce.php', $active_plugins);
145 }
146 }
147
148 /**
149 * Check woocommerce version is compatibility
150 * @return bool
151 */
152 if(!function_exists('isAWDRWooCompatible')){
153 function isAWDRWooCompatible()
154 {
155 $current_wc_version = getAWDRWooVersion();
156 return version_compare($current_wc_version, WDR_WC_REQUIRED_VERSION, '>=');
157 }
158 }
159
160 /**
161 * get the version of woocommerce
162 * @return mixed|null
163 */
164 if(!function_exists('getAWDRWooVersion')){
165 function getAWDRWooVersion()
166 {
167 if (defined('WC_VERSION')) {
168 return WC_VERSION;
169 }
170 if (!function_exists('get_plugins')) {
171 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
172 }
173 $plugin_folder = get_plugins('/woocommerce');
174 $plugin_file = 'woocommerce.php';
175 $wc_installed_version = NULL;
176 if (isset($plugin_folder[$plugin_file]['Version'])) {
177 $wc_installed_version = $plugin_folder[$plugin_file]['Version'];
178 }
179 return $wc_installed_version;
180 }
181 }
182
183 /**
184 * Determines if the WordPress compatible.
185 *
186 * @return bool
187 * @since 1.0.0
188 *
189 */
190 if(!function_exists('isAWDRWpCompatible')){
191 function isAWDRWpCompatible()
192 {
193 $required_wp_version = 4.9;
194 return version_compare(get_bloginfo('version'), $required_wp_version, '>=');
195 }
196 }
197
198 if(!function_exists('awdr_check_compatible')){
199 function awdr_check_compatible(){
200 if (!isAWDREnvironmentCompatible()) {
201 exit(__('This plugin can not be activated because it requires minimum PHP version of ', WDR_TEXT_DOMAIN) . ' ' . WDR_REQUIRED_PHP_VERSION);
202 }
203 if (!isAWDRWooActive()) {
204 exit(__('Woocommerce must installed and activated in-order to use Advanced woo discount rules!', WDR_TEXT_DOMAIN));
205 }
206 if (!isAWDRWooCompatible()) {
207 exit(__(' Advanced woo discount rules requires at least Woocommerce', WDR_TEXT_DOMAIN) . ' ' . WDR_WC_REQUIRED_VERSION);
208 }
209 }
210 }
211