| 1 |
<?php |
| 2 |
|
| 3 |
namespace Sellkit\Admin\Funnel\Importer\Page_Builder; |
| 4 |
|
| 5 |
use Elementor\Plugin; |
| 6 |
use Elementor\TemplateLibrary\Source_Local; |
| 7 |
use stdClass; |
| 8 |
|
| 9 |
defined( 'ABSPATH' ) || die(); |
| 10 |
|
| 11 |
/** |
| 12 |
* Class Elementor. |
| 13 |
* |
| 14 |
* @since 1.1.0 |
| 15 |
*/ |
| 16 |
class Elementor_Importer extends Source_Local { |
| 17 |
|
| 18 |
/** |
| 19 |
* Elementor_Importer constructor. |
| 20 |
* |
| 21 |
* @since 1.1.0 |
| 22 |
* @param object $data All data from api. |
| 23 |
* @param int $step_id The id of imported step. |
| 24 |
*/ |
| 25 |
public function __construct( $data, $step_id ) { |
| 26 |
parent::__construct(); |
| 27 |
|
| 28 |
if ( ! is_object( $data ) ) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
$meta_data = (array) $data->meta; |
| 33 |
|
| 34 |
if ( array_key_exists( '_elementor_data', $meta_data ) ) { |
| 35 |
$this->import_single_template( $step_id, $meta_data['_elementor_data'] ); |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Imports single template. |
| 41 |
* |
| 42 |
* @param int $post_id Post ID. |
| 43 |
* @param string $content Content. |
| 44 |
*/ |
| 45 |
public function import_single_template( $post_id, $content ) { |
| 46 |
if ( empty( $content ) ) { |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
if ( ! is_array( $content ) ) { |
| 51 |
$content = add_magic_quotes( $content ); |
| 52 |
$content = json_decode( $content, true ); |
| 53 |
} |
| 54 |
|
| 55 |
if ( is_array( $content ) ) { |
| 56 |
$content = $this->process_export_import_content( $content, 'on_import' ); |
| 57 |
|
| 58 |
update_post_meta( $post_id, '_elementor_data', $content ); |
| 59 |
|
| 60 |
$this->clear_elementor_cache(); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Clear Cache. |
| 66 |
* |
| 67 |
* @since 1.0.0 |
| 68 |
*/ |
| 69 |
public function clear_elementor_cache() { |
| 70 |
// Clear 'Elementor' file cache. |
| 71 |
if ( class_exists( '\Elementor\Plugin' ) ) { |
| 72 |
Plugin::$instance->files_manager->clear_cache(); |
| 73 |
} |
| 74 |
} |
| 75 |
} |
| 76 |
|