Last active
January 8, 2019 16:53
-
-
Save wpmudev-sls/4ae7e81d54ce631b0cc0fc07a5418956 to your computer and use it in GitHub Desktop.
Cloner Integration With Elememnot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Cloner Integration With Elementor | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: This plugin used a hack to fix compatibility issue with elementor plugin | |
* Author: Ariful Islam @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/profile/itsarifulislam | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
if ( ! class_exists( 'Cloner_Elementor_Integration' ) ) { | |
class Cloner_Elementor_Integration { | |
private static $_instance = null; | |
public $elementor_post_meta = array(); | |
public static function get_instance() { | |
if( is_null( self::$_instance ) ) { | |
self::$_instance = new Cloner_Elementor_Integration(); | |
} | |
return self::$_instance; | |
} | |
private function __construct() { | |
global $blog_templates; | |
if ( class_exists('WPMUDEV_Cloner') ) { | |
add_action( 'wpmudev_copier-copy-after_copying', array( $this, 'copy_elementor_css_files'), 10, 1 ); | |
add_action( 'wpmudev_copier-copy-post', array( $this, 'get_the_elementor_meta_data'), 10, 6 ); | |
add_action( 'wpmudev_copier-copied-posts', array( $this, 'update_elementor_meta_data'), 10 ); | |
} | |
} | |
public function update_elementor_meta_data() { | |
global $wpdb; | |
$table = $wpdb->get_blog_prefix() . 'postmeta'; | |
foreach ($this->elementor_post_meta as $data) { | |
$wpdb->query( $wpdb->prepare( "UPDATE $table SET meta_value = %s WHERE post_id = %d AND meta_key = %s", $data['meta_value'], $data['post_id'], '_elementor_data') ); | |
} | |
} | |
public function get_the_elementor_meta_data( $source_blog_id, $post_id, $new_post, $user_id, $template, $post ) { | |
if ( $post && $post->meta && isset( $post->meta['_elementor_data'] ) ) { | |
$this->elementor_post_meta[] = array( | |
'post_id' => $post_id, | |
'meta_value' => $post->meta['_elementor_data'] | |
); | |
} | |
} | |
public function copy_elementor_css_files( $source_blog_id ) { | |
if ( ! function_exists( 'WP_Filesystem' ) ) { | |
require_once ABSPATH . "wp-admin/includes/file.php"; | |
} | |
if ( ! WP_Filesystem() ) { | |
return new WP_Error( 'wp_filesystem_error', 'The Filesystem could not be instatiated' ); | |
} | |
$elementor_css_path = '/elementor/'; | |
switch_to_blog( $source_blog_id ); | |
$source = wp_upload_dir()['basedir'] . $elementor_css_path; | |
$source = trailingslashit( wp_normalize_path( $source ) ); | |
restore_current_blog(); | |
$destination = wp_upload_dir()['basedir'] . $elementor_css_path; | |
$destination = trailingslashit( wp_normalize_path( $destination ) ); | |
wp_mkdir_p( $destination ); | |
copy_dir( $source, $destination ); | |
} | |
} | |
function Cloner_Elementor_Integration(){ | |
$GLOBALS['Cloner_Elementor_Integration'] = Cloner_Elementor_Integration::get_instance(); | |
} | |
add_action( 'plugins_loaded', 'Cloner_Elementor_Integration' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment