| 1 |
<?php |
| 2 |
/** |
| 3 |
* Compatibility Action. |
| 4 |
* |
| 5 |
* @package ULTP\Compatibility |
| 6 |
* @since v.1.1.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace ULTP; |
| 10 |
|
| 11 |
defined( 'ABSPATH' ) || exit; |
| 12 |
|
| 13 |
/** |
| 14 |
* Compatibility class. |
| 15 |
* |
| 16 |
* Handles compatibility with other plugins and themes for Ultimate Post. |
| 17 |
* |
| 18 |
* @package ULTP\Compatibility |
| 19 |
* @since 4.0.0 |
| 20 |
*/ |
| 21 |
class Compatibility { |
| 22 |
|
| 23 |
/** |
| 24 |
* Setup class. |
| 25 |
* |
| 26 |
* @since v.1.1.0 |
| 27 |
*/ |
| 28 |
public function __construct() { |
| 29 |
add_action( 'admin_init', array( $this, 'handle_front_page_builder' ) ); |
| 30 |
|
| 31 |
// PublishPress Revisions Plugin Compatibility Add |
| 32 |
add_action( 'revisionary_copy_postmeta', array( $this, 'ultp_revisionary_copy_postmeta_callback' ), 10, 3 ); |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Compatibility for Front Page Builder |
| 37 |
* |
| 38 |
* @since 4.1.12 |
| 39 |
*/ |
| 40 |
public function handle_front_page_builder() { |
| 41 |
|
| 42 |
if ( get_option( 'ultp_frontpage_builder_comp' ) != 'yes' ) { |
| 43 |
$builder_condition = get_option( 'ultp_builder_conditions', array() ); |
| 44 |
if ( ! empty( $builder_condition ) && |
| 45 |
! empty( $builder_condition['singular'] ) |
| 46 |
) { |
| 47 |
$f_pages = array(); |
| 48 |
foreach ( $builder_condition['singular'] as $id => $paths ) { |
| 49 |
if ( in_array( 'include/singular/front_page', $paths ) ) { |
| 50 |
$f_pages[ $id ] = array( 'include/front_page' ); // Add the ID to the list |
| 51 |
update_post_meta( $id, '__ultp_builder_type', 'front_page' ); |
| 52 |
unset( $builder_condition['singular'][ $id ] ); |
| 53 |
} |
| 54 |
} |
| 55 |
if ( empty( $builder_condition['front_page'] ) ) { |
| 56 |
$builder_condition['front_page'] = $f_pages; |
| 57 |
} else { |
| 58 |
$builder_condition['front_page'] = $builder_condition['front_page'] + $f_pages; |
| 59 |
} |
| 60 |
update_option( 'ultp_frontpage_builder_comp', 'yes' ); |
| 61 |
update_option( 'ultp_builder_conditions', $builder_condition ); |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
/** |
| 67 |
* Compatibility for PublishPress Revisions Plugin |
| 68 |
* |
| 69 |
* @url https://wordpress.org/plugins/revisionary/ |
| 70 |
* |
| 71 |
* @since v.2.9.8 |
| 72 |
* |
| 73 |
* @param MIXED $from_post The source post object or ID. |
| 74 |
* @param INT $to_post_id The destination post ID. |
| 75 |
* @param ARRAY $args Additional arguments. |
| 76 |
*/ |
| 77 |
public function ultp_revisionary_copy_postmeta_callback( $from_post, $to_post_id, $args ) { |
| 78 |
global $wp_filesystem; |
| 79 |
if ( ! $wp_filesystem ) { |
| 80 |
require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 81 |
WP_Filesystem(); |
| 82 |
} |
| 83 |
$css_meta = get_post_meta( $to_post_id, '_ultp_css', true ); |
| 84 |
$upload_dir_url = wp_get_upload_dir(); |
| 85 |
$upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] ); |
| 86 |
$css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$to_post_id}.css"; |
| 87 |
|
| 88 |
if ( file_exists( $css_dir_path ) ) { |
| 89 |
$css = $wp_filesystem->get_contents( $css_dir_path ); |
| 90 |
if ( $css_meta != $css ) { |
| 91 |
$wp_filesystem->put_contents( $css_dir_path, $css_meta ); |
| 92 |
} |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|