PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.41
Post Grid Gutenberg Blocks – PostX v5.0.41
5.0.41 5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 All 238 releases
ultimate-post / includes / durbin / class-xpo.php

class-xpo.php in Post Grid Gutenberg Blocks – PostX 5.0.41, at includes/durbin/class-xpo.php

518 lines 15.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore
2
3 namespace ULTP\Includes\Durbin;
4
5 defined( 'ABSPATH' ) || exit;
6
7 /**
8 * Core class for managing plugin actions and integrations.
9 */
10 class Xpo {
11
12 /**
13 * Gets license key
14 *
15 * @return string
16 */
17 public static function get_lc_key() {
18 return get_option( 'edd_ultp_license_key', '' );
19 }
20
21 public static function is_lc_active() {
22 if ( defined( 'ULTP_PRO_VER' ) ) {
23 $license_data = get_option( 'edd_ultp_license_data', array() );
24 return isset( $license_data['license'] ) && 'valid' === $license_data['license'];
25 }
26 return false;
27 }
28
29 /**
30 * Checks if the license has expired.
31 *
32 * This method checks the stored license data in the WordPress options table
33 * and determines if the license status is set to 'expired'. It returns `true`
34 * if the license is expired, otherwise `false`.
35 *
36 * @return bool True if the license is expired, otherwise false.
37 */
38 public static function is_lc_expired() {
39 $license_data = get_option( 'edd_ultp_license_data', array() );
40 return isset( $license_data['license'] ) && 'expired' === $license_data['license'];
41 }
42
43 /**
44 * Get Option Value bypassing cache
45 * Inspired By WordPress Core get_option
46 *
47 * @since v.1.0.7
48 * @param string $option Option Name.
49 * @param boolean $default_value option default value.
50 * @return mixed
51 */
52 public static function get_option_without_cache( $option, $default_value = false ) {
53 global $wpdb;
54
55 if ( is_scalar( $option ) ) {
56 $option = trim( $option );
57 }
58
59 if ( empty( $option ) ) {
60 return false;
61 }
62
63 $value = $default_value;
64
65 $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
66
67 if ( is_object( $row ) ) {
68 $value = $row->option_value;
69 } else {
70 return apply_filters( "ultp_default_option_{$option}", $default_value, $option );
71 }
72
73 return apply_filters( "ultp_option_{$option}", maybe_unserialize( $value ), $option );
74 }
75
76 /**
77 * Add option without adding to the cache
78 * Inspired By WordPress Core set_transient
79 *
80 * @since v.1.0.7
81 * @param string $option option name.
82 * @param string $value option value.
83 * @param string $autoload whether to load WordPress startup.
84 * @return bool
85 */
86 public static function add_option_without_cache( $option, $value = '', $autoload = 'yes' ) {
87 global $wpdb;
88
89 if ( is_scalar( $option ) ) {
90 $option = trim( $option );
91 }
92
93 if ( empty( $option ) ) {
94 return false;
95 }
96
97 wp_protect_special_option( $option );
98
99 if ( is_object( $value ) ) {
100 $value = clone $value;
101 }
102
103 $value = sanitize_option( $option, $value );
104
105 /*
106 * Make sure the option doesn't already exist.
107 */
108
109 if ( apply_filters( "ultp_default_option_{$option}", false, $option, false ) !== self::get_option_without_cache( $option ) ) {
110 return false;
111 }
112
113 $serialized_value = maybe_serialize( $value );
114 $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
115
116 $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
117 if ( ! $result ) {
118 return false;
119 }
120
121 return true;
122 }
123
124 /**
125 * Get Transient Value bypassing cache
126 * Inspired By WordPress Core get_transient
127 *
128 * @since v.1.0.7
129 * @param string $transient Transient Name.
130 * @return mixed
131 */
132 public static function get_transient_without_cache( $transient ) {
133 $transient_option = '_transient_' . $transient;
134 $transient_timeout = '_transient_timeout_' . $transient;
135 $timeout = self::get_option_without_cache( $transient_timeout );
136
137 if ( false !== $timeout && $timeout < time() ) {
138 delete_option( $transient_option );
139 delete_option( $transient_timeout );
140 $value = false;
141 }
142
143 if ( ! isset( $value ) ) {
144 $value = self::get_option_without_cache( $transient_option );
145 }
146
147 return apply_filters( "ultp_transient_{$transient}", $value, $transient );
148 }
149
150 /**
151 * Set transient without adding to the cache
152 * Inspired By WordPress Core set_transient
153 *
154 * @since v.1.0.7
155 * @param string $transient Transient Name.
156 * @param mixed $value Transient Value.
157 * @param integer $expiration Time until expiration in seconds.
158 * @return bool
159 */
160 public static function set_transient_without_cache( $transient, $value, $expiration = 0 ) {
161
162 $expiration = (int) $expiration;
163
164 $transient_timeout = '_transient_timeout_' . $transient;
165 $transient_option = '_transient_' . $transient;
166
167 $result = false;
168
169 if ( false === self::get_option_without_cache( $transient_option ) ) {
170 $autoload = 'yes';
171 if ( $expiration ) {
172 $autoload = 'no';
173 self::add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
174 }
175 $result = self::add_option_without_cache( $transient_option, $value, $autoload );
176 } else {
177 /*
178 * If expiration is requested, but the transient has no timeout option,
179 * delete, then re-create transient rather than update.
180 */
181 $update = true;
182
183 if ( $expiration ) {
184 if ( false === self::get_option_without_cache( $transient_timeout ) ) {
185 delete_option( $transient_option );
186 self::add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
187 $result = self::add_option_without_cache( $transient_option, $value, 'no' );
188 $update = false;
189 } else {
190 update_option( $transient_timeout, time() + $expiration );
191 }
192 }
193
194 if ( $update ) {
195 $result = update_option( $transient_option, $value );
196 }
197 }
198
199 return $result;
200 }
201
202 public static function generate_utm_link( $params = array() ) {
203 $default_config = array(
204 'example' => array(
205 'source' => 'db-postx-featurename',
206 'medium' => 'block-feature',
207 'campaign' => 'postx-dashboard',
208 ),
209 'summer_db' => array(
210 'source' => 'db-postx-notice',
211 'medium' => 'summer-sale',
212 'campaign' => 'postx-dashboard',
213 ),
214 'plugin_dir_pro' => array(
215 'source' => 'db-postx-plugin',
216 'medium' => 'upgrade-pro',
217 'campaign' => 'postx-dashboard',
218 ),
219 'post_type_page' => array(
220 'source' => 'db-postx-posttype',
221 'medium' => 'upgrade-pro',
222 'campaign' => 'postx-dashboard',
223 ),
224 'plugin_dir_support' => array(
225 'source' => 'db-postx-pluginmeta',
226 'medium' => 'meta-support',
227 'campaign' => 'postx-dashboard',
228 ),
229 'dashboard_go_pro' => array(
230 'source' => 'db-postx-submenu',
231 'medium' => 'left-menu-upgrade',
232 'campaign' => 'postx-dashboard',
233 ),
234 'sub_menu' => array(
235 'source' => 'db-postx-submenu',
236 'medium' => 'upgrade-pro',
237 'campaign' => 'postx-dashboard',
238 ),
239 'content_notice' => array(
240 'source' => 'db-postx-notice',
241 'medium' => 'spring-sale',
242 'campaign' => 'postx-dashboard',
243 ),
244 'summer_sale_meta' => array(
245 'source' => 'db-postx-plugin-meta',
246 'medium' => 'summer-sale',
247 'campaign' => 'postx-dashboard',
248 ),
249 'base_price_meta' => array(
250 'source' => 'db-postx-plugin-meta',
251 'medium' => 'base-price',
252 'campaign' => 'postx-dashboard',
253 ),
254
255 // Flash sale.
256 'flash_sale_content' => array(
257 'source' => 'db-postx-notice-content',
258 'medium' => 'summer-flash-sale',
259 'campaign' => 'postx-dashboard',
260 ),
261 'flash_sale' => array(
262 'source' => 'db-postx-notice',
263 'medium' => 'summer-flash-sale',
264 'campaign' => 'postx-dashboard',
265 ),
266 'flash_sale_meta' => array(
267 'source' => 'db-postx-plugin-meta',
268 'medium' => 'summer-flash-sale',
269 'campaign' => 'postx-dashboard',
270 ),
271 // Massive Sale
272 'massive_sale_content' => array(
273 'source' => 'db-postx-notice-content',
274 'medium' => 'summer-massive-sale',
275 'campaign' => 'postx-dashboard',
276 ),
277 'massive_sale' => array(
278 'source' => 'db-postx-notice',
279 'medium' => 'summer-massive-sale',
280 'campaign' => 'postx-dashboard',
281 ),
282 'massive_sale_meta' => array(
283 'source' => 'db-postx-plugin-meta',
284 'medium' => 'summer-massive-sale',
285 'campaign' => 'postx-dashboard',
286 ),
287 // Surprise Sale
288 'surprise_sale_content' => array(
289 'source' => 'db-postx-notice-content',
290 'medium' => 'summer-surprise-sale',
291 'campaign' => 'postx-dashboard',
292 ),
293 'surprise_sale' => array(
294 'source' => 'db-postx-notice',
295 'medium' => 'summer-surprise-sale',
296 'campaign' => 'postx-dashboard',
297 ),
298 'surprise_sale_meta' => array(
299 'source' => 'db-postx-plugin-meta',
300 'medium' => 'summer-surprise-sale',
301 'campaign' => 'postx-dashboard',
302 ),
303 // Final Hours Sale
304 'final_hours_content' => array(
305 'source' => 'db-postx-notice-content',
306 'medium' => 'summer-final-sale',
307 'campaign' => 'postx-dashboard',
308 ),
309 'final_hour' => array(
310 'source' => 'db-postx-notice',
311 'medium' => 'summer-final-sale',
312 'campaign' => 'postx-dashboard',
313 ),
314 'final_hour_meta' => array(
315 'source' => 'db-postx-plugin-meta',
316 'medium' => 'summer-final-sale',
317 'campaign' => 'postx-dashboard',
318 ),
319 );
320
321 // Step 1: Get parameters
322 $base_url = $params['url'] ?? 'https://www.wpxpo.com/postx/';
323 $utm_key = $params['utmKey'] ?? null;
324 $affiliate = $params['affiliate'] ?? apply_filters( 'ultp_affiliate_id', '' );
325 $hash = $params['hash'] ?? 'pricing';
326 $custom_config = $params['config'] ?? null;
327
328 $parsed_url = parse_url( $base_url );
329 $scheme = $parsed_url['scheme'] ?? 'https';
330 $host = $parsed_url['host'] ?? '';
331 $path = $parsed_url['path'] ?? '';
332 $query = array();
333
334 // Step 3: Extract existing query params if present
335 if ( isset( $parsed_url['query'] ) ) {
336 parse_str( $parsed_url['query'], $query );
337 }
338
339 // Step 4: Determine config
340 $utm_config = $custom_config ?? ( $utm_key && isset( $default_config[ $utm_key ] ) ? $default_config[ $utm_key ] : array() );
341
342 // Step 5: Add UTM parameters
343 if ( ! empty( $utm_config ) ) {
344 $query = array_merge(
345 $query,
346 array(
347 'utm_source' => $utm_config['source'],
348 'utm_medium' => $utm_config['medium'],
349 'utm_campaign' => $utm_config['campaign'],
350 )
351 );
352 }
353
354 // Step 6: Add affiliate if present
355 if ( $affiliate ) {
356 $query['ref'] = $affiliate;
357 }
358
359 // Step 7: Reconstruct URL
360 $final_url = $scheme . '://' . $host . $path;
361
362 if ( ! empty( $query ) ) {
363 $final_url .= '?' . http_build_query( $query );
364 }
365
366 if ( $hash ) {
367 $final_url .= '#' . $hash;
368 }
369
370 return $final_url;
371 }
372
373
374 /**
375 * Get WOW Products Details
376 *
377 * @return array
378 */
379 public static function get_wow_products_details() {
380 return array(
381 'products' => array(
382 'wow_shipping' => file_exists( WP_PLUGIN_DIR . '/wow-table-rate-shipping/wow-table-rate-shipping.php' ),
383 'post_x' => file_exists( WP_PLUGIN_DIR . '/ultimate-post/ultimate-post.php' ),
384 'wow_store' => file_exists( WP_PLUGIN_DIR . '/product-blocks/product-blocks.php' ),
385 'wow_optin' => file_exists( WP_PLUGIN_DIR . '/optin/optin.php' ),
386 'wow_revenue' => file_exists( WP_PLUGIN_DIR . '/revenue/revenue.php' ),
387 'wholesale_x' => file_exists( WP_PLUGIN_DIR . '/wholesalex/wholesalex.php' ),
388 'wow_addon' => file_exists( WP_PLUGIN_DIR . '/product-addons/product-addons.php' ),
389 'wow_invoice' => file_exists( WP_PLUGIN_DIR . '/wow-pdf-invoices-packing-slips/wow-pdf-invoices-packing-slips.php' ),
390 'wow_recommend' => file_exists( WP_PLUGIN_DIR . '/wow-ai-product-recommendations/wow-ai-product-recommendations.php' ),
391 ),
392 'products_active' => array(
393 'wow_shipping' => defined( 'WTRS_VER' ),
394 'post_x' => defined( 'ULTP_VER' ),
395 'wow_store' => defined( 'WOPB_VER' ),
396 'wow_optin' => defined( 'OPTN_VERSION' ),
397 'wow_revenue' => defined( 'REVENUE_VER' ),
398 'wholesale_x' => defined( 'WHOLESALEX_VER' ),
399 'wow_addon' => defined( 'PRAD_VER' ),
400 'wow_invoice' => defined( 'WINV_VER' ),
401 'wow_recommend' => defined( 'PRECO_VER' ),
402 ),
403 );
404 }
405
406
407 /**
408 * Installs and activates a plugin by its name only.
409 *
410 * @param string $name The name or slug of the plugin to install and activate.
411 */
412 public static function install_and_active_plugin( $name ) {
413 $to_r = array( 'done' => true );
414 $plugin_slug = '';
415 switch ( $name ) {
416 case 'wow_shipping':
417 $plugin_slug = 'wow-table-rate-shipping';
418 break;
419 case 'post_x':
420 $plugin_slug = 'ultimate-post';
421 break;
422 case 'wow_store':
423 $plugin_slug = 'product-blocks';
424 break;
425 case 'wow_optin':
426 $plugin_slug = 'optin';
427 break;
428 case 'wow_revenue':
429 $plugin_slug = 'revenue';
430 break;
431 case 'wholesale_x':
432 $plugin_slug = 'wholesalex';
433 break;
434 case 'wow_addon':
435 $plugin_slug = 'product-addons';
436 break;
437 case 'woocommerce':
438 $plugin_slug = 'woocommerce';
439 break;
440 case 'wow_invoice':
441 $plugin_slug = 'wow-pdf-invoices-packing-slips';
442 $active_url = admin_url( 'admin.php?page=winv-dashboard#overview' );
443 break;
444 case 'wow_recommend':
445 $plugin_slug = 'wow-ai-product-recommendations';
446 break;
447 }
448
449 if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug . '/' . $plugin_slug . '.php' ) ) {
450 $to_r = self::plugin_install( $plugin_slug . '/' . $plugin_slug . '.php', $plugin_slug );
451 } else {
452 activate_plugin( $plugin_slug . '/' . $plugin_slug . '.php' );
453 }
454 return $to_r;
455 }
456
457 /**
458 * Installs a plugin based on the provided plugin file and slug.
459 *
460 * This function is expected to handle the logic required to install a plugin,
461 * such as downloading, unpacking, and activating the plugin using the provided
462 * plugin file and slug.
463 *
464 * @param string $plugin The plugin file path or identifier (e.g., 'plugin-directory/plugin-file.php').
465 * @param string $slug The plugin slug (typically the directory name of the plugin).
466 */
467 public static function plugin_install( $plugin, $slug ) {
468 include ABSPATH . 'wp-admin/includes/plugin-install.php';
469 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
470
471 if ( ! class_exists( 'Plugin_Upgrader' ) ) {
472 include ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php';
473 }
474 if ( ! class_exists( 'WP_Ajax_Upgrader_Skin' ) ) {
475 include ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php';
476 }
477
478 $api = plugins_api(
479 'plugin_information',
480 array(
481 'slug' => $slug,
482 'fields' => array(
483 'short_description' => false,
484 'sections' => false,
485 'requires' => false,
486 'rating' => false,
487 'ratings' => false,
488 'downloaded' => false,
489 'last_updated' => false,
490 'added' => false,
491 'tags' => false,
492 'compatibility' => false,
493 'homepage' => false,
494 'donate_link' => false,
495 ),
496 )
497 );
498
499 if ( is_wp_error( $api ) ) {
500 wp_die( $api ); //phpcs:ignore
501 }
502 $title = '';
503 $url = '';
504 $nonce = '';
505 $upgrader = new \Plugin_Upgrader( new \WP_Ajax_Upgrader_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) );
506 $install_result = $upgrader->install( $api->download_link );
507
508 if ( ! is_wp_error( $install_result ) ) {
509 activate_plugin( $plugin );
510 return array(
511 'done' => false,
512 );
513 }
514
515 return array( 'done' => true );
516 }
517 }
518