| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\App\Modules\ImportExportCustomization\Runners\Export; |
| 4 |
|
| 5 |
use Elementor\App\Modules\ImportExportCustomization\Compatibility\Customization; |
| 6 |
use Elementor\App\Modules\ImportExportCustomization\Utils as ImportExportUtils; |
| 7 |
use Elementor\Core\Utils\ImportExport\WP_Exporter; |
| 8 |
|
| 9 |
class Wp_Content extends Export_Runner_Base { |
| 10 |
|
| 11 |
public static function get_name(): string { |
| 12 |
return 'wp-content'; |
| 13 |
} |
| 14 |
|
| 15 |
public function should_export( array $data ) { |
| 16 |
return ( |
| 17 |
isset( $data['include'] ) && |
| 18 |
in_array( 'content', $data['include'], true ) |
| 19 |
); |
| 20 |
} |
| 21 |
|
| 22 |
public function export( array $data ) { |
| 23 |
$customization = $data['customization']['content'] ?? null; |
| 24 |
$exclude_post_types = []; |
| 25 |
|
| 26 |
if ( isset( $customization['customPostTypes'] ) && ! in_array( 'post', $customization['customPostTypes'], true ) ) { |
| 27 |
$exclude_post_types[] = 'post'; |
| 28 |
} |
| 29 |
|
| 30 |
$post_types = ImportExportUtils::get_builtin_wp_post_types( $exclude_post_types ); |
| 31 |
|
| 32 |
$post_types = apply_filters( 'elementor/import-export-customization/wp-content/post-types/customization', $post_types, $data, $customization ); |
| 33 |
|
| 34 |
$custom_post_types = isset( $data['selected_custom_post_types'] ) ? $data['selected_custom_post_types'] : []; |
| 35 |
|
| 36 |
$files = []; |
| 37 |
$manifest_data = []; |
| 38 |
|
| 39 |
foreach ( $post_types as $post_type ) { |
| 40 |
$export = $this->export_wp_post_type( $post_type, $customization ); |
| 41 |
|
| 42 |
if ( ! empty( $export['file'] ) ) { |
| 43 |
$files[] = $export['file']; |
| 44 |
} |
| 45 |
|
| 46 |
$manifest_data['wp-content'][ $post_type ] = $export['manifest_data']; |
| 47 |
} |
| 48 |
|
| 49 |
foreach ( $custom_post_types as $post_type ) { |
| 50 |
$post_type_object = get_post_type_object( $post_type ); |
| 51 |
|
| 52 |
$manifest_data['custom-post-type-title'][ $post_type ] = [ |
| 53 |
'name' => $post_type_object->name, |
| 54 |
'label' => $post_type_object->label, |
| 55 |
]; |
| 56 |
|
| 57 |
// handled in the previous loop |
| 58 |
if ( 'post' === $post_type ) { |
| 59 |
continue; |
| 60 |
} |
| 61 |
$export = $this->export_wp_post_type( $post_type, $customization ); |
| 62 |
|
| 63 |
if ( ! empty( $export['file'] ) ) { |
| 64 |
$files[] = $export['file']; |
| 65 |
} |
| 66 |
|
| 67 |
$manifest_data['wp-content'][ $post_type ] = $export['manifest_data']; |
| 68 |
} |
| 69 |
|
| 70 |
return [ |
| 71 |
'files' => $files, |
| 72 |
'manifest' => [ |
| 73 |
$manifest_data, |
| 74 |
], |
| 75 |
]; |
| 76 |
} |
| 77 |
|
| 78 |
private function export_wp_post_type( $post_type, $customization ) { |
| 79 |
$exporter_args = [ |
| 80 |
'content' => $post_type, |
| 81 |
'status' => 'publish', |
| 82 |
'meta_query' => [ |
| 83 |
[ |
| 84 |
'key' => static::META_KEY_ELEMENTOR_EDIT_MODE, |
| 85 |
'compare' => 'NOT EXISTS', |
| 86 |
], |
| 87 |
], |
| 88 |
'include_post_featured_image_as_attachment' => true, |
| 89 |
]; |
| 90 |
|
| 91 |
if ( 'pages' !== $post_type ) { |
| 92 |
$exporter_args['limit'] = 20; |
| 93 |
} |
| 94 |
|
| 95 |
$exporter_args = apply_filters( 'elementor/import-export-customization/export/wp-content/query-args/customization', $exporter_args, $post_type, $customization ); |
| 96 |
|
| 97 |
$wp_exporter = new WP_Exporter( $exporter_args ); |
| 98 |
|
| 99 |
$export_result = $wp_exporter->run(); |
| 100 |
|
| 101 |
return [ |
| 102 |
'file' => [ |
| 103 |
'path' => 'wp-content/' . $post_type . '/' . $post_type . '.xml', |
| 104 |
'data' => $export_result['xml'], |
| 105 |
], |
| 106 |
'manifest_data' => $export_result['posts'], |
| 107 |
]; |
| 108 |
} |
| 109 |
} |
| 110 |
|