| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\App\Modules\ImportExport\Runners\Export; |
| 4 |
|
| 5 |
use Elementor\App\Modules\ImportExport\Utils as ImportExportUtils; |
| 6 |
use Elementor\Core\Utils\ImportExport\WP_Exporter; |
| 7 |
|
| 8 |
class Wp_Content extends Export_Runner_Base { |
| 9 |
|
| 10 |
public static function get_name(): string { |
| 11 |
return 'wp-content'; |
| 12 |
} |
| 13 |
|
| 14 |
public function should_export( array $data ) { |
| 15 |
return ( |
| 16 |
isset( $data['include'] ) && |
| 17 |
in_array( 'content', $data['include'], true ) |
| 18 |
); |
| 19 |
} |
| 20 |
|
| 21 |
public function export( array $data ) { |
| 22 |
$post_types = ImportExportUtils::get_builtin_wp_post_types(); |
| 23 |
$custom_post_types = isset( $data['selected_custom_post_types'] ) ? $data['selected_custom_post_types'] : []; |
| 24 |
|
| 25 |
$files = []; |
| 26 |
$manifest_data = []; |
| 27 |
|
| 28 |
foreach ( $post_types as $post_type ) { |
| 29 |
$export = $this->export_wp_post_type( $post_type ); |
| 30 |
$files[] = $export['file']; |
| 31 |
$manifest_data['wp-content'][ $post_type ] = $export['manifest_data']; |
| 32 |
} |
| 33 |
|
| 34 |
foreach ( $custom_post_types as $post_type ) { |
| 35 |
$export = $this->export_wp_post_type( $post_type ); |
| 36 |
$files[] = $export['file']; |
| 37 |
$manifest_data['wp-content'][ $post_type ] = $export['manifest_data']; |
| 38 |
|
| 39 |
$post_type_object = get_post_type_object( $post_type ); |
| 40 |
|
| 41 |
$manifest_data['custom-post-type-title'][ $post_type ] = [ |
| 42 |
'name' => $post_type_object->name, |
| 43 |
'label' => $post_type_object->label, |
| 44 |
]; |
| 45 |
} |
| 46 |
|
| 47 |
return [ |
| 48 |
'files' => $files, |
| 49 |
'manifest' => [ |
| 50 |
$manifest_data, |
| 51 |
], |
| 52 |
]; |
| 53 |
} |
| 54 |
|
| 55 |
private function export_wp_post_type( $post_type ) { |
| 56 |
$wp_exporter = new WP_Exporter( [ |
| 57 |
'content' => $post_type, |
| 58 |
'status' => 'publish', |
| 59 |
'limit' => 20, |
| 60 |
'meta_query' => [ |
| 61 |
[ |
| 62 |
'key' => static::META_KEY_ELEMENTOR_EDIT_MODE, |
| 63 |
'compare' => 'NOT EXISTS', |
| 64 |
], |
| 65 |
], |
| 66 |
'include_post_featured_image_as_attachment' => true, |
| 67 |
] ); |
| 68 |
|
| 69 |
$export_result = $wp_exporter->run(); |
| 70 |
|
| 71 |
return [ |
| 72 |
'file' => [ |
| 73 |
'path' => 'wp-content/' . $post_type . '/' . $post_type . '.xml', |
| 74 |
'data' => $export_result['xml'], |
| 75 |
], |
| 76 |
'manifest_data' => $export_result['ids'], |
| 77 |
]; |
| 78 |
} |
| 79 |
} |
| 80 |
|