PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.23
Post Grid Gutenberg Blocks – PostX v5.0.23
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.23, at includes/durbin/class-xpo.php

494 lines 14.5 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' => 'black-friday-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
245 // Flash sale.
246 'flash_sale_content' => array(
247 'source' => 'db-postx-notice-content',
248 'medium' => 'summer-flash-sale',
249 'campaign' => 'postx-dashboard',
250 ),
251 'flash_sale' => array(
252 'source' => 'db-postx-notice',
253 'medium' => 'summer-flash-sale',
254 'campaign' => 'postx-dashboard',
255 ),
256 'flash_sale_meta' => array(
257 'source' => 'db-postx-plugin-meta',
258 'medium' => 'summer-flash-sale',
259 'campaign' => 'postx-dashboard',
260 ),
261 // Massive Sale
262 'massive_sale_content' => array(
263 'source' => 'db-postx-notice-content',
264 'medium' => 'summer-massive-sale',
265 'campaign' => 'postx-dashboard',
266 ),
267 'massive_sale' => array(
268 'source' => 'db-postx-notice',
269 'medium' => 'summer-massive-sale',
270 'campaign' => 'postx-dashboard',
271 ),
272 'massive_sale_meta' => array(
273 'source' => 'db-postx-plugin-meta',
274 'medium' => 'summer-massive-sale',
275 'campaign' => 'postx-dashboard',
276 ),
277 // Surprise Sale
278 'surprise_sale_content' => array(
279 'source' => 'db-postx-notice-content',
280 'medium' => 'summer-surprise-sale',
281 'campaign' => 'postx-dashboard',
282 ),
283 'surprise_sale' => array(
284 'source' => 'db-postx-notice',
285 'medium' => 'summer-surprise-sale',
286 'campaign' => 'postx-dashboard',
287 ),
288 'surprise_sale_meta' => array(
289 'source' => 'db-postx-plugin-meta',
290 'medium' => 'summer-surprise-sale',
291 'campaign' => 'postx-dashboard',
292 ),
293 // Final Hours Sale
294 'final_hours_content' => array(
295 'source' => 'db-postx-notice-content',
296 'medium' => 'summer-final-sale',
297 'campaign' => 'postx-dashboard',
298 ),
299 'final_hour' => array(
300 'source' => 'db-postx-notice',
301 'medium' => 'summer-final-sale',
302 'campaign' => 'postx-dashboard',
303 ),
304 'final_hour_meta' => array(
305 'source' => 'db-postx-plugin-meta',
306 'medium' => 'summer-final-sale',
307 'campaign' => 'postx-dashboard',
308 ),
309 );
310
311 // Step 1: Get parameters
312 $base_url = $params['url'] ?? 'https://www.wpxpo.com/postx/';
313 $utm_key = $params['utmKey'] ?? null;
314 $affiliate = $params['affiliate'] ?? apply_filters( 'ultp_affiliate_id', '' );
315 $hash = $params['hash'] ?? 'pricing';
316 $custom_config = $params['config'] ?? null;
317
318 $parsed_url = parse_url( $base_url );
319 $scheme = $parsed_url['scheme'] ?? 'https';
320 $host = $parsed_url['host'] ?? '';
321 $path = $parsed_url['path'] ?? '';
322 $query = array();
323
324 // Step 3: Extract existing query params if present
325 if ( isset( $parsed_url['query'] ) ) {
326 parse_str( $parsed_url['query'], $query );
327 }
328
329 // Step 4: Determine config
330 $utm_config = $custom_config ?? ( $utm_key && isset( $default_config[ $utm_key ] ) ? $default_config[ $utm_key ] : array() );
331
332 // Step 5: Add UTM parameters
333 if ( ! empty( $utm_config ) ) {
334 $query = array_merge(
335 $query,
336 array(
337 'utm_source' => $utm_config['source'],
338 'utm_medium' => $utm_config['medium'],
339 'utm_campaign' => $utm_config['campaign'],
340 )
341 );
342 }
343
344 // Step 6: Add affiliate if present
345 if ( $affiliate ) {
346 $query['ref'] = $affiliate;
347 }
348
349 // Step 7: Reconstruct URL
350 $final_url = $scheme . '://' . $host . $path;
351
352 if ( ! empty( $query ) ) {
353 $final_url .= '?' . http_build_query( $query );
354 }
355
356 if ( $hash ) {
357 $final_url .= '#' . $hash;
358 }
359
360 return $final_url;
361 }
362
363
364 /**
365 * Get WOW Products Details
366 *
367 * @return array
368 */
369 public static function get_wow_products_details() {
370 return array(
371 'products' => array(
372 'wow_shipping' => file_exists( WP_PLUGIN_DIR . '/wow-table-rate-shipping/wow-table-rate-shipping.php' ),
373 'post_x' => file_exists( WP_PLUGIN_DIR . '/ultimate-post/ultimate-post.php' ),
374 'wow_store' => file_exists( WP_PLUGIN_DIR . '/product-blocks/product-blocks.php' ),
375 'wow_optin' => file_exists( WP_PLUGIN_DIR . '/optin/optin.php' ),
376 'wow_revenue' => file_exists( WP_PLUGIN_DIR . '/revenue/revenue.php' ),
377 'wholesale_x' => file_exists( WP_PLUGIN_DIR . '/wholesalex/wholesalex.php' ),
378 'wow_addon' => file_exists( WP_PLUGIN_DIR . '/product-addons/product-addons.php' ),
379
380 ),
381 'products_active' => array(
382 'wow_shipping' => defined( 'WTRS_VER' ),
383 'post_x' => defined( 'ULTP_VER' ),
384 'wow_store' => defined( 'WOPB_VER' ),
385 'wow_optin' => defined( 'OPTN_VERSION' ),
386 'wow_revenue' => defined( 'REVENUE_VER' ),
387 'wholesale_x' => defined( 'WHOLESALEX_VER' ),
388 'wow_addon' => defined( 'PRAD_VER' ),
389 ),
390 );
391 }
392
393
394 /**
395 * Installs and activates a plugin by its name only.
396 *
397 * @param string $name The name or slug of the plugin to install and activate.
398 */
399 public static function install_and_active_plugin( $name ) {
400 $to_r = array( 'done' => true );
401 $plugin_slug = '';
402 switch ( $name ) {
403 case 'wow_shipping':
404 $plugin_slug = 'wow-table-rate-shipping';
405 break;
406 case 'post_x':
407 $plugin_slug = 'ultimate-post';
408 break;
409 case 'wow_store':
410 $plugin_slug = 'product-blocks';
411 break;
412 case 'wow_optin':
413 $plugin_slug = 'optin';
414 break;
415 case 'wow_revenue':
416 $plugin_slug = 'revenue';
417 break;
418 case 'wholesale_x':
419 $plugin_slug = 'wholesalex';
420 break;
421 case 'wow_addon':
422 $plugin_slug = 'product-addons';
423 break;
424 case 'woocommerce':
425 $plugin_slug = 'woocommerce';
426 break;
427 }
428
429 if ( ! file_exists( WP_PLUGIN_DIR . '/' . $plugin_slug . '/' . $plugin_slug . '.php' ) ) {
430 $to_r = self::plugin_install( $plugin_slug . '/' . $plugin_slug . '.php', $plugin_slug );
431 } else {
432 activate_plugin( $plugin_slug . '/' . $plugin_slug . '.php' );
433 }
434 return $to_r;
435 }
436
437 /**
438 * Installs a plugin based on the provided plugin file and slug.
439 *
440 * This function is expected to handle the logic required to install a plugin,
441 * such as downloading, unpacking, and activating the plugin using the provided
442 * plugin file and slug.
443 *
444 * @param string $plugin The plugin file path or identifier (e.g., 'plugin-directory/plugin-file.php').
445 * @param string $slug The plugin slug (typically the directory name of the plugin).
446 */
447 public static function plugin_install( $plugin, $slug ) {
448 include ABSPATH . 'wp-admin/includes/plugin-install.php';
449 include ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
450
451 if ( ! class_exists( 'Plugin_Upgrader' ) ) {
452 include ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php';
453 }
454 if ( ! class_exists( 'WP_Ajax_Upgrader_Skin' ) ) {
455 include ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php';
456 }
457
458 $api = plugins_api(
459 'plugin_information',
460 array(
461 'slug' => $slug,
462 'fields' => array(
463 'short_description' => false,
464 'sections' => false,
465 'requires' => false,
466 'rating' => false,
467 'ratings' => false,
468 'downloaded' => false,
469 'last_updated' => false,
470 'added' => false,
471 'tags' => false,
472 'compatibility' => false,
473 'homepage' => false,
474 'donate_link' => false,
475 ),
476 )
477 );
478
479 if ( is_wp_error( $api ) ) {
480 wp_die( $api ); //phpcs:ignore
481 }
482
483 $upgrader = new \Plugin_Upgrader( new \WP_Ajax_Upgrader_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) );
484 $install_result = $upgrader->install( $api->download_link );
485
486 if ( ! is_wp_error( $install_result ) ) {
487 activate_plugin( $plugin );
488 return array( 'done' => false );
489 }
490
491 return array( 'done' => true );
492 }
493 }
494