| 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 |
// PublishPress Revisions Plugin Compatibility Add |
| 26 |
add_action('revisionary_copy_postmeta', array($this, 'ultp_revisionary_copy_postmeta_callback'), 10, 3); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Compatibility for Front Page Builder |
| 31 |
* |
| 32 |
* @since 4.1.12 |
| 33 |
*/ |
| 34 |
public function handle_front_page_builder() { |
| 35 |
|
| 36 |
if ( get_option('ultp_frontpage_builder_comp') != "yes" ) { |
| 37 |
$builder_condition = get_option('ultp_builder_conditions', array()); |
| 38 |
if ( |
| 39 |
!empty($builder_condition) && |
| 40 |
!empty($builder_condition['singular']) |
| 41 |
) { |
| 42 |
$f_pages = array(); |
| 43 |
foreach ( $builder_condition['singular'] as $id => $paths ) { |
| 44 |
if ( in_array('include/singular/front_page', $paths) ) { |
| 45 |
$f_pages[$id] = ["include/front_page"]; // Add the ID to the list |
| 46 |
update_post_meta($id, '__ultp_builder_type', 'front_page'); |
| 47 |
unset($builder_condition['singular'][$id]); |
| 48 |
} |
| 49 |
} |
| 50 |
if ( empty($builder_condition['front_page']) ) { |
| 51 |
$builder_condition['front_page'] = $f_pages; |
| 52 |
} else { |
| 53 |
$builder_condition['front_page'] = $builder_condition['front_page'] + $f_pages; |
| 54 |
} |
| 55 |
update_option("ultp_frontpage_builder_comp", "yes"); |
| 56 |
update_option("ultp_builder_conditions", $builder_condition); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Compatibility for PublishPress Revisions Plugin |
| 63 |
* @url https://wordpress.org/plugins/revisionary/ |
| 64 |
* |
| 65 |
* @since v.2.9.8 |
| 66 |
*/ |
| 67 |
public function ultp_revisionary_copy_postmeta_callback($from_post, $to_post_id, $args) { |
| 68 |
global $wp_filesystem; |
| 69 |
if (! $wp_filesystem ) { |
| 70 |
require_once( ABSPATH . 'wp-admin/includes/file.php' ); |
| 71 |
WP_Filesystem(); |
| 72 |
} |
| 73 |
$css_meta = get_post_meta( $to_post_id, '_ultp_css', true ); |
| 74 |
$upload_dir_url = wp_get_upload_dir(); |
| 75 |
$upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] ); |
| 76 |
$css_dir_path = $upload_css_dir_url."ultimate-post/ultp-css-{$to_post_id}.css"; |
| 77 |
|
| 78 |
if ( file_exists( $css_dir_path ) ) { |
| 79 |
$css = $wp_filesystem->get_contents($css_dir_path); |
| 80 |
if ($css_meta != $css) { |
| 81 |
$wp_filesystem->put_contents( $css_dir_path, $css_meta ); |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
} |