| 1 |
<?php |
| 2 |
/** |
| 3 |
* Compatibility Action. |
| 4 |
* |
| 5 |
* @package ULTP\Compatibility |
| 6 |
* @since v.1.1.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace ULTP; |
| 10 |
defined('ABSPATH') || exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Compatibility class. |
| 14 |
*/ |
| 15 |
class Compatibility { |
| 16 |
|
| 17 |
/** |
| 18 |
* Setup class. |
| 19 |
* |
| 20 |
* @since v.1.1.0 |
| 21 |
*/ |
| 22 |
public function __construct() { |
| 23 |
add_action( 'admin_init', array( $this, 'handle_front_page_builder' ) ); |
| 24 |
|
| 25 |
add_action( 'upgrader_process_complete', array($this, 'plugin_upgrade_completed'), 10, 2 ); |
| 26 |
|
| 27 |
// PublishPress Revisions Plugin Compatibility Add |
| 28 |
add_action('revisionary_copy_postmeta', array($this, 'ultp_revisionary_copy_postmeta_callback'), 10, 3); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Compatibility for Front Page Builder |
| 33 |
* |
| 34 |
* @since 4.1.12 |
| 35 |
*/ |
| 36 |
public function handle_front_page_builder() { |
| 37 |
|
| 38 |
if ( get_option('ultp_frontpage_builder_comp') != "yes" ) { |
| 39 |
$builder_condition = get_option('ultp_builder_conditions', array()); |
| 40 |
if ( |
| 41 |
!empty($builder_condition) && |
| 42 |
!empty($builder_condition['singular']) |
| 43 |
) { |
| 44 |
$f_pages = array(); |
| 45 |
foreach ( $builder_condition['singular'] as $id => $paths ) { |
| 46 |
if ( in_array('include/singular/front_page', $paths) ) { |
| 47 |
$f_pages[$id] = ["include/front_page"]; // Add the ID to the list |
| 48 |
update_post_meta($id, '__ultp_builder_type', 'front_page'); |
| 49 |
unset($builder_condition['singular'][$id]); |
| 50 |
} |
| 51 |
} |
| 52 |
if ( empty($builder_condition['front_page']) ) { |
| 53 |
$builder_condition['front_page'] = $f_pages; |
| 54 |
} else { |
| 55 |
$builder_condition['front_page'] = $builder_condition['front_page'] + $f_pages; |
| 56 |
} |
| 57 |
update_option("ultp_frontpage_builder_comp", "yes"); |
| 58 |
update_option("ultp_builder_conditions", $builder_condition); |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Compatibility for PublishPress Revisions Plugin |
| 65 |
* @url https://wordpress.org/plugins/revisionary/ |
| 66 |
* |
| 67 |
* @since v.2.9.8 |
| 68 |
*/ |
| 69 |
public function ultp_revisionary_copy_postmeta_callback($from_post, $to_post_id, $args) { |
| 70 |
global $wp_filesystem; |
| 71 |
if (! $wp_filesystem ) { |
| 72 |
require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
| 73 |
WP_Filesystem(); |
| 74 |
} |
| 75 |
$css_meta = get_post_meta( $to_post_id, '_ultp_css', true ); |
| 76 |
$upload_dir_url = wp_get_upload_dir(); |
| 77 |
$upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] ); |
| 78 |
$css_dir_path = $upload_css_dir_url."ultimate-post/ultp-css-{$to_post_id}.css"; |
| 79 |
|
| 80 |
if ( file_exists( $css_dir_path ) ) { |
| 81 |
$css = $wp_filesystem->get_contents($css_dir_path); |
| 82 |
if ($css_meta != $css) { |
| 83 |
$wp_filesystem->put_contents( $css_dir_path, $css_meta ); |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Compatibility Class Run after Plugin Upgrade |
| 90 |
* |
| 91 |
* @since v.1.1.0 |
| 92 |
*/ |
| 93 |
public function plugin_upgrade_completed( $upgrader_object, $options ) { |
| 94 |
if ($options['action'] == 'update' && $options['type'] == 'plugin' && isset( $options['plugins'] )) { |
| 95 |
foreach( $options['plugins'] as $plugin ) { |
| 96 |
if ($plugin == ULTP_BASE ) { |
| 97 |
// License Check And Active |
| 98 |
if ( defined('ULTP_PRO_VER') ) { |
| 99 |
$license = get_option( 'edd_ultp_license_key' ); |
| 100 |
$response = wp_remote_post( |
| 101 |
'https://account.wpxpo.com', |
| 102 |
array( |
| 103 |
'timeout' => 15, |
| 104 |
'sslverify' => false, |
| 105 |
'body' => array( |
| 106 |
'edd_action' => 'activate_license', |
| 107 |
'license' => $license, |
| 108 |
'item_id' => 181, |
| 109 |
'url' => home_url() |
| 110 |
) |
| 111 |
) |
| 112 |
); |
| 113 |
if ( !is_wp_error( $response ) && 200 == wp_remote_retrieve_response_code( $response ) ) { |
| 114 |
$license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
| 115 |
update_option( 'edd_ultp_license_status', $license_data->license ); |
| 116 |
} |
| 117 |
} |
| 118 |
if ( ultimate_post()->get_setting('init_setup') != 'yes' ) { |
| 119 |
ultimate_post()->set_setting('init_setup', 'yes'); |
| 120 |
} |
| 121 |
} |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
} |