PluginProbe
WowOptin: Next-Gen Popup Maker – Create Stunning Popups and Optins for Lead Generation / trunk
WowOptin: Next-Gen Popup Maker – Create Stunning Popups and Optins for Lead Generation vtrunk
1.4.48 1.4.47 1.4.46 1.4.45 1.4.44 1.4.43 1.4.42 1.4.41 1.4.40 1.4.39 1.4.38 1.4.37 1.4.36 1.1.2 1.2.0 1.2.1 1.2.2 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 All 64 releases
optin / includes / class-xpo.php

class-xpo.php in WowOptin: Next-Gen Popup Maker – Create Stunning Popups and Optins for Lead Generation trunk, at includes/class-xpo.php

400 lines 11.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phcps:ignore
2
3 namespace OPTN\Includes;
4
5 use OPTN\Includes\Utils\Utils;
6
7 defined( 'ABSPATH' ) || exit;
8
9 /**
10 * Core class for managing plugin actions and integrations.
11 */
12 class Xpo {
13
14 /**
15 * Checks if the license is active.
16 *
17 * @return boolean
18 */
19 public static function is_lc_active() {
20 if ( defined( 'OPTN_PRO_VERSION' ) ) {
21 $license_data = get_option( 'edd_optin_license_data', array() );
22 return isset( $license_data['license'] ) && 'valid' === $license_data['license'];
23 }
24 return false;
25 }
26
27 /**
28 * Checks if the license has expired.
29 *
30 * @return bool True if the license is expired, otherwise false.
31 */
32 public static function is_lc_expired() {
33 $license_data = get_option( 'edd_optin_license_data', array() );
34 return isset( $license_data['license'] ) && 'expired' === $license_data['license'];
35 }
36
37 /**
38 * Get renew link
39 *
40 * @return string
41 */
42 public static function get_renew_link() {
43 return 'https://account.wpxpo.com/checkout/?edd_license_key=' . Utils::get_license_key() . '&renew=1';
44 }
45
46 /**
47 * Get Option Value bypassing cache
48 * Inspired By WordPress Core get_option
49 *
50 * @param string $option Option Name.
51 * @param boolean $default_value option default value.
52 * @return mixed
53 */
54 public static function get_option_without_cache( $option, $default_value = false ) {
55 global $wpdb;
56
57 if ( is_scalar( $option ) ) {
58 $option = trim( $option );
59 }
60
61 if ( empty( $option ) ) {
62 return false;
63 }
64
65 $value = $default_value;
66
67 $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
68
69 if ( is_object( $row ) ) {
70 $value = $row->option_value;
71 } else {
72 return apply_filters( "optn_default_option_{$option}", $default_value, $option );
73 }
74
75 return apply_filters( "optn_option_{$option}", maybe_unserialize( $value ), $option );
76 }
77
78 /**
79 * Add option without adding to the cache
80 * Inspired By WordPress Core set_transient
81 *
82 * @since v.1.0.7
83 * @param string $option option name.
84 * @param string $value option value.
85 * @param string $autoload whether to load WordPress startup.
86 * @return bool
87 */
88 public static function add_option_without_cache( $option, $value = '', $autoload = 'yes' ) {
89 global $wpdb;
90
91 if ( is_scalar( $option ) ) {
92 $option = trim( $option );
93 }
94
95 if ( empty( $option ) ) {
96 return false;
97 }
98
99 wp_protect_special_option( $option );
100
101 if ( is_object( $value ) ) {
102 $value = clone $value;
103 }
104
105 $value = sanitize_option( $option, $value );
106
107 /*
108 * Make sure the option doesn't already exist.
109 */
110
111 if ( apply_filters( "optn_default_option_{$option}", false, $option, false ) !== self::get_option_without_cache( $option ) ) {
112 return false;
113 }
114
115 $serialized_value = maybe_serialize( $value );
116 $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
117
118 $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
119 if ( ! $result ) {
120 return false;
121 }
122
123 return true;
124 }
125
126 /**
127 * Get Transient Value bypassing cache
128 * Inspired By WordPress Core get_transient
129 *
130 * @since v.1.0.7
131 * @param string $transient Transient Name.
132 * @return mixed
133 */
134 public static function get_transient_without_cache( $transient ) {
135 $transient_option = '_transient_' . $transient;
136 $transient_timeout = '_transient_timeout_' . $transient;
137 $timeout = self::get_option_without_cache( $transient_timeout );
138
139 if ( false !== $timeout && $timeout < time() ) {
140 delete_option( $transient_option );
141 delete_option( $transient_timeout );
142 $value = false;
143 }
144
145 if ( ! isset( $value ) ) {
146 $value = self::get_option_without_cache( $transient_option );
147 }
148
149 return apply_filters( "optn_transient_{$transient}", $value, $transient );
150 }
151
152 /**
153 * Set transient without adding to the cache
154 * Inspired By WordPress Core set_transient
155 *
156 * @since v.1.0.7
157 * @param string $transient Transient Name.
158 * @param mixed $value Transient Value.
159 * @param integer $expiration Time until expiration in seconds.
160 * @return bool
161 */
162 public static function set_transient_without_cache( $transient, $value, $expiration = 0 ) {
163 $expiration = (int) $expiration;
164
165 $transient_timeout = '_transient_timeout_' . $transient;
166 $transient_option = '_transient_' . $transient;
167
168 $result = false;
169
170 if ( false === self::get_option_without_cache( $transient_option ) ) {
171 $autoload = 'yes';
172 if ( $expiration ) {
173 $autoload = 'no';
174 self::add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
175 }
176 $result = self::add_option_without_cache( $transient_option, $value, $autoload );
177 } else {
178 /*
179 * If expiration is requested, but the transient has no timeout option,
180 * delete, then re-create transient rather than update.
181 */
182 $update = true;
183
184 if ( $expiration ) {
185 if ( false === self::get_option_without_cache( $transient_timeout ) ) {
186 delete_option( $transient_option );
187 self::add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
188 $result = self::add_option_without_cache( $transient_option, $value, 'no' );
189 $update = false;
190 } else {
191 update_option( $transient_timeout, time() + $expiration );
192 }
193 }
194
195 if ( $update ) {
196 $result = update_option( $transient_option, $value );
197 }
198 }
199
200 return $result;
201 }
202
203 /**
204 * Generate UTM Link.
205 *
206 * @param array $params params.
207 * @return string
208 */
209 public static function generate_utm_link( $params = array() ) {
210 $default_config = array(
211 'summer' => array(
212 'source' => 'db-wowoptin-notice',
213 'medium' => 'summer-sale',
214 'campaign' => 'wowoptin-dashboard',
215 ),
216 );
217
218 // Step 1: Get parameters.
219 $base_url = $params['url'] ?? 'https://www.wowoptin.com';
220 $utm_key = $params['utmKey'] ?? null;
221 $affiliate = $params['affiliate'] ?? apply_filters( 'optn_affiliate_id', '' );
222 $hash = $params['hash'] ?? '#pricing';
223 $custom_config = $params['config'] ?? null;
224
225 $parsed_url = wp_parse_url( $base_url );
226 $scheme = $parsed_url['scheme'] ?? 'https';
227 $host = $parsed_url['host'] ?? '';
228 $path = $parsed_url['path'] ?? '';
229 $query = array();
230
231 // Step 3: Extract existing query params if present.
232 if ( isset( $parsed_url['query'] ) ) {
233 parse_str( $parsed_url['query'], $query );
234 }
235
236 // Step 4: Determine config.
237 $utm_config = $custom_config ?? ( $utm_key && isset( $default_config[ $utm_key ] ) ? $default_config[ $utm_key ] : array() );
238
239 // Step 5: Add UTM parameters.
240 if ( ! empty( $utm_config ) ) {
241 $query = array_merge(
242 $query,
243 array(
244 'utm_source' => $utm_config['source'],
245 'utm_medium' => $utm_config['medium'],
246 'utm_campaign' => $utm_config['campaign'],
247 )
248 );
249 }
250
251 // Step 6: Add affiliate if present.
252 if ( $affiliate ) {
253 $query['ref'] = $affiliate;
254 }
255
256 // Step 7: Reconstruct URL.
257 $final_url = $scheme . '://' . $host . $path;
258
259 if ( ! empty( $query ) ) {
260 $final_url .= '?' . http_build_query( $query );
261 }
262
263 if ( $hash ) {
264 $final_url .= '#' . ltrim( $hash, '#' );
265 }
266
267 return $final_url;
268 }
269
270
271 /**
272 * Get WOW Products Details.
273 *
274 * @return array
275 */
276 public static function get_wow_products_details() {
277 return array(
278 'products' => array(
279 'post_x' => file_exists( WP_PLUGIN_DIR . '/ultimate-post/ultimate-post.php' ),
280 'wow_store' => file_exists( WP_PLUGIN_DIR . '/product-blocks/product-blocks.php' ),
281 'wow_revenue' => file_exists( WP_PLUGIN_DIR . '/revenue/revenue.php' ),
282 'wholesale_x' => file_exists( WP_PLUGIN_DIR . '/wholesalex/wholesalex.php' ),
283 'wow_addon' => file_exists( WP_PLUGIN_DIR . '/product-addons/product-addons.php' ),
284 'wow_shipping' => file_exists( WP_PLUGIN_DIR . '/wow-table-rate-shipping/wow-table-rate-shipping.php' ),
285 'wow_invoice' => file_exists( WP_PLUGIN_DIR . '/wow-pdf-invoices-packing-slips/wow-pdf-invoices-packing-slips.php' ),
286 ),
287 'products_active' => array(
288 'post_x' => defined( 'ULTP_VER' ),
289 'wow_store' => defined( 'WOPB_VER' ),
290 'wow_revenue' => defined( 'REVENUE_VER' ),
291 'wholesale_x' => defined( 'WHOLESALEX_VER' ),
292 'wow_addon' => defined( 'PRAD_VER' ),
293 'wow_shipping' => defined( 'WTRS_VER' ),
294 'wow_invoice' => defined( 'WINV_VER' ),
295 ),
296 );
297 }
298
299
300 /**
301 * Installs and activates a plugin by its name only.
302 *
303 * @param string $name The name or slug of the plugin to install and activate.
304 */
305 public static function install_and_active_plugin( $name ) {
306 $to_r = array( 'done' => true );
307 $plugin_slug = $name;
308 switch ( $name ) {
309 case 'post_x':
310 $plugin_slug = 'ultimate-post';
311 break;
312 case 'wow_store':
313 $plugin_slug = 'product-blocks';
314 break;
315 case 'wow_optin':
316 $plugin_slug = 'optin';
317 break;
318 case 'wow_revenue':
319 $plugin_slug = 'revenue';
320 break;
321 case 'wholesale_x':
322 $plugin_slug = 'wholesalex';
323 break;
324 case 'wow_addon':
325 $plugin_slug = 'product-addons';
326 break;
327 case 'wow_shipping':
328 $plugin_slug = 'wow-table-rate-shipping';
329 break;
330 case 'wow_invoice':
331 $plugin_slug = 'wow-pdf-invoices-packing-slips';
332 break;
333 }
334
335 if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug . '/' . $plugin_slug . '.php' ) ) {
336 $to_r = self::plugin_install( $plugin_slug . '/' . $plugin_slug . '.php', $plugin_slug );
337 } else {
338 activate_plugin( $plugin_slug . '/' . $plugin_slug . '.php' );
339 }
340 return $to_r;
341 }
342
343 /**
344 * Installs a plugin based on the provided plugin file and slug.
345 *
346 * This function is expected to handle the logic required to install a plugin,
347 * such as downloading, unpacking, and activating the plugin using the provided
348 * plugin file and slug.
349 *
350 * @param string $plugin The plugin file path or identifier (e.g., 'plugin-directory/plugin-file.php').
351 * @param string $slug The plugin slug (typically the directory name of the plugin).
352 */
353 public static function plugin_install( $plugin, $slug ) {
354 include ABSPATH . 'wp-admin/includes/plugin-install.php';
355 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
356
357 if ( ! class_exists( 'Plugin_Upgrader' ) ) {
358 include ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php';
359 }
360 if ( ! class_exists( 'WP_Ajax_Upgrader_Skin' ) ) {
361 include ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php';
362 }
363
364 $api = plugins_api(
365 'plugin_information',
366 array(
367 'slug' => $slug,
368 'fields' => array(
369 'short_description' => false,
370 'sections' => false,
371 'requires' => false,
372 'rating' => false,
373 'ratings' => false,
374 'downloaded' => false,
375 'last_updated' => false,
376 'added' => false,
377 'tags' => false,
378 'compatibility' => false,
379 'homepage' => false,
380 'donate_link' => false,
381 ),
382 )
383 );
384
385 if ( is_wp_error( $api ) ) {
386 wp_die( $api ); //phpcs:ignore
387 }
388
389 $upgrader = new \Plugin_Upgrader( new \WP_Ajax_Upgrader_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) );
390 $install_result = $upgrader->install( $api->download_link );
391
392 if ( ! is_wp_error( $install_result ) ) {
393 activate_plugin( $plugin );
394 return array( 'done' => false );
395 }
396
397 return array( 'done' => true );
398 }
399 }
400