PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.3.2
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.3.2
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
← All changes | inc/classes/class-merchant-modules.php +277 -215 1.8.22.3.2 View file →
@@ -1,215 +1,277 @@
1 -<?php
2 -/**
3 - * Merchant_Modules Class.
4 - */
5 -
6 -if ( ! defined( 'ABSPATH' ) ) {
7 - exit; // Exit if accessed directly
8 -}
9 -
10 -if ( ! class_exists( 'Merchant_Modules' ) ) {
11 -
12 - class Merchant_Modules {
13 -
14 - /**
15 - * The modules container.
16 - */
17 - private $container = array();
18 -
19 - /**
20 - * Option name
21 - */
22 - public static $option = 'merchant-modules';
23 -
24 - /**
25 - * The single class instance.
26 - */
27 - private static $instance = null;
28 -
29 - /**
30 - * Instance.
31 - */
32 - public static function instance() {
33 - if ( is_null( self::$instance ) ) {
34 - self::$instance = new self();
35 - }
36 - return self::$instance;
37 - }
38 -
39 - /**
40 - * Constructor.
41 - */
42 - public function __construct() {
43 -
44 - add_action( 'wp_ajax_merchant_module_activate', array( $this, 'activate_module' ) );
45 - add_action( 'wp_ajax_merchant_module_deactivate', array( $this, 'deactivate_module' ) );
46 - add_action( 'wp_ajax_merchant_module_feedback', array( $this, 'feedback_module' ) );
47 - }
48 -
49 - /**
50 - * Activate module with Ajax.
51 - */
52 - public function activate_module() {
53 - $nonce = ( isset( $_POST['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
54 - $module = ( isset( $_POST['module'] ) ) ? sanitize_text_field( wp_unslash( $_POST['module'] ) ) : '';
55 -
56 - // Check current user capabilities
57 - if ( ! current_user_can( 'manage_options' ) ) {
58 - wp_send_json_error( 'You are not allowed to do this.' );
59 - }
60 -
61 - if ( wp_verify_nonce( $nonce, 'merchant' ) && ! empty( $module ) ) {
62 -
63 - $modules = get_option( self::$option, array() );
64 -
65 - $modules[ $module ] = true;
66 -
67 - update_option( self::$option, $modules );
68 -
69 - wp_send_json_success();
70 -
71 - }
72 -
73 - wp_send_json_error();
74 - }
75 -
76 - /**
77 - * Deactivate module with Ajax.
78 - */
79 - public function deactivate_module() {
80 - $nonce = ( isset( $_POST['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
81 - $module = ( isset( $_POST['module'] ) ) ? sanitize_text_field( wp_unslash( $_POST['module'] ) ) : '';
82 -
83 - // Check current user capabilities
84 - if ( ! current_user_can( 'manage_options' ) ) {
85 - wp_send_json_error( 'You are not allowed to do this.' );
86 - }
87 -
88 - if ( wp_verify_nonce( $nonce, 'merchant' ) && ! empty( $module ) ) {
89 -
90 - $modules = get_option( self::$option, array() );
91 -
92 - $modules[ $module ] = false;
93 -
94 - update_option( self::$option, $modules );
95 -
96 - wp_send_json_success();
97 -
98 - }
99 -
100 - wp_send_json_error();
101 - }
102 -
103 - /**
104 - * Feedback module with Ajax.
105 - */
106 - public function feedback_module() {
107 - $nonce = ( isset( $_POST['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
108 - $subject = ( isset( $_POST['subject'] ) ) ? sanitize_text_field( wp_unslash( $_POST['subject'] ) ) : '';
109 - $message = ( isset( $_POST['message'] ) ) ? sanitize_textarea_field( wp_unslash( $_POST['message'] ) ) : '';
110 - $module = ( isset( $_POST['module'] ) ) ? sanitize_text_field( wp_unslash( $_POST['module'] ) ) : '';
111 - $from = get_bloginfo( 'admin_email' );
112 -
113 - // Check current user capabilities
114 - if ( ! current_user_can( 'manage_options' ) ) {
115 - wp_send_json_error( 'You are not allowed to do this.' );
116 - }
117 -
118 - if ( wp_verify_nonce( $nonce, 'merchant' ) ) {
119 - $response = wp_remote_post( 'https://athemes.com/merchant/', array(
120 - 'body' => array(
121 - 'mailsender' => true,
122 - 'from' => $from,
123 - 'subject' => $subject,
124 - 'message' => $message,
125 - 'module' => $module,
126 - ),
127 - ) );
128 -
129 - if ( is_wp_error( $response ) ) {
130 - wp_send_json_error();
131 - }
132 -
133 - wp_send_json_success();
134 - }
135 -
136 - wp_send_json_error();
137 - }
138 -
139 - /**
140 - * Creates and adds the module instance to the container.
141 - *
142 - * @param Merchant_Add_Module $module The module instance.
143 - *
144 - * @return void
145 - */
146 - public static function create_module( Merchant_Add_Module $module ) {
147 - static::instance()->container[ $module->module_id ] = $module;
148 - }
149 -
150 - /**
151 - * Get the module instance.
152 - *
153 - * @param string $module_id The module ID.
154 - *
155 - * @return Merchant_Add_Module|mixed The module instance.
156 - */
157 - public static function get_module( $module_id ) {
158 - return static::instance()->container[ $module_id ];
159 - }
160 -
161 - /**
162 - * Determines if a module has already been added to the container.
163 - *
164 - * @param string $module_id The module ID.
165 - *
166 - * @return bool
167 - */
168 - public static function is_module_created( $module_id ) {
169 - return in_array( $module_id, static::instance()->container, true );
170 - }
171 -
172 - /**
173 - * Check if a specific module is activated
174 - */
175 - public static function is_module_active( $module ) {
176 - /**
177 - * Hook 'merchant_module_{$module}_deactivate'
178 - *
179 - * @since 1.0
180 - */
181 - if ( apply_filters( "merchant_module_{$module}_deactivate", false ) ) {
182 - add_filter( "merchant_admin_module_{$module}_list_item_class", static function( $class_name ) {
183 - return $class_name . ' merchant-module-deactivated-by-bp';
184 - } );
185 -
186 - return false;
187 - }
188 -
189 - $modules = get_option( self::$option, array() );
190 -
191 - // Preview Mode
192 - if ( isset( $_GET['preview'] ) && isset( $_GET['module'] ) && $_GET['module'] === $module && current_user_can( 'manage_options' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
193 - return true;
194 - }
195 -
196 - // Preview Mode
197 - $operation_mode = Merchant_Option::get( 'global-settings', 'operating_mode', 'active' );
198 -
199 - if ( 'inactive' === $operation_mode ) {
200 - return false;
201 - } elseif ( 'preview' === $operation_mode && ! current_user_can( 'manage_options' ) ) {
202 - return false;
203 - }
204 -
205 - if ( is_array( $modules ) && array_key_exists( $module, $modules ) && true === $modules[ $module ] ) {
206 - return true;
207 - }
208 -
209 - return false;
210 - }
211 - }
212 -
213 - Merchant_Modules::instance();
214 -
215 -}
1 +<?php
2 +/**
3 + * Merchant_Modules Class.
4 + */
5 +
6 +if ( ! defined( 'ABSPATH' ) ) {
7 + exit; // Exit if accessed directly
8 +}
9 +
10 +if ( ! class_exists( 'Merchant_Modules' ) ) {
11 +
12 + class Merchant_Modules {
13 +
14 + /**
15 + * The modules container.
16 + *
17 + * @var array<string, Merchant_Add_Module>
18 + */
19 + private $container = array();
20 +
21 + /**
22 + * Option name
23 + */
24 + public static $option = 'merchant-modules';
25 +
26 + /**
27 + * The single class instance.
28 + */
29 + private static $instance = null;
30 +
31 + /**
32 + * Instance.
33 + */
34 + public static function instance() {
35 + if ( is_null( self::$instance ) ) {
36 + self::$instance = new self();
37 + }
38 + return self::$instance;
39 + }
40 +
41 + /**
42 + * Constructor.
43 + */
44 + public function __construct() {
45 + add_action( 'wp_ajax_merchant_module_activate', array( $this, 'activate_module' ) );
46 + add_action( 'wp_ajax_merchant_module_deactivate', array( $this, 'deactivate_module' ) );
47 + add_action( 'wp_ajax_merchant_module_feedback', array( $this, 'feedback_module' ) );
48 + }
49 +
50 + /**
51 + * Activate module with Ajax.
52 + */
53 + public function activate_module() {
54 + $nonce = ( isset( $_POST['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
55 + $module = ( isset( $_POST['module'] ) ) ? sanitize_text_field( wp_unslash( $_POST['module'] ) ) : '';
56 +
57 + // Check current user capabilities
58 + if ( ! current_user_can( 'manage_options' ) ) {
59 + wp_send_json_error( 'You are not allowed to do this.' );
60 + }
61 +
62 + if ( wp_verify_nonce( $nonce, 'merchant' ) && ! empty( $module ) ) {
63 + self::set_module_active( $module );
64 + wp_send_json_success();
65 + }
66 +
67 + wp_send_json_error();
68 + }
69 +
70 + /**
71 + * Deactivate module with Ajax.
72 + */
73 + public function deactivate_module() {
74 + $nonce = ( isset( $_POST['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
75 + $module = ( isset( $_POST['module'] ) ) ? sanitize_text_field( wp_unslash( $_POST['module'] ) ) : '';
76 +
77 + // Check current user capabilities
78 + if ( ! current_user_can( 'manage_options' ) ) {
79 + wp_send_json_error( 'You are not allowed to do this.' );
80 + }
81 +
82 + if ( wp_verify_nonce( $nonce, 'merchant' ) && ! empty( $module ) ) {
83 + self::set_module_inactive( $module );
84 + wp_send_json_success();
85 + }
86 +
87 + wp_send_json_error();
88 + }
89 +
90 + /**
91 + * Feedback module with Ajax.
92 + */
93 + public function feedback_module() {
94 + $nonce = ( isset( $_POST['nonce'] ) ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
95 + $subject = ( isset( $_POST['subject'] ) ) ? sanitize_text_field( wp_unslash( $_POST['subject'] ) ) : '';
96 + $message = ( isset( $_POST['message'] ) ) ? sanitize_textarea_field( wp_unslash( $_POST['message'] ) ) : '';
97 + $module = ( isset( $_POST['module'] ) ) ? sanitize_text_field( wp_unslash( $_POST['module'] ) ) : '';
98 + $from = get_bloginfo( 'admin_email' );
99 +
100 + // Check current user capabilities
101 + if ( ! current_user_can( 'manage_options' ) ) {
102 + wp_send_json_error( 'You are not allowed to do this.' );
103 + }
104 +
105 + if ( wp_verify_nonce( $nonce, 'merchant' ) ) {
106 + $response = wp_remote_post( 'https://athemes.com/merchant/', array(
107 + 'body' => array(
108 + 'mailsender' => true,
109 + 'from' => $from,
110 + 'subject' => $subject,
111 + 'message' => $message,
112 + 'module' => $module,
113 + ),
114 + ) );
115 +
116 + if ( is_wp_error( $response ) ) {
117 + wp_send_json_error();
118 + }
119 +
120 + wp_send_json_success();
121 + }
122 +
123 + wp_send_json_error();
124 + }
125 +
126 + /**
127 + * Creates and adds the module instance to the container.
128 + *
129 + * @param Merchant_Add_Module $module The module instance.
130 + *
131 + * @return void
132 + */
133 + public static function create_module( Merchant_Add_Module $module ) {
134 + static::instance()->container[ $module->module_id ] = $module;
135 + }
136 +
137 + /**
138 + * Get the module instance.
139 + *
140 + * @param string $module_id The module ID.
141 + *
142 + * @return Merchant_Add_Module|null The module instance, or null if not registered.
143 + */
144 + public static function get_module( $module_id ) {
145 + return static::instance()->container[ $module_id ] ?? null;
146 + }
147 +
148 + /**
149 + * Determines if a module has already been added to the container.
150 + *
151 + * @param string $module_id The module ID.
152 + *
153 + * @return bool
154 + */
155 + public static function is_module_created( $module_id ) {
156 + return isset( static::instance()->container[ $module_id ] );
157 + }
158 +
159 + /**
160 + * Activate a module.
161 + *
162 + * Sets the module status to active in the database and fires
163 + * the merchant_admin_module_activated action hook.
164 + *
165 + * @param string $module_id The module identifier.
166 + *
167 + * @return void
168 + *
169 + * @since 2.3.0
170 + */
171 + public static function set_module_active( $module_id ) {
172 + $modules = get_option( self::$option, array() );
173 +
174 + $modules[ $module_id ] = true;
175 +
176 + update_option( self::$option, $modules );
177 +
178 + /**
179 + * Fires when a module is activated.
180 + *
181 + * @param string $module_id The module identifier.
182 + *
183 + * @since 1.9.3
184 + */
185 + do_action( 'merchant_admin_module_activated', $module_id );
186 + }
187 +
188 + /**
189 + * Deactivate a module.
190 + *
191 + * Sets the module status to inactive in the database and fires
192 + * the merchant_admin_module_deactivated action hook.
193 + *
194 + * @param string $module_id The module identifier.
195 + *
196 + * @return void
197 + *
198 + * @since 2.3.0
199 + */
200 + public static function set_module_inactive( $module_id ) {
201 + $modules = get_option( self::$option, array() );
202 +
203 + $modules[ $module_id ] = false;
204 +
205 + update_option( self::$option, $modules );
206 +
207 + /**
208 + * Fires when a module is deactivated.
209 + *
210 + * @param string $module_id The module identifier.
211 + *
212 + * @since 1.9.3
213 + */
214 + do_action( 'merchant_admin_module_deactivated', $module_id );
215 + }
216 +
217 + /**
218 + * Check if a specific module is activated
219 + */
220 + public static function is_module_active( $module ) {
221 + /**
222 + * Hook 'merchant_module_{$module}_deactivate'
223 + *
224 + * @since 1.0
225 + */
226 + if ( apply_filters( "merchant_module_{$module}_deactivate", false ) ) {
227 + add_filter( "merchant_admin_module_{$module}_list_item_class", static function( $class_name ) {
228 + return $class_name . ' merchant-module-deactivated-by-bp';
229 + } );
230 +
231 + if ( isset( $_GET['module'] ) && $_GET['module'] === $module ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
232 + add_filter( "merchant_admin_module_{$module}_activate_button_class", static function( $class_name ) {
233 + if ( strpos( $class_name, 'merchant-module-deactivated-by-bp' ) !== false ) {
234 + return $class_name;
235 + }
236 +
237 + return $class_name . ' merchant-module-deactivated-by-bp';
238 + } );
239 + }
240 +
241 + return false;
242 + }
243 +
244 + $modules = get_option( self::$option, array() );
245 +
246 + // Preview Mode
247 + if ( isset( $_GET['preview'] ) && isset( $_GET['module'] ) && $_GET['module'] === $module && current_user_can( 'manage_options' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
248 + return true;
249 + }
250 +
251 + // Preview Mode
252 + $operation_mode = Merchant_Option::get( 'global-settings', 'operating_mode', 'active' );
253 +
254 + if ( 'inactive' === $operation_mode ) {
255 + return false;
256 + }
257 +
258 + if ( 'preview' === $operation_mode ) {
259 + if ( ! function_exists( 'wp_get_current_user' ) ) {
260 + include ABSPATH . 'wp-includes/pluggable.php';
261 + }
262 + if ( ! current_user_can( 'manage_options' ) ) {
263 + return false;
264 + }
265 + }
266 +
267 + if ( is_array( $modules ) && array_key_exists( $module, $modules ) && true === $modules[ $module ] ) {
268 + return true;
269 + }
270 +
271 + return false;
272 + }
273 + }
274 +
275 + Merchant_Modules::instance();
276 +
277 +}