Update elementor pro
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\AssetsManager\AssetTypes\Fonts\ImportExportCustomization;
|
||||
|
||||
use Elementor\App\Modules\ImportExportCustomization\Runners\Export\Export_Runner_Base;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Fonts_Manager;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Fonts\Custom_Fonts;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Export_Runner extends Export_Runner_Base {
|
||||
public static function get_name(): string {
|
||||
return 'custom-fonts';
|
||||
}
|
||||
|
||||
public function should_export( array $data ) {
|
||||
return (
|
||||
isset( $data['include'] ) &&
|
||||
in_array( 'settings', $data['include'], true )
|
||||
);
|
||||
}
|
||||
|
||||
public function export( array $data ) {
|
||||
$custom_fonts = new Custom_Fonts();
|
||||
$fonts = $custom_fonts->get_fonts( true );
|
||||
|
||||
$include_custom_fonts = $data['customization']['settings']['customFonts'] ?? true;
|
||||
|
||||
if ( empty( $fonts ) || ! $include_custom_fonts ) {
|
||||
return [
|
||||
'manifest' => [],
|
||||
'files' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$fonts_data = [];
|
||||
$manifest = [];
|
||||
|
||||
foreach ( $fonts as $font_family => $font_type ) {
|
||||
$font_data = $this->prepare_font_data( $font_family );
|
||||
if ( $font_data ) {
|
||||
$fonts_data[] = $font_data;
|
||||
$manifest['custom-fonts'][ $font_family ] = $font_data;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'files' => [
|
||||
'path' => Import_Export_Customization::FILE_NAME,
|
||||
'data' => $fonts_data,
|
||||
],
|
||||
'manifest' => [
|
||||
$manifest,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function prepare_font_data( $font_family ) {
|
||||
$font_query = new \WP_Query( [
|
||||
'post_type' => Fonts_Manager::CPT,
|
||||
'post_status' => 'any',
|
||||
'posts_per_page' => 1,
|
||||
'title' => $font_family,
|
||||
] );
|
||||
|
||||
if ( ! $font_query->have_posts() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$font_post = $font_query->posts[0];
|
||||
|
||||
$custom_fonts = new Custom_Fonts();
|
||||
|
||||
$font_files = get_post_meta( $font_post->ID, Custom_Fonts::FONT_META_KEY, true );
|
||||
$font_face = get_post_meta( $font_post->ID, Custom_Fonts::FONT_FACE_META_KEY, true );
|
||||
|
||||
$font_type = $custom_fonts->get_font_family_type( $font_post->ID, $font_post->post_title );
|
||||
$is_font_variable = 'variable' === $font_type;
|
||||
|
||||
$font_variables = [];
|
||||
$font_variable_ranges = [];
|
||||
|
||||
if ( $is_font_variable ) {
|
||||
$font_data = $custom_fonts->get_font_data( $font_post->ID, $font_post->post_title );
|
||||
$font_variables = $font_data[ $font_post->post_title ]['variables'] ?? null;
|
||||
$font_variable_ranges = $font_data[ $font_post->post_title ]['variable_ranges'] ?? null;
|
||||
}
|
||||
|
||||
$attachments = get_attached_media( '', $font_post->ID );
|
||||
$attachments_data = [];
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$url = wp_get_attachment_url( $attachment->ID );
|
||||
$attachments_data[] = [
|
||||
'id' => $attachment->ID,
|
||||
'title' => $attachment->post_title,
|
||||
'url' => $url,
|
||||
];
|
||||
|
||||
do_action( 'elementor/templates/collect_media_url', $url, (array) $attachment );
|
||||
}
|
||||
|
||||
return [
|
||||
'ID' => $font_post->ID,
|
||||
'post_title' => $font_post->post_title,
|
||||
'post_content' => $font_post->post_content,
|
||||
'post_status' => $font_post->post_status,
|
||||
'font_type' => $font_type,
|
||||
'font_files' => $font_files,
|
||||
'font_face' => $font_face,
|
||||
'font_variables' => $font_variables,
|
||||
'font_variable_ranges' => $font_variable_ranges,
|
||||
'attachments' => $attachments_data,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\AssetsManager\AssetTypes\Fonts\ImportExportCustomization;
|
||||
|
||||
use Elementor\App\Modules\ImportExportCustomization\Processes\Export;
|
||||
use Elementor\App\Modules\ImportExportCustomization\Processes\Import;
|
||||
use Elementor\App\Modules\ImportExportCustomization\Processes\Revert;
|
||||
|
||||
class Import_Export_Customization {
|
||||
const FILE_NAME = 'custom-fonts';
|
||||
|
||||
public function register_hooks() {
|
||||
add_action( 'elementor/import-export-customization/export-kit', function ( Export $export ) {
|
||||
$export->register( new Export_Runner() );
|
||||
} );
|
||||
|
||||
add_action( 'elementor/import-export-customization/import-kit', function ( Import $import ) {
|
||||
$import->register( new Import_Runner() );
|
||||
} );
|
||||
|
||||
add_action( 'elementor/import-export-customization/revert-kit', function ( Revert $revert ) {
|
||||
$revert->register( new Revert_Runner() );
|
||||
} );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\AssetsManager\AssetTypes\Fonts\ImportExportCustomization;
|
||||
|
||||
use Elementor\App\Modules\ImportExportCustomization\Runners\Import\Import_Runner_Base;
|
||||
use Elementor\App\Modules\ImportExportCustomization\Utils as ImportExportUtils;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Fonts_Manager;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Fonts\Custom_Fonts;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\ImportExport\Traits\External_Attachment_Trait;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Import_Runner extends Import_Runner_Base {
|
||||
use External_Attachment_Trait;
|
||||
|
||||
private $session_id;
|
||||
private $imported_fonts = [];
|
||||
|
||||
public static function get_name(): string {
|
||||
return 'custom-fonts';
|
||||
}
|
||||
|
||||
public function should_import( array $data ) {
|
||||
return (
|
||||
isset( $data['include'] ) &&
|
||||
in_array( 'settings', $data['include'], true )
|
||||
);
|
||||
}
|
||||
|
||||
public function import( array $data, array $imported_data ) {
|
||||
$this->session_id = $data['session_id'];
|
||||
|
||||
$include_custom_fonts = $data['customization']['settings']['customFonts'] ?? true;
|
||||
|
||||
$custom_fonts = new Custom_Fonts();
|
||||
$custom_fonts->get_fonts( true );
|
||||
|
||||
$result = [];
|
||||
|
||||
$custom_fonts_file_path = $data['extracted_directory_path'] . Import_Export_Customization::FILE_NAME;
|
||||
$fonts_data = ImportExportUtils::read_json_file( $custom_fonts_file_path );
|
||||
|
||||
if ( empty( $fonts_data ) || ! $include_custom_fonts ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
foreach ( $fonts_data as $font_data ) {
|
||||
$this->import_font( $font_data );
|
||||
}
|
||||
|
||||
if ( empty( $this->imported_fonts ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$result['site-settings']['custom-fonts'] = $this->imported_fonts;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function get_import_session_metadata(): array {
|
||||
return [
|
||||
'imported_fonts' => $this->imported_fonts,
|
||||
];
|
||||
}
|
||||
|
||||
private function import_font( $font_data ) {
|
||||
$existing_font = $this->get_existing_font( $font_data['post_title'] );
|
||||
|
||||
if ( $existing_font ) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$font_id = $this->create_font( $font_data );
|
||||
|
||||
if ( $font_id ) {
|
||||
$this->imported_fonts[] = [
|
||||
'id' => $font_id,
|
||||
'title' => $font_data['post_title'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
private function get_existing_font( $font_title ) {
|
||||
$font_query = new \WP_Query( [
|
||||
'post_type' => Fonts_Manager::CPT,
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 1,
|
||||
'title' => $font_title,
|
||||
] );
|
||||
|
||||
if ( $font_query->have_posts() ) {
|
||||
$font_post = $font_query->posts[0];
|
||||
return [
|
||||
'id' => $font_post->ID,
|
||||
'title' => $font_post->post_title,
|
||||
];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function create_font( $font_data ) {
|
||||
$font_id = wp_insert_post( [
|
||||
'post_title' => $font_data['post_title'],
|
||||
'post_content' => $font_data['post_content'],
|
||||
'post_status' => $font_data['post_status'],
|
||||
'post_type' => Fonts_Manager::CPT,
|
||||
] );
|
||||
|
||||
if ( is_wp_error( $font_id ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->set_session_post_meta( $font_id, $this->session_id );
|
||||
|
||||
if ( ! empty( $font_data['font_files'] ) ) {
|
||||
update_post_meta( $font_id, Custom_Fonts::FONT_META_KEY, $font_data['font_files'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $font_data['font_face'] ) ) {
|
||||
update_post_meta( $font_id, Custom_Fonts::FONT_FACE_META_KEY, $font_data['font_face'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $font_data['attachments'] ) ) {
|
||||
$this->import_font_attachments( $font_id, $font_data['attachments'] );
|
||||
}
|
||||
|
||||
return $font_id;
|
||||
}
|
||||
|
||||
private function import_font_attachments( $font_id, $attachments_data ) {
|
||||
$this->create_attachments_from_urls( $font_id, $attachments_data );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\AssetsManager\AssetTypes\Fonts\ImportExportCustomization;
|
||||
|
||||
use Elementor\App\Modules\ImportExportCustomization\Runners\Revert\Revert_Runner_Base;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Fonts_Manager;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Fonts\Custom_Fonts;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Revert_Runner extends Revert_Runner_Base {
|
||||
|
||||
public static function get_name(): string {
|
||||
return 'custom-fonts';
|
||||
}
|
||||
|
||||
public function should_revert( array $data ): bool {
|
||||
return (
|
||||
isset( $data['runners'] ) &&
|
||||
array_key_exists( static::get_name(), $data['runners'] )
|
||||
);
|
||||
}
|
||||
|
||||
public function revert( array $data ) {
|
||||
$metadata = $data['runners'][ static::get_name() ] ?? [];
|
||||
|
||||
if ( empty( $metadata ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->revert_imported_fonts( $metadata );
|
||||
|
||||
$this->revert_attachments( $data['session_id'] );
|
||||
|
||||
$custom_fonts = new Custom_Fonts();
|
||||
$custom_fonts->get_fonts( true );
|
||||
}
|
||||
|
||||
private function revert_imported_fonts( $metadata ) {
|
||||
$imported_fonts = $metadata['imported_fonts'] ?? [];
|
||||
|
||||
foreach ( $imported_fonts as $font ) {
|
||||
$this->delete_font_and_attachments( $font['id'] );
|
||||
}
|
||||
}
|
||||
|
||||
private function revert_attachments( $session_id ) {
|
||||
$attachments_query = new \WP_Query( [
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => 'inherit',
|
||||
'posts_per_page' => -1,
|
||||
'meta_query' => [
|
||||
[
|
||||
'key' => static::META_KEY_ELEMENTOR_IMPORT_SESSION_ID,
|
||||
'value' => $session_id,
|
||||
'compare' => '=',
|
||||
],
|
||||
],
|
||||
] );
|
||||
|
||||
if ( ! $attachments_query->have_posts() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $attachments_query->posts as $attachment ) {
|
||||
wp_delete_attachment( $attachment->ID, true );
|
||||
}
|
||||
}
|
||||
|
||||
private function delete_font_and_attachments( $font_id ) {
|
||||
$attachments = get_attached_media( '', $font_id );
|
||||
foreach ( $attachments as $attachment ) {
|
||||
wp_delete_attachment( $attachment->ID, true );
|
||||
}
|
||||
|
||||
wp_delete_post( $font_id, true );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,11 +34,13 @@ class Export_Runner extends Export_Runner_Base {
|
||||
}
|
||||
|
||||
$fonts_data = [];
|
||||
$manifest_data = [];
|
||||
|
||||
foreach ( $fonts as $font_family => $font_type ) {
|
||||
$font_data = $this->prepare_font_data( $font_family );
|
||||
if ( $font_data ) {
|
||||
$fonts_data[] = $font_data;
|
||||
$manifest['custom-fonts'][ $font_family ] = $font_data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +49,9 @@ class Export_Runner extends Export_Runner_Base {
|
||||
'path' => Import_Export::FILE_NAME,
|
||||
'data' => $fonts_data,
|
||||
],
|
||||
'manifest' => [
|
||||
$manifest_data,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace ElementorPro\Modules\AssetsManager\AssetTypes\Fonts\ImportExport;
|
||||
|
||||
use Elementor\App\Modules\ImportExport\Runners\Import\Import_Runner_Base;
|
||||
use Elementor\App\Modules\ImportExport\Utils as ImportExportUtils;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Fonts_Manager;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Fonts\Custom_Fonts;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\ImportExport\Traits\External_Attachment_Trait;
|
||||
@@ -36,7 +37,8 @@ class Import_Runner extends Import_Runner_Base {
|
||||
|
||||
$result = [];
|
||||
|
||||
$fonts_data = $imported_data['files']['custom-fonts']['data'] ?? [];
|
||||
$custom_fonts_file_path = $data['extracted_directory_path'] . Import_Export::FILE_NAME;
|
||||
$fonts_data = ImportExportUtils::read_json_file( $custom_fonts_file_path );
|
||||
|
||||
if ( empty( $fonts_data ) ) {
|
||||
return $result;
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\AssetsManager\AssetTypes\Icons\ImportExportCustomization;
|
||||
|
||||
use Elementor\App\Modules\ImportExportCustomization\Runners\Export\Export_Runner_Base;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Icons_Manager;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Icons\Custom_Icons;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Export_Runner extends Export_Runner_Base {
|
||||
public static function get_name(): string {
|
||||
return 'custom-icons';
|
||||
}
|
||||
|
||||
public function should_export( array $data ) {
|
||||
return (
|
||||
isset( $data['include'] ) &&
|
||||
in_array( 'settings', $data['include'], true )
|
||||
);
|
||||
}
|
||||
|
||||
public function export( array $data ) {
|
||||
$icon_sets = $this->get_custom_icon_sets();
|
||||
|
||||
$include_custom_icons = $data['customization']['settings']['customIcons'] ?? true;
|
||||
|
||||
if ( empty( $icon_sets ) || ! $include_custom_icons ) {
|
||||
return [
|
||||
'manifest' => [],
|
||||
'files' => [],
|
||||
];
|
||||
}
|
||||
|
||||
$icon_sets_data = [];
|
||||
$manifest = [];
|
||||
|
||||
foreach ( $icon_sets as $icon_set ) {
|
||||
$icon_set_data = $this->prepare_icon_set_data( $icon_set );
|
||||
if ( $icon_set_data ) {
|
||||
$icon_sets_data[] = $icon_set_data;
|
||||
$manifest['custom-icons'][ $icon_set->ID ] = $icon_set_data;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'files' => [
|
||||
'path' => Import_Export_Customization::FILE_NAME,
|
||||
'data' => $icon_sets_data,
|
||||
],
|
||||
'manifest' => [
|
||||
$manifest,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
private function get_custom_icon_sets() {
|
||||
return get_posts( [
|
||||
'post_type' => Icons_Manager::CPT,
|
||||
'posts_per_page' => -1,
|
||||
'post_status' => 'publish',
|
||||
] );
|
||||
}
|
||||
|
||||
private function prepare_icon_set_data( $icon_set ) {
|
||||
$icon_set_config = Custom_Icons::get_icon_set_config( $icon_set->ID );
|
||||
$icon_set_path = get_post_meta( $icon_set->ID, '_elementor_icon_set_path', true );
|
||||
|
||||
$icon_type = '';
|
||||
if ( $icon_set_config ) {
|
||||
$config_data = json_decode( $icon_set_config, true );
|
||||
$icon_type = $config_data['custom_icon_type'] ?? '';
|
||||
}
|
||||
|
||||
$attachments = get_attached_media( '', $icon_set->ID );
|
||||
$attachments_data = [];
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
$url = wp_get_attachment_url( $attachment->ID );
|
||||
$attachments_data[] = [
|
||||
'id' => $attachment->ID,
|
||||
'title' => $attachment->post_title,
|
||||
'url' => $url,
|
||||
];
|
||||
|
||||
do_action( 'elementor/templates/collect_media_url', $url, (array) $attachment );
|
||||
}
|
||||
|
||||
return [
|
||||
'ID' => $icon_set->ID,
|
||||
'post_title' => $icon_set->post_title,
|
||||
'post_content' => $icon_set->post_content,
|
||||
'post_status' => $icon_set->post_status,
|
||||
'icon_set_config' => $icon_set_config,
|
||||
'icon_set_path' => $icon_set_path,
|
||||
'icon_type' => $icon_type,
|
||||
'attachments' => $attachments_data,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\AssetsManager\AssetTypes\Icons\ImportExportCustomization;
|
||||
|
||||
use Elementor\App\Modules\ImportExportCustomization\Processes\Export;
|
||||
use Elementor\App\Modules\ImportExportCustomization\Processes\Import;
|
||||
use Elementor\App\Modules\ImportExportCustomization\Processes\Revert;
|
||||
|
||||
class Import_Export_Customization {
|
||||
const FILE_NAME = 'custom-icons';
|
||||
|
||||
public function register_hooks() {
|
||||
add_action( 'elementor/import-export-customization/export-kit', function ( Export $export ) {
|
||||
$export->register( new Export_Runner() );
|
||||
} );
|
||||
|
||||
add_action( 'elementor/import-export-customization/import-kit', function ( Import $import ) {
|
||||
$import->register( new Import_Runner() );
|
||||
} );
|
||||
|
||||
add_action( 'elementor/import-export-customization/revert-kit', function ( Revert $revert ) {
|
||||
$revert->register( new Revert_Runner() );
|
||||
} );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\AssetsManager\AssetTypes\Icons\ImportExportCustomization;
|
||||
|
||||
use Elementor\App\Modules\ImportExportCustomization\Runners\Import\Import_Runner_Base;
|
||||
use Elementor\App\Modules\ImportExportCustomization\Utils as ImportExportUtils;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Icons_Manager;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Icons\Custom_Icons;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\ImportExport\Traits\External_Attachment_Trait;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Import_Runner extends Import_Runner_Base {
|
||||
use External_Attachment_Trait;
|
||||
|
||||
private $session_id;
|
||||
private $imported_icon_sets = [];
|
||||
|
||||
public static function get_name(): string {
|
||||
return 'custom-icons';
|
||||
}
|
||||
|
||||
public function should_import( array $data ) {
|
||||
return (
|
||||
isset( $data['include'] ) &&
|
||||
in_array( 'settings', $data['include'], true )
|
||||
);
|
||||
}
|
||||
|
||||
public function import( array $data, array $imported_data ) {
|
||||
$this->session_id = $data['session_id'];
|
||||
|
||||
$result = [];
|
||||
|
||||
$custom_icons_file_path = $data['extracted_directory_path'] . Import_Export_Customization::FILE_NAME;
|
||||
$icon_sets_data = ImportExportUtils::read_json_file( $custom_icons_file_path );
|
||||
|
||||
$include_custom_icons = $data['customization']['settings']['customIcons'] ?? true;
|
||||
|
||||
if ( empty( $icon_sets_data ) || ! $include_custom_icons ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
foreach ( $icon_sets_data as $icon_set_data ) {
|
||||
$this->import_icon_set( $icon_set_data );
|
||||
}
|
||||
|
||||
if ( empty( $this->imported_icon_sets ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
$result['site-settings']['custom-icons'] = $this->imported_icon_sets;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function get_import_session_metadata(): array {
|
||||
return [
|
||||
'imported_icon_sets' => $this->imported_icon_sets,
|
||||
];
|
||||
}
|
||||
|
||||
private function import_icon_set( $icon_set_data ) {
|
||||
$existing_icon_set = $this->get_existing_icon_set( $icon_set_data['post_title'] );
|
||||
|
||||
if ( $existing_icon_set ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$icon_set_id = $this->create_icon_set( $icon_set_data );
|
||||
|
||||
if ( $icon_set_id ) {
|
||||
$this->imported_icon_sets[] = [
|
||||
'id' => $icon_set_id,
|
||||
'title' => $icon_set_data['post_title'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
private function get_existing_icon_set( $icon_set_title ) {
|
||||
$icon_set_query = new \WP_Query( [
|
||||
'post_type' => Icons_Manager::CPT,
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 1,
|
||||
'title' => $icon_set_title,
|
||||
] );
|
||||
|
||||
if ( $icon_set_query->have_posts() ) {
|
||||
$icon_set_post = $icon_set_query->posts[0];
|
||||
return [
|
||||
'id' => $icon_set_post->ID,
|
||||
'title' => $icon_set_post->post_title,
|
||||
];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function create_icon_set( $icon_set_data ) {
|
||||
$icon_set_id = wp_insert_post( [
|
||||
'post_title' => $icon_set_data['post_title'],
|
||||
'post_content' => $icon_set_data['post_content'],
|
||||
'post_status' => $icon_set_data['post_status'],
|
||||
'post_type' => Icons_Manager::CPT,
|
||||
] );
|
||||
|
||||
if ( is_wp_error( $icon_set_id ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->set_session_post_meta( $icon_set_id, $this->session_id );
|
||||
|
||||
if ( ! empty( $icon_set_data['icon_set_config'] ) ) {
|
||||
update_post_meta( $icon_set_id, Custom_Icons::META_KEY, $icon_set_data['icon_set_config'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $icon_set_data['icon_set_path'] ) ) {
|
||||
update_post_meta( $icon_set_id, '_elementor_icon_set_path', $icon_set_data['icon_set_path'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $icon_set_data['attachments'] ) ) {
|
||||
$this->handle_icon_set_attachments( $icon_set_id, $icon_set_data['attachments'] );
|
||||
}
|
||||
|
||||
Custom_Icons::clear_icon_list_option();
|
||||
|
||||
return $icon_set_id;
|
||||
}
|
||||
|
||||
private function handle_icon_set_attachments( $icon_set_id, $attachments_data ) {
|
||||
$this->create_attachments_from_urls( $icon_set_id, $attachments_data );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace ElementorPro\Modules\AssetsManager\AssetTypes\Icons\ImportExportCustomization;
|
||||
|
||||
use Elementor\App\Modules\ImportExportCustomization\Runners\Revert\Revert_Runner_Base;
|
||||
use Elementor\Plugin;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Icons\Custom_Icons;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Revert_Runner extends Revert_Runner_Base {
|
||||
|
||||
public static function get_name(): string {
|
||||
return 'custom-icons';
|
||||
}
|
||||
|
||||
public function should_revert( array $data ): bool {
|
||||
return (
|
||||
isset( $data['runners'] ) &&
|
||||
array_key_exists( static::get_name(), $data['runners'] )
|
||||
);
|
||||
}
|
||||
|
||||
public function revert( array $data ) {
|
||||
$metadata = $data['runners'][ static::get_name() ] ?? [];
|
||||
|
||||
if ( empty( $metadata ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->revert_imported_icon_sets( $metadata );
|
||||
|
||||
$this->revert_attachments( $data['session_id'] );
|
||||
|
||||
Custom_Icons::clear_icon_list_option();
|
||||
}
|
||||
|
||||
private function revert_imported_icon_sets( $metadata ) {
|
||||
$imported_icon_sets = $metadata['imported_icon_sets'] ?? [];
|
||||
|
||||
foreach ( $imported_icon_sets as $icon_set ) {
|
||||
$this->delete_icon_set_and_attachments( $icon_set['id'] );
|
||||
}
|
||||
}
|
||||
|
||||
private function revert_attachments( $session_id ) {
|
||||
$attachments_query = new \WP_Query( [
|
||||
'post_type' => 'attachment',
|
||||
'post_status' => 'inherit',
|
||||
'posts_per_page' => -1,
|
||||
'meta_query' => [
|
||||
[
|
||||
'key' => static::META_KEY_ELEMENTOR_IMPORT_SESSION_ID,
|
||||
'value' => $session_id,
|
||||
'compare' => '=',
|
||||
],
|
||||
],
|
||||
] );
|
||||
|
||||
if ( ! $attachments_query->have_posts() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $attachments_query->posts as $attachment ) {
|
||||
wp_delete_attachment( $attachment->ID, true );
|
||||
}
|
||||
}
|
||||
|
||||
private function delete_icon_set_and_attachments( $icon_set_id ) {
|
||||
$icon_set_path = get_post_meta( $icon_set_id, '_elementor_icon_set_path', true );
|
||||
if ( $icon_set_path && is_dir( $icon_set_path ) ) {
|
||||
Plugin::$instance->uploads_manager->remove_file_or_dir( $icon_set_path );
|
||||
}
|
||||
|
||||
$attachments = get_attached_media( '', $icon_set_id );
|
||||
|
||||
foreach ( $attachments as $attachment ) {
|
||||
wp_delete_attachment( $attachment->ID, true );
|
||||
}
|
||||
|
||||
wp_delete_post( $icon_set_id, true );
|
||||
}
|
||||
}
|
||||
@@ -33,11 +33,13 @@ class Export_Runner extends Export_Runner_Base {
|
||||
}
|
||||
|
||||
$icon_sets_data = [];
|
||||
$manifest = [];
|
||||
|
||||
foreach ( $icon_sets as $icon_set ) {
|
||||
$icon_set_data = $this->prepare_icon_set_data( $icon_set );
|
||||
if ( $icon_set_data ) {
|
||||
$icon_sets_data[] = $icon_set_data;
|
||||
$manifest['custom-icons'][ $icon_set->ID ] = $icon_set_data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +48,9 @@ class Export_Runner extends Export_Runner_Base {
|
||||
'path' => Import_Export::FILE_NAME,
|
||||
'data' => $icon_sets_data,
|
||||
],
|
||||
'manifest' => [
|
||||
$manifest,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ class Import_Runner extends Import_Runner_Base {
|
||||
|
||||
$result = [];
|
||||
|
||||
$icon_sets_data = $imported_data['files']['custom-icons']['data'] ?? [];
|
||||
$custom_icons_file_path = $data['extracted_directory_path'] . Import_Export::FILE_NAME;
|
||||
$icon_sets_data = ImportExportUtils::read_json_file( $custom_icons_file_path );
|
||||
|
||||
if ( empty( $icon_sets_data ) ) {
|
||||
return $result;
|
||||
|
||||
@@ -2,12 +2,34 @@
|
||||
|
||||
namespace ElementorPro\Modules\AssetsManager\AssetTypes\ImportExport\Traits;
|
||||
|
||||
use Elementor\Plugin;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
trait External_Attachment_Trait {
|
||||
private function create_attachment_from_url( $parent_id, $attachment_data ) {
|
||||
$local_file_path = \Elementor\TemplateLibrary\Classes\Media_Mapper::get_local_file_path( $attachment_data['url'] );
|
||||
$imported_attachment = false;
|
||||
|
||||
if ( $local_file_path !== $attachment_data['url'] && file_exists( $local_file_path ) ) {
|
||||
$imported_attachment = Plugin::$instance->templates_manager->get_import_images_instance()->import_local_file( $local_file_path, $parent_id );
|
||||
}
|
||||
|
||||
if ( $imported_attachment ) {
|
||||
wp_update_post( [
|
||||
'ID' => $imported_attachment['id'],
|
||||
'post_title' => $attachment_data['title'],
|
||||
'post_content' => '',
|
||||
'post_status' => 'inherit',
|
||||
'post_parent' => $parent_id,
|
||||
'post_mime_type' => 'application/octet-stream',
|
||||
] );
|
||||
|
||||
return $imported_attachment['id'];
|
||||
}
|
||||
|
||||
$attachment_id = wp_insert_attachment( [
|
||||
'post_title' => $attachment_data['title'],
|
||||
'post_content' => '',
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
namespace ElementorPro\Modules\AssetsManager;
|
||||
|
||||
use ElementorPro\Base\Module_Base;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Fonts\ImportExport\Import_Export as Fonts_Import_Export;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Fonts\ImportExportCustomization\Import_Export_Customization as Fonts_Import_Export_Customization;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Icons\ImportExport\Import_Export as Icons_Import_Export;
|
||||
use ElementorPro\Plugin;
|
||||
use ElementorPro\Modules\AssetsManager\AssetTypes\Icons\ImportExportCustomization\Import_Export_Customization as Icons_Import_Export_Customization;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly
|
||||
@@ -46,6 +46,8 @@ class Module extends Module_Base {
|
||||
|
||||
private function register_import_export() {
|
||||
( new Fonts_Import_Export() )->register_hooks();
|
||||
( new Fonts_Import_Export_Customization() )->register_hooks();
|
||||
( new Icons_Import_Export() )->register_hooks();
|
||||
( new Icons_Import_Export_Customization() )->register_hooks();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user