PluginProbe ʕ •ᴥ•ʔ
Discount Rules for WooCommerce / 2.6.13
Discount Rules for WooCommerce v2.6.13
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 8 months ago v1 1 year ago v2 8 months ago common.php 1 year ago readme.txt 8 months ago woo-discount-rules.php 8 months ago
common.php
213 lines
1 <?php
2 if (!defined('ABSPATH')) exit; // Exit if accessed directly
3
4 add_action('wp_ajax_awdr_switch_version', function (){
5 $version = isset($_REQUEST['version'])? sanitize_text_field(wp_unslash($_REQUEST['version'])) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
6 $page = isset($_REQUEST['page'])? sanitize_text_field(wp_unslash($_REQUEST['page'])): ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
7 $wdr_nonce = isset($_REQUEST['wdr_nonce'])? sanitize_text_field(wp_unslash($_REQUEST['wdr_nonce'])): ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
8 $return['status'] = false;
9 $return['message'] = esc_html('Invalid request');
10 if($version == "v1"){
11 \Wdr\App\Helpers\Helper::validateRequest('wdr_ajax_switch_version', $wdr_nonce);
12 } else {
13 WDRV1Deprecated::validateRequest('wdr_ajax_switch_version', $wdr_nonce);
14 }
15 if (current_user_can( 'manage_woocommerce' )) {
16 if($version !== '' && $page !== ''){
17 $url = esc_url(admin_url('admin.php?page=' . $page . '&awdr_switch_plugin_to=' . $version));
18 $do_switch = true;
19 if (!isAWDREnvironmentCompatible()) {
20 $return['message'] = 'Discount Rules 2.0 requires minimum PHP version of ' . ' ' . WDR_REQUIRED_PHP_VERSION;
21 wp_send_json_success($return);
22 }
23 if (!isAWDRWooCompatible()) {
24 $return['message'] = 'Discount Rules 2.0 requires at least Woocommerce' . ' ' . WDR_WC_REQUIRED_VERSION;
25 wp_send_json_success($return);
26 }
27 if (defined('WDR_BACKWARD_COMPATIBLE')) {
28 if(WDR_BACKWARD_COMPATIBLE == true){
29 if ($version == "v2") {
30 if (!defined('WDR_PRO')) {
31 $do_switch = false;
32 }
33 }
34 }
35 }
36 if($do_switch){
37 if(in_array($version, array('v1', 'v2'))){
38 update_option('advanced_woo_discount_rules_load_version', $version);
39 }
40 $return['status'] = true;
41 $return['message'] = '';
42 $return['url'] = $url;
43 } else {
44 $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.';
45 $return['type'] = 'manual_install';
46 }
47 }
48 }
49
50 wp_send_json_success($return);
51 });
52
53
54 /**
55 * Action sto show the toggle button
56 */
57 add_action('advanced_woo_discount_rules_on_settings_head', function () {
58 $has_switch = true;
59 $page = NULL;
60 /* phpcs:ignore WordPress.Security.NonceVerification.Recommended */
61 if (isset($_GET['page'])) {
62 $page = sanitize_text_field(wp_unslash($_GET['page'])); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
63 }
64 global $awdr_load_version;
65 $version = ($awdr_load_version == "v1") ? "v2" : "v1";
66 $url = esc_url(admin_url('admin.php?page=' . $page . '&awdr_switch_plugin_to=' . $version));
67 $message = 'Discount Rules V2 comes with a better UI and advanced options.';
68 $button_text = "Switch to New User Interface";
69 if($version == "v1"){
70 $has_switch = \Wdr\App\Helpers\Migration::hasSwitchBackOption();
71 $message = 'Would you like to switch to older Woo Discount Rules?';
72 $button_text = "Click here to Switch back";
73 }
74 if($has_switch){
75 if($version == "v1"){
76 $nounce = \Wdr\App\Helpers\Helper::create_nonce('wdr_ajax_switch_version');
77 } else {
78 $nounce = WDRV1Deprecated::createNonce('wdr_ajax_switch_version');
79 }
80 echo '<div class="notice notice-danger" style="background: red; color:#fff; padding: 20px;font-size: 13px;font-weight: bold;">
81 <p><b>Important: </b>It seems you are using the V1 User Interface. This UI was deprecated since March 2020. We have now removed it as it is no longer supported. Please switch to the new User Interface to create and manage your discount rules.
82 Click the "Switch" button to start using the new interface.</p>
83 </div>';
84
85 echo '<div style="background: #fff;padding: 20px;font-size: 13px;font-weight: bold;">' . esc_html($message) . ' <button class="btn btn-info awdr-switch-version-button" data-version="' . esc_attr($version) . '" data-page="' . esc_attr($page) . '" data-nonce="' . esc_attr($nounce) . '">' . esc_html($button_text) . '</button></div>';
86 echo "<div class='wdr_switch_message' style='color:#a00;font-weight: bold;'></div>";
87 }
88 });
89
90 /*add_action('advanced_woo_discount_rules_content_next_to_tabs', function () {
91 $has_switch = true;
92 $page = NULL;
93 if (isset($_GET['page'])) {
94 $page = sanitize_text_field($_GET['page']);
95 }
96 global $awdr_load_version;
97 $version = ($awdr_load_version == "v1") ? "v2" : "v1";
98 if($version == "v1"){
99 $has_switch = \Wdr\App\Helpers\Migration::hasSwitchBackOption();
100 }
101 if($version == "v1"){
102 $nounce = \Wdr\App\Helpers\Helper::create_nonce('wdr_ajax_switch_version');
103 } else {
104 $nounce = WDRV1Deprecated::createNonce('wdr_ajax_switch_version');
105 }
106 if($has_switch){
107 $button_text = "Switch back to Discount Rules 1.x";
108 echo '<button class="btn btn-info awdr-switch-version-button awdr-switch-version-button-on-tab" data-version="' . $version . '" data-page="'.$page.'" data-nonce="'.$nounce.'">' . $button_text . '</button>';
109 }
110 });*/
111
112 /**
113 * Determines if the server environment is compatible with this plugin.
114 *
115 * @return bool
116 * @since 1.0.0
117 *
118 */
119 if(!function_exists('isAWDREnvironmentCompatible')){
120 function isAWDREnvironmentCompatible()
121 {
122 return version_compare(PHP_VERSION, WDR_REQUIRED_PHP_VERSION, '>=');
123 }
124 }
125
126 /**
127 * Check the woocommerce is active or not
128 * @return bool
129 */
130 if(!function_exists('isAWDRWooActive')){
131 function isAWDRWooActive()
132 {
133 $active_plugins = apply_filters('active_plugins', get_option('active_plugins', array()));
134 if (is_multisite()) {
135 $active_plugins = array_merge($active_plugins, get_site_option('active_sitewide_plugins', array()));
136 }
137 return in_array('woocommerce/woocommerce.php', $active_plugins, false) || array_key_exists('woocommerce/woocommerce.php', $active_plugins);
138 }
139 }
140
141 /**
142 * Check woocommerce version is compatibility
143 * @return bool
144 */
145 if(!function_exists('isAWDRWooCompatible')){
146 function isAWDRWooCompatible()
147 {
148 $current_wc_version = getAWDRWooVersion();
149 return version_compare($current_wc_version, WDR_WC_REQUIRED_VERSION, '>=');
150 }
151 }
152
153 /**
154 * get the version of woocommerce
155 * @return mixed|null
156 */
157 if(!function_exists('getAWDRWooVersion')){
158 function getAWDRWooVersion()
159 {
160 if (defined('WC_VERSION')) {
161 return WC_VERSION;
162 }
163 if (!function_exists('get_plugins')) {
164 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
165 }
166 $plugin_folder = get_plugins('/woocommerce');
167 $plugin_file = 'woocommerce.php';
168 $wc_installed_version = NULL;
169 if (isset($plugin_folder[$plugin_file]['Version'])) {
170 $wc_installed_version = $plugin_folder[$plugin_file]['Version'];
171 }
172 return $wc_installed_version;
173 }
174 }
175
176 /**
177 * Determines if the WordPress compatible.
178 *
179 * @return bool
180 * @since 1.0.0
181 *
182 */
183 if(!function_exists('isAWDRWpCompatible')){
184 function isAWDRWpCompatible()
185 {
186 $required_wp_version = 4.9;
187 return version_compare(get_bloginfo('version'), $required_wp_version, '>=');
188 }
189 }
190
191 if(!function_exists('awdr_check_compatible')){
192 function awdr_check_compatible(){
193 if (!isAWDREnvironmentCompatible()) {
194 exit(esc_html('This plugin can not be activated because it requires minimum PHP version of ') . ' ' . esc_html(WDR_REQUIRED_PHP_VERSION));
195 }
196 if (!isAWDRWooActive()) {
197 exit(esc_html('Woocommerce must installed and activated in-order to use Advanced woo discount rules!'));
198 }
199 if (!isAWDRWooCompatible()) {
200 exit(esc_html(' Advanced woo discount rules requires at least Woocommerce') . ' ' . esc_html(WDR_WC_REQUIRED_VERSION));
201 }
202 }
203 }
204
205 /**
206 * For plugin translation
207 * */
208 add_action( 'plugins_loaded', function (){
209 if(function_exists('load_plugin_textdomain')){
210 load_plugin_textdomain( 'woo-discount-rules', false, basename( dirname( __FILE__ ) ) . '/i18n/languages/' );
211 }
212 });
213