Initial commit: Atomaste website
This commit is contained in:
@@ -0,0 +1,312 @@
|
||||
<?php
|
||||
/**
|
||||
* Batch Processing
|
||||
*
|
||||
* @package Astra Sites
|
||||
* @since 1.0.14
|
||||
*/
|
||||
|
||||
use STImporter\Importer\Helpers\ST_Image_Importer;
|
||||
|
||||
if ( ! class_exists( 'Astra_Sites_Batch_Processing_Beaver_Builder' ) ) :
|
||||
|
||||
/**
|
||||
* Astra_Sites_Batch_Processing_Beaver_Builder
|
||||
*
|
||||
* @since 1.0.14
|
||||
*/
|
||||
class Astra_Sites_Batch_Processing_Beaver_Builder {
|
||||
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @since 1.0.14
|
||||
* @access private
|
||||
* @var object Class object.
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Initiator
|
||||
*
|
||||
* @since 1.0.14
|
||||
* @return object initialized object of class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 1.0.14
|
||||
*/
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Import
|
||||
*
|
||||
* @since 1.0.14
|
||||
* @return void
|
||||
*/
|
||||
public function import() {
|
||||
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
WP_CLI::line( 'Processing "Beaver Builder" Batch Import' );
|
||||
}
|
||||
|
||||
Astra_Sites_Importer_Log::add( '---- Processing WordPress Posts / Pages - for Beaver Builder ----' );
|
||||
|
||||
if ( ! is_callable( 'FLBuilderModel::get_post_types' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_types = FLBuilderModel::get_post_types( 'post-types' );
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
WP_CLI::line( 'For post types: ' . implode( ', ', $post_types ) );
|
||||
}
|
||||
if ( empty( $post_types ) && ! is_array( $post_types ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types );
|
||||
if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $post_ids as $post_id ) {
|
||||
$this->import_single_post( $post_id );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update post meta.
|
||||
*
|
||||
* @param integer $post_id Post ID.
|
||||
* @return void
|
||||
*/
|
||||
public function import_single_post( $post_id = 0 ) {
|
||||
|
||||
$is_bb_post = get_post_meta( $post_id, '_fl_builder_enabled', true );
|
||||
if ( ! $is_bb_post ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Is page imported with Starter Sites?
|
||||
// If not then skip batch process.
|
||||
$imported_from_demo_site = get_post_meta( $post_id, '_astra_sites_enable_for_batch', true );
|
||||
if ( ! $imported_from_demo_site ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
WP_CLI::line( 'Beaver Builder - Processing page: ' . $post_id );
|
||||
}
|
||||
Astra_Sites_Importer_Log::add( '---- Processing WordPress Page - for Beaver Builder ---- "' . $post_id . '"' );
|
||||
|
||||
if ( ! empty( $post_id ) ) {
|
||||
|
||||
// Get page builder data.
|
||||
$data = get_post_meta( $post_id, '_fl_builder_data', true );
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
foreach ( $data as $key => $el ) {
|
||||
|
||||
// Update 'row' images.
|
||||
if ( 'row' === $el->type ) {
|
||||
$data[ $key ]->settings = self::update_row( $el->settings );
|
||||
}
|
||||
|
||||
// Update 'module' images.
|
||||
if ( 'module' === $el->type ) {
|
||||
$data[ $key ]->settings = self::update_module( $el->settings );
|
||||
}
|
||||
|
||||
// Update 'column' images.
|
||||
if ( 'column' === $el->type ) {
|
||||
$data[ $key ]->settings = self::update_column( $el->settings );
|
||||
}
|
||||
}
|
||||
|
||||
// Update page builder data.
|
||||
update_post_meta( $post_id, '_fl_builder_data', $data );
|
||||
update_post_meta( $post_id, '_fl_builder_draft', $data );
|
||||
|
||||
// Clear all cache.
|
||||
FLBuilderModel::delete_asset_cache_for_all_posts();
|
||||
}
|
||||
|
||||
// Clean the post excerpt.
|
||||
astra_sites_empty_post_excerpt( $post_id );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Import Module Images.
|
||||
*
|
||||
* @param object $settings Module settings object.
|
||||
* @return object
|
||||
*/
|
||||
public static function update_module( $settings ) {
|
||||
|
||||
// 1) Set photos.
|
||||
$settings = self::import_photo( $settings );
|
||||
|
||||
/**
|
||||
* 2) Set `$settings->data` for Only type 'image-icon'
|
||||
*
|
||||
* @todo Remove the condition `'image-icon' === $settings->type` if `$settings->data` is used only for the Image Icon.
|
||||
*/
|
||||
if (
|
||||
isset( $settings->data ) &&
|
||||
isset( $settings->photo ) && ! empty( $settings->photo ) &&
|
||||
'image-icon' === $settings->type
|
||||
) {
|
||||
$settings->data = FLBuilderPhoto::get_attachment_data( $settings->photo );
|
||||
}
|
||||
|
||||
if ( 'uabb-wp-forms-styler' === $settings->type ) {
|
||||
astra_sites_error_log( '--------WP Form Styler ID replacement start-------' );
|
||||
$ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
|
||||
if ( $ids_mapping ) {
|
||||
// Update WP form IDs.
|
||||
foreach ( $ids_mapping as $old_id => $new_id ) {
|
||||
if ( isset( $settings->wp_form_id ) && $old_id === $settings->wp_form_id ) {
|
||||
astra_sites_error_log( '--------WP Form Styler ID ' . $old_id . ' replaced to ' . $new_id . '-------' );
|
||||
$settings->wp_form_id = $new_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
astra_sites_error_log( '--------WP Form Styler ID replacement done-------' );
|
||||
}
|
||||
|
||||
// 3) Set `list item` module images.
|
||||
if ( isset( $settings->add_list_item ) ) {
|
||||
foreach ( $settings->add_list_item as $key => $value ) {
|
||||
$settings->add_list_item[ $key ] = self::import_photo( $value );
|
||||
}
|
||||
}
|
||||
|
||||
// 4) Set `list item` module images.
|
||||
if ( isset( $settings->text ) ) {
|
||||
$settings->text = self::get_wpforms_mapping( $settings->text );
|
||||
} elseif ( isset( $settings->html ) ) {
|
||||
$settings->html = self::get_wpforms_mapping( $settings->html );
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace WP Forms shortcode.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @param string $content Content.
|
||||
* @return string Content.
|
||||
*/
|
||||
private static function get_wpforms_mapping( $content = '' ) {
|
||||
$ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
|
||||
astra_sites_error_log( wp_json_encode( $ids_mapping ) );
|
||||
if ( $ids_mapping ) {
|
||||
// Update WP form IDs.
|
||||
foreach ( $ids_mapping as $old_id => $new_id ) {
|
||||
$content = str_replace( '[wpforms id="' . $old_id, '[wpforms id="' . $new_id, $content );
|
||||
}
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import Column Images.
|
||||
*
|
||||
* @param object $settings Column settings object.
|
||||
* @return object
|
||||
*/
|
||||
public static function update_column( $settings ) {
|
||||
|
||||
// 1) Set BG Images.
|
||||
$settings = self::import_bg_image( $settings );
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import Row Images.
|
||||
*
|
||||
* @param object $settings Row settings object.
|
||||
* @return object
|
||||
*/
|
||||
public static function update_row( $settings ) {
|
||||
|
||||
// 1) Set BG Images.
|
||||
$settings = self::import_bg_image( $settings );
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper: Import BG Images.
|
||||
*
|
||||
* @param object $settings Row settings object.
|
||||
* @return object
|
||||
*/
|
||||
public static function import_bg_image( $settings ) {
|
||||
|
||||
if (
|
||||
( ! empty( $settings->bg_image ) && ! empty( $settings->bg_image_src ) )
|
||||
) {
|
||||
$image = array(
|
||||
'url' => $settings->bg_image_src,
|
||||
'id' => $settings->bg_image,
|
||||
);
|
||||
|
||||
$downloaded_image = ST_Image_Importer::get_instance()->import( $image );
|
||||
|
||||
$settings->bg_image_src = $downloaded_image['url'];
|
||||
$settings->bg_image = $downloaded_image['id'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper: Import Photo.
|
||||
*
|
||||
* @param object $settings Row settings object.
|
||||
* @return object
|
||||
*/
|
||||
public static function import_photo( $settings ) {
|
||||
|
||||
if ( ! empty( $settings->photo ) && ! empty( $settings->photo_src ) ) {
|
||||
|
||||
$image = array(
|
||||
'url' => $settings->photo_src,
|
||||
'id' => $settings->photo,
|
||||
);
|
||||
|
||||
$downloaded_image = ST_Image_Importer::get_instance()->import( $image );
|
||||
|
||||
$settings->photo_src = $downloaded_image['url'];
|
||||
$settings->photo = $downloaded_image['id'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicking this off by calling 'get_instance()' method
|
||||
*/
|
||||
Astra_Sites_Batch_Processing_Beaver_Builder::get_instance();
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
/**
|
||||
* Batch Processing
|
||||
*
|
||||
* @package Astra Sites
|
||||
* @since 1.2.14
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'Astra_Sites_Batch_Processing_Brizy' ) ) :
|
||||
|
||||
/**
|
||||
* Astra Sites Batch Processing Brizy
|
||||
*
|
||||
* @since 1.2.14
|
||||
*/
|
||||
class Astra_Sites_Batch_Processing_Brizy {
|
||||
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @since 1.2.14
|
||||
* @access private
|
||||
* @var object Class object.
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Initiator
|
||||
*
|
||||
* @since 1.2.14
|
||||
* @return object initialized object of class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 1.2.14
|
||||
*/
|
||||
public function __construct() {}
|
||||
|
||||
/**
|
||||
* Import
|
||||
*
|
||||
* @since 1.2.14
|
||||
* @return void
|
||||
*/
|
||||
public function import() {
|
||||
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
WP_CLI::line( 'Processing "Brizy" Batch Import' );
|
||||
}
|
||||
|
||||
Astra_Sites_Importer_Log::add( '---- Processing WordPress Posts / Pages - for "Brizy" ----' );
|
||||
|
||||
if ( ! is_callable( 'Brizy_Editor_Storage_Common::instance' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_types = Brizy_Editor_Storage_Common::instance()->get( 'post-types' );
|
||||
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
WP_CLI::line( 'For post types: ' . implode( ', ', $post_types ) );
|
||||
}
|
||||
|
||||
if ( empty( $post_types ) && ! is_array( $post_types ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_ids = Astra_Sites_Batch_Processing::get_pages( $post_types );
|
||||
if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $post_ids as $post_id ) {
|
||||
$this->import_single_post( $post_id );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update post meta.
|
||||
*
|
||||
* @param integer $post_id Post ID.
|
||||
* @return void
|
||||
*/
|
||||
public function import_single_post( $post_id = 0 ) {
|
||||
|
||||
$is_brizy_post = get_post_meta( $post_id, 'brizy_post_uid', true );
|
||||
if ( ! $is_brizy_post ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Is page imported with Starter Sites?
|
||||
// If not then skip batch process.
|
||||
$imported_from_demo_site = get_post_meta( $post_id, '_astra_sites_enable_for_batch', true );
|
||||
if ( ! $imported_from_demo_site ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
WP_CLI::line( 'Brizy - Processing page: ' . $post_id );
|
||||
}
|
||||
|
||||
astra_sites_error_log( '---- Processing WordPress Page - for "Brizy" ---- "' . $post_id . '"' );
|
||||
|
||||
$ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
|
||||
|
||||
$json_value = null;
|
||||
|
||||
$post = Brizy_Editor_Post::get( (int) $post_id );
|
||||
$editor_data = $post->get_editor_data();
|
||||
|
||||
// Empty mapping? Then return.
|
||||
if ( ! empty( $ids_mapping ) ) {
|
||||
|
||||
// Update WPForm IDs.
|
||||
astra_sites_error_log( '---- Processing WP Forms Mapping ----' );
|
||||
astra_sites_error_log( $ids_mapping );
|
||||
|
||||
foreach ( $ids_mapping as $old_id => $new_id ) {
|
||||
$editor_data = str_replace( '[wpforms id=\"' . $old_id, '[wpforms id=\"' . $new_id, $editor_data );
|
||||
}
|
||||
}
|
||||
|
||||
$post->set_editor_data( $editor_data );
|
||||
$post->set_needs_compile( $post->get_needs_compile() );
|
||||
$post->set_editor_version( BRIZY_EDITOR_VERSION );
|
||||
$post->set_compiler_version( BRIZY_EDITOR_VERSION );
|
||||
$post->set_plugin_version( BRIZY_VERSION );
|
||||
$post->saveStorage();
|
||||
$post->savePost();
|
||||
|
||||
// Clean the post excerpt.
|
||||
astra_sites_empty_post_excerpt( $post_id );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicking this off by calling 'get_instance()' method
|
||||
*/
|
||||
Astra_Sites_Batch_Processing_Brizy::get_instance();
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Cleanup batch import tasks.
|
||||
*
|
||||
* @package Astra Sites
|
||||
* @since 4.0.11
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'Astra_Sites_Batch_Processing_Cleanup' ) ) :
|
||||
|
||||
/**
|
||||
* Astra_Sites_Batch_Processing_Cleanup
|
||||
*
|
||||
* @since 4.0.11
|
||||
*/
|
||||
class Astra_Sites_Batch_Processing_Cleanup {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 4.0.11
|
||||
*/
|
||||
public function __construct() {}
|
||||
|
||||
/**
|
||||
* Import
|
||||
*
|
||||
* @since 4.0.11
|
||||
* @return void
|
||||
*/
|
||||
public function import() {
|
||||
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
WP_CLI::line( 'Processing "Cleanup" Batch Import' );
|
||||
}
|
||||
|
||||
update_option( 'st_attachments', array(), 'no' );
|
||||
delete_option( 'st_attachments_offset' );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Customizer batch import tasks.
|
||||
*
|
||||
* @package Astra Sites
|
||||
* @since 3.0.22
|
||||
*/
|
||||
|
||||
use STImporter\Importer\Helpers\ST_Image_Importer;
|
||||
|
||||
/**
|
||||
* Astra_Sites_Batch_Processing_Customizer
|
||||
*
|
||||
* @since 3.0.22
|
||||
*/
|
||||
class Astra_Sites_Batch_Processing_Customizer {
|
||||
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @since 3.0.22
|
||||
* @access private
|
||||
* @var object Class object.
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Initiator
|
||||
*
|
||||
* @since 3.0.22
|
||||
* @return object initialized object of class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 3.0.22
|
||||
*/
|
||||
public function __construct() {}
|
||||
|
||||
/**
|
||||
* Import
|
||||
*
|
||||
* @since 3.0.22
|
||||
* @return void
|
||||
*/
|
||||
public function import() {
|
||||
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
WP_CLI::line( 'Processing "Customizer" Batch Import' );
|
||||
}
|
||||
|
||||
Astra_Sites_Importer_Log::add( '---- Processing batch process for Customizer start ----' );
|
||||
self::images_download();
|
||||
Astra_Sites_Importer_Log::add( '---- Processing batch process for Customizer done ----' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads images from customizer.
|
||||
*/
|
||||
public static function images_download() {
|
||||
$options = get_option( 'astra-settings', array() );
|
||||
array_walk_recursive(
|
||||
$options,
|
||||
function ( &$value ) {
|
||||
if ( ! is_array( $value ) && astra_sites_is_valid_image( $value ) ) {
|
||||
$downloaded_image = ST_Image_Importer::get_instance()->import(
|
||||
array(
|
||||
'url' => $value,
|
||||
'id' => 0,
|
||||
)
|
||||
);
|
||||
$value = $downloaded_image['url'];
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
// Updated settings.
|
||||
update_option( 'astra-settings', $options );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicking this off by calling 'get_instance()' method
|
||||
*/
|
||||
Astra_Sites_Batch_Processing_Customizer::get_instance();
|
||||
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
* Elementor Importer
|
||||
*
|
||||
* @package Astra Sites
|
||||
*/
|
||||
|
||||
namespace Elementor\TemplateLibrary;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
// If plugin - 'Elementor' not exist then return.
|
||||
if ( ! class_exists( '\Elementor\Plugin' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
use Elementor\Core\Base\Document;
|
||||
use Elementor\Core\Editor\Editor;
|
||||
use Elementor\DB;
|
||||
use Elementor\Core\Settings\Manager as SettingsManager;
|
||||
use Elementor\Core\Settings\Page\Model;
|
||||
use Elementor\Modules\Library\Documents\Library_Document;
|
||||
use Elementor\Plugin;
|
||||
use Elementor\Utils;
|
||||
|
||||
/**
|
||||
* Elementor template library local source.
|
||||
*
|
||||
* Elementor template library local source handler class is responsible for
|
||||
* handling local Elementor templates saved by the user locally on his site.
|
||||
*
|
||||
* @since 1.2.13 Added compatibility for Elemetnor v2.5.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Astra_Sites_Batch_Processing_Elementor extends Source_Local {
|
||||
|
||||
/**
|
||||
* Import
|
||||
*
|
||||
* @since 1.0.14
|
||||
* @return void
|
||||
*/
|
||||
public function import() {
|
||||
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
\WP_CLI::line( 'Processing "Elementor" Batch Import' );
|
||||
}
|
||||
\Astra_Sites_Importer_Log::add( '---- Processing WordPress Posts / Pages - for Elementor ----' );
|
||||
$post_types = \Astra_Sites_Batch_Processing::get_post_types_supporting( 'elementor' );
|
||||
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
\WP_CLI::line( 'For post types: ' . implode( ', ', $post_types ) );
|
||||
}
|
||||
if ( empty( $post_types ) && ! is_array( $post_types ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$post_ids = \Astra_Sites_Batch_Processing::get_pages( $post_types );
|
||||
if ( empty( $post_ids ) && ! is_array( $post_ids ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $post_ids as $post_id ) {
|
||||
$this->import_single_post( $post_id );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update post meta.
|
||||
*
|
||||
* @since 1.0.14
|
||||
* @param integer $post_id Post ID.
|
||||
* @return void
|
||||
*/
|
||||
public function import_single_post( $post_id = 0 ) {
|
||||
|
||||
$is_elementor_post = get_post_meta( $post_id, '_elementor_version', true );
|
||||
if ( ! $is_elementor_post ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Is page imported with Starter Sites?
|
||||
// If not then skip batch process.
|
||||
$imported_from_demo_site = get_post_meta( $post_id, '_astra_sites_enable_for_batch', true );
|
||||
if ( ! $imported_from_demo_site ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
\WP_CLI::line( 'Elementor - Processing page: ' . $post_id );
|
||||
}
|
||||
|
||||
\Astra_Sites_Importer_Log::add( '---- Processing WordPress Page - for Elementor ---- "' . $post_id . '"' );
|
||||
|
||||
if ( ! empty( $post_id ) ) {
|
||||
|
||||
$data = get_post_meta( $post_id, '_elementor_data', true );
|
||||
|
||||
\Astra_Sites_Importer_Log::add( wp_json_encode( $data ) );
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
|
||||
// Update WP form IDs.
|
||||
$ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
|
||||
\Astra_Sites_Importer_Log::add( wp_json_encode( $ids_mapping ) );
|
||||
if ( $ids_mapping ) {
|
||||
foreach ( $ids_mapping as $old_id => $new_id ) {
|
||||
$data = str_replace( '[wpforms id=\"' . $old_id, '[wpforms id=\"' . $new_id, $data );
|
||||
$data = str_replace( '"select_form":"' . $old_id, '"select_form":"' . $new_id, $data );
|
||||
$data = str_replace( '"form_id":"' . $old_id, '"form_id":"' . $new_id, $data );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! is_array( $data ) ) {
|
||||
$data = json_decode( $data, true );
|
||||
}
|
||||
\Astra_Sites_Importer_Log::add( wp_json_encode( $data ) );
|
||||
|
||||
$document = Plugin::$instance->documents->get( $post_id );
|
||||
if ( $document ) {
|
||||
$data = $document->get_elements_raw_data( $data, true );
|
||||
}
|
||||
|
||||
// Import the data.
|
||||
$data = $this->process_export_import_content( $data, 'on_import' );
|
||||
|
||||
// Replace the site urls.
|
||||
$demo_data = \Astra_Sites_File_System::get_instance()->get_demo_content();
|
||||
\Astra_Sites_Importer_Log::add( wp_json_encode( $demo_data ) );
|
||||
if ( isset( $demo_data['astra-site-url'] ) ) {
|
||||
$data = wp_json_encode( $data );
|
||||
if ( ! empty( $data ) ) {
|
||||
$site_url = get_site_url();
|
||||
$site_url = str_replace( '/', '\/', $site_url );
|
||||
$demo_site_url = 'https:' . $demo_data['astra-site-url'];
|
||||
$demo_site_url = str_replace( '/', '\/', $demo_site_url );
|
||||
$data = str_replace( $demo_site_url, $site_url, $data );
|
||||
$data = json_decode( $data, true );
|
||||
}
|
||||
}
|
||||
|
||||
// Update processed meta.
|
||||
update_metadata( 'post', $post_id, '_elementor_data', $data );
|
||||
update_metadata( 'post', $post_id, '_astra_sites_hotlink_imported', true );
|
||||
|
||||
// !important, Clear the cache after images import.
|
||||
Plugin::$instance->files_manager->clear_cache();
|
||||
}
|
||||
|
||||
// Clean the post excerpt.
|
||||
$clean_post_excerpt = apply_filters( 'astra_sites_pre_process_post_empty_excerpt', true );
|
||||
if ( $clean_post_excerpt ) {
|
||||
astra_sites_empty_post_excerpt( $post_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,397 @@
|
||||
<?php
|
||||
/**
|
||||
* Batch Processing
|
||||
*
|
||||
* @package Astra Sites
|
||||
* @since 2.0.0
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'Astra_Sites_Batch_Processing_Importer' ) ) :
|
||||
|
||||
/**
|
||||
* Astra_Sites_Batch_Processing_Importer
|
||||
*
|
||||
* @since 1.0.14
|
||||
*/
|
||||
class Astra_Sites_Batch_Processing_Importer {
|
||||
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @since 1.0.14
|
||||
* @access private
|
||||
* @var object Class object.
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Initiator
|
||||
*
|
||||
* @since 1.0.14
|
||||
* @return object initialized object of class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 1.0.14
|
||||
*/
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Import All Categories and Tags
|
||||
*
|
||||
* @since 2.6.22
|
||||
* @return void
|
||||
*/
|
||||
public function import_all_categories_and_tags() {
|
||||
astra_sites_error_log( 'Requesting Site Categories' );
|
||||
update_site_option( 'astra-sites-batch-status-string', 'Requesting Site Categories' );
|
||||
|
||||
$api_args = array(
|
||||
'timeout' => 30,
|
||||
);
|
||||
$request = wp_safe_remote_get( trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-content/uploads/all-site-categories.json', $api_args );
|
||||
if ( ! is_wp_error( $request ) && 200 === (int) wp_remote_retrieve_response_code( $request ) ) {
|
||||
$cats = json_decode( wp_remote_retrieve_body( $request ), true );
|
||||
|
||||
if ( isset( $cats['code'] ) ) {
|
||||
$message = isset( $cats['message'] ) ? $cats['message'] : '';
|
||||
if ( ! empty( $message ) ) {
|
||||
astra_sites_error_log( 'HTTP Request Error: ' . $message );
|
||||
} else {
|
||||
astra_sites_error_log( 'HTTP Request Error!' );
|
||||
}
|
||||
} else {
|
||||
Astra_Sites_File_System::get_instance()->update_json_file( 'astra-sites-all-site-categories-and-tags.json', $cats );
|
||||
do_action( 'astra_sites_sync_all_site_categories_and_tags', $cats );
|
||||
}
|
||||
}
|
||||
|
||||
astra_sites_error_log( 'Site Categories Imported Successfully!' );
|
||||
update_site_option( 'astra-sites-batch-status-string', 'Site Categories Imported Successfully!' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Import All Categories and Tags
|
||||
*
|
||||
* @since 2.6.22
|
||||
* @return void
|
||||
*/
|
||||
public function import_all_categories() {
|
||||
astra_sites_error_log( 'Requesting Site Categories' );
|
||||
update_site_option( 'astra-sites-batch-status-string', 'Requesting Site Categories' );
|
||||
|
||||
$api_args = array(
|
||||
'timeout' => 30,
|
||||
);
|
||||
$request = wp_safe_remote_get( trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/wp/v2/astra-sites-site-category/?hide_empty=true&_fields=id,name,slug&per_page=100', $api_args );
|
||||
if ( ! is_wp_error( $request ) && 200 === (int) wp_remote_retrieve_response_code( $request ) ) {
|
||||
$cats = json_decode( wp_remote_retrieve_body( $request ), true );
|
||||
|
||||
if ( isset( $cats['code'] ) ) {
|
||||
$message = isset( $cats['message'] ) ? $cats['message'] : '';
|
||||
if ( ! empty( $message ) ) {
|
||||
astra_sites_error_log( 'HTTP Request Error: ' . $message );
|
||||
} else {
|
||||
astra_sites_error_log( 'HTTP Request Error!' );
|
||||
}
|
||||
} else {
|
||||
Astra_Sites_File_System::get_instance()->update_json_file( 'astra-sites-all-site-categories.json', $cats );
|
||||
do_action( 'astra_sites_sync_all_site_categories', $cats );
|
||||
}
|
||||
}
|
||||
|
||||
astra_sites_error_log( 'Site Categories Imported Successfully!' );
|
||||
update_site_option( 'astra-sites-batch-status-string', 'Site Categories Imported Successfully!' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Import Categories
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function import_site_categories() {
|
||||
astra_sites_error_log( 'Requesting Site Categories' );
|
||||
update_site_option( 'astra-sites-batch-status-string', 'Requesting Site Categories' );
|
||||
|
||||
$api_args = array(
|
||||
'timeout' => 30,
|
||||
);
|
||||
$categories_request = wp_safe_remote_get( trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/wp/v2/astra-sites-site-category/?hide_empty=true&_fields=id,name,slug&per_page=100', $api_args );
|
||||
if ( ! is_wp_error( $categories_request ) && 200 === (int) wp_remote_retrieve_response_code( $categories_request ) ) {
|
||||
$categories = json_decode( wp_remote_retrieve_body( $categories_request ), true );
|
||||
|
||||
if ( isset( $categories['code'] ) ) {
|
||||
$message = isset( $categories['message'] ) ? $categories['message'] : '';
|
||||
if ( ! empty( $message ) ) {
|
||||
astra_sites_error_log( 'HTTP Request Error: ' . $message );
|
||||
} else {
|
||||
astra_sites_error_log( 'HTTP Request Error!' );
|
||||
}
|
||||
} else {
|
||||
Astra_Sites_File_System::get_instance()->update_json_file( 'astra-sites-categories.json', $categories );
|
||||
do_action( 'astra_sites_sync_categories', $categories );
|
||||
}
|
||||
}
|
||||
|
||||
astra_sites_error_log( 'Site Categories Imported Successfully!' );
|
||||
update_site_option( 'astra-sites-batch-status-string', 'Site Categories Imported Successfully!' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Import Block Categories
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function import_block_categories() {
|
||||
astra_sites_error_log( 'Requesting Block Categories' );
|
||||
update_site_option( 'astra-sites-batch-status-string', 'Requesting Block Categories' );
|
||||
|
||||
$api_args = array(
|
||||
'timeout' => 30,
|
||||
);
|
||||
$tags_request = wp_safe_remote_get( trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/wp/v2/blocks-category/?_fields=id,name,slug&per_page=100&hide_empty=1', $api_args );
|
||||
if ( ! is_wp_error( $tags_request ) && 200 === (int) wp_remote_retrieve_response_code( $tags_request ) ) {
|
||||
$tags = json_decode( wp_remote_retrieve_body( $tags_request ), true );
|
||||
|
||||
if ( isset( $tags['code'] ) ) {
|
||||
$message = isset( $tags['message'] ) ? $tags['message'] : '';
|
||||
if ( ! empty( $message ) ) {
|
||||
astra_sites_error_log( 'HTTP Request Error: ' . $message );
|
||||
} else {
|
||||
astra_sites_error_log( 'HTTP Request Error!' );
|
||||
}
|
||||
} else {
|
||||
$categories = array();
|
||||
foreach ( $tags as $key => $value ) {
|
||||
$categories[ $value['id'] ] = $value;
|
||||
}
|
||||
|
||||
Astra_Sites_File_System::get_instance()->update_json_file( 'astra-blocks-categories.json', $categories );
|
||||
do_action( 'astra_sites_sync_blocks_categories', $categories );
|
||||
}
|
||||
}
|
||||
|
||||
astra_sites_error_log( 'Block Categories Imported Successfully!' );
|
||||
update_site_option( 'astra-sites-batch-status-string', 'Categories Imported Successfully!' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Import Page Builders
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function set_license_page_builder() {
|
||||
|
||||
astra_sites_error_log( 'Requesting License Page Builders' );
|
||||
|
||||
$url = add_query_arg(
|
||||
array(
|
||||
'_fields' => 'id,name,slug',
|
||||
'site_url' => get_site_url(),
|
||||
'purchase_key' => Astra_Sites::get_instance()->get_license_key(),
|
||||
'only_allow_page_builders' => 'true',
|
||||
),
|
||||
trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/wp/v2/astra-site-page-builder/'
|
||||
);
|
||||
|
||||
$api_args = array(
|
||||
'timeout' => 30,
|
||||
);
|
||||
|
||||
$page_builder_request = wp_safe_remote_get( $url, $api_args );
|
||||
if ( ! is_wp_error( $page_builder_request ) && 200 === (int) wp_remote_retrieve_response_code( $page_builder_request ) ) {
|
||||
$page_builders = json_decode( wp_remote_retrieve_body( $page_builder_request ), true );
|
||||
if ( isset( $page_builders['code'] ) ) {
|
||||
$message = isset( $page_builders['message'] ) ? $page_builders['message'] : '';
|
||||
if ( ! empty( $message ) ) {
|
||||
astra_sites_error_log( 'HTTP Request Error: ' . $message );
|
||||
} else {
|
||||
astra_sites_error_log( 'HTTP Request Error!' );
|
||||
}
|
||||
} else {
|
||||
// Set mini agency page builder.
|
||||
$page_builder_slugs = wp_list_pluck( $page_builders, 'slug' );
|
||||
if ( in_array( 'elementor', $page_builder_slugs ) && ! in_array( 'beaver-builder', $page_builder_slugs ) ) {
|
||||
update_option( 'astra-sites-license-page-builder', 'elementor', 'no' );
|
||||
astra_sites_error_log( 'Set "Elementor" as License Page Builder' );
|
||||
} elseif ( in_array( 'beaver-builder', $page_builder_slugs ) && ! in_array( 'elementor', $page_builder_slugs ) ) {
|
||||
update_option( 'astra-sites-license-page-builder', 'beaver-builder', 'no' );
|
||||
astra_sites_error_log( 'Set "Beaver Builder" as License Page Builder' );
|
||||
} else {
|
||||
update_option( 'astra-sites-license-page-builder', '', 'no' );
|
||||
astra_sites_error_log( 'Not Set Any License Page Builder' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Import Page Builders
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @return void
|
||||
*/
|
||||
public function import_page_builders() {
|
||||
astra_sites_error_log( 'Requesting Page Builders' );
|
||||
update_site_option( 'astra-sites-batch-status-string', 'Requesting Page Builders' );
|
||||
|
||||
$purchase_key = Astra_Sites::get_instance()->get_license_key();
|
||||
$site_url = get_site_url();
|
||||
|
||||
$api_args = array(
|
||||
'timeout' => 30,
|
||||
);
|
||||
|
||||
$page_builder_request = wp_safe_remote_get( trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/wp/v2/astra-site-page-builder/?_fields=id,name,slug&site_url=' . $site_url . '&purchase_key=' . $purchase_key, $api_args );
|
||||
if ( ! is_wp_error( $page_builder_request ) && 200 === (int) wp_remote_retrieve_response_code( $page_builder_request ) ) {
|
||||
$page_builders = json_decode( wp_remote_retrieve_body( $page_builder_request ), true );
|
||||
|
||||
if ( isset( $page_builders['code'] ) ) {
|
||||
$message = isset( $page_builders['message'] ) ? $page_builders['message'] : '';
|
||||
if ( ! empty( $message ) ) {
|
||||
astra_sites_error_log( 'HTTP Request Error: ' . $message );
|
||||
} else {
|
||||
astra_sites_error_log( 'HTTP Request Error!' );
|
||||
}
|
||||
} else {
|
||||
Astra_Sites_File_System::get_instance()->update_json_file( 'astra-sites-page-builders.json', $page_builders );
|
||||
do_action( 'astra_sites_sync_page_builders', $page_builders );
|
||||
}
|
||||
}
|
||||
|
||||
astra_sites_error_log( 'Page Builders Imported Successfully!' );
|
||||
update_site_option( 'astra-sites-batch-status-string', 'Page Builders Imported Successfully!' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Import Blocks
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @param integer $page Page number.
|
||||
* @return void
|
||||
*/
|
||||
public function import_blocks( $page = 1 ) {
|
||||
|
||||
astra_sites_error_log( 'BLOCK: -------- ACTUAL IMPORT --------' );
|
||||
$api_args = array(
|
||||
'timeout' => 30,
|
||||
);
|
||||
$all_blocks = array();
|
||||
astra_sites_error_log( 'BLOCK: Requesting ' . $page );
|
||||
update_site_option( 'astra-blocks-batch-status-string', 'Requesting for blocks page - ' . $page );
|
||||
|
||||
$query_args = apply_filters(
|
||||
'astra_sites_blocks_query_args',
|
||||
array(
|
||||
'page_builder' => 'elementor',
|
||||
'per_page' => 100,
|
||||
'page' => $page,
|
||||
'wireframe' => 'yes',
|
||||
)
|
||||
);
|
||||
|
||||
$api_url = add_query_arg( $query_args, trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/astra-blocks/v1/blocks/' );
|
||||
|
||||
$response = wp_safe_remote_get( $api_url, $api_args );
|
||||
|
||||
if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) {
|
||||
$astra_blocks = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||
|
||||
if ( isset( $astra_blocks['code'] ) ) {
|
||||
$message = isset( $astra_blocks['message'] ) ? $astra_blocks['message'] : '';
|
||||
if ( ! empty( $message ) ) {
|
||||
astra_sites_error_log( 'HTTP Request Error: ' . $message );
|
||||
} else {
|
||||
astra_sites_error_log( 'HTTP Request Error!' );
|
||||
}
|
||||
} else {
|
||||
astra_sites_error_log( 'BLOCK: Storing data for page ' . $page . ' in option astra-blocks-' . $page );
|
||||
update_site_option( 'astra-blocks-batch-status-string', 'Storing data for page ' . $page . ' in option astra-blocks-' . $page );
|
||||
Astra_Sites_File_System::get_instance()->update_json_file( 'astra-blocks-' . $page . '.json', $astra_blocks );
|
||||
|
||||
do_action( 'astra_sites_sync_blocks', $page, $astra_blocks );
|
||||
}
|
||||
} else {
|
||||
astra_sites_error_log( 'BLOCK: API Error: ' . $response->get_error_message() );
|
||||
}
|
||||
|
||||
astra_sites_error_log( 'BLOCK: Complete storing data for blocks ' . $page );
|
||||
update_site_option( 'astra-blocks-batch-status-string', 'Complete storing data for page ' . $page );
|
||||
}
|
||||
|
||||
/**
|
||||
* Import
|
||||
*
|
||||
* @since 1.0.14
|
||||
* @since 2.0.0 Added page no.
|
||||
*
|
||||
* @param integer $page Page number.
|
||||
* @return array
|
||||
*/
|
||||
public function import_sites( $page = 1 ) {
|
||||
$api_args = array(
|
||||
'timeout' => 30,
|
||||
);
|
||||
$sites_and_pages = array();
|
||||
astra_sites_error_log( 'Requesting ' . $page );
|
||||
update_site_option( 'astra-sites-batch-status-string', 'Requesting ' . $page );
|
||||
|
||||
$query_args = apply_filters(
|
||||
'astra_sites_import_sites_query_args',
|
||||
array(
|
||||
'per_page' => 15,
|
||||
'page' => $page,
|
||||
)
|
||||
);
|
||||
|
||||
$api_url = add_query_arg( $query_args, trailingslashit( Astra_Sites::get_instance()->get_api_domain() ) . 'wp-json/astra-sites/v1/sites-and-pages/' );
|
||||
|
||||
$response = wp_safe_remote_get( $api_url, $api_args );
|
||||
if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) {
|
||||
$sites_and_pages = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||
|
||||
if ( isset( $sites_and_pages['code'] ) ) {
|
||||
$message = isset( $sites_and_pages['message'] ) ? $sites_and_pages['message'] : '';
|
||||
if ( ! empty( $message ) ) {
|
||||
astra_sites_error_log( 'HTTP Request Error: ' . $message );
|
||||
} else {
|
||||
astra_sites_error_log( 'HTTP Request Error!' );
|
||||
}
|
||||
} else {
|
||||
astra_sites_error_log( 'Storing data for page ' . $page . ' in option astra-sites-and-pages-page-' . $page );
|
||||
update_site_option( 'astra-sites-batch-status-string', 'Storing data for page ' . $page . ' in option astra-sites-and-pages-page-' . $page );
|
||||
|
||||
Astra_Sites_File_System::get_instance()->update_json_file( 'astra-sites-and-pages-page-' . $page . '.json', $sites_and_pages );
|
||||
|
||||
do_action( 'astra_sites_sync_sites_and_pages', $page, $sites_and_pages );
|
||||
}
|
||||
} else {
|
||||
astra_sites_error_log( 'API Error: ' . $response->get_error_message() );
|
||||
}
|
||||
|
||||
astra_sites_error_log( 'Complete storing data for page ' . $page );
|
||||
update_site_option( 'astra-sites-batch-status-string', 'Complete storing data for page ' . $page );
|
||||
|
||||
return $sites_and_pages;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicking this off by calling 'get_instance()' method
|
||||
*/
|
||||
Astra_Sites_Batch_Processing_Importer::get_instance();
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/**
|
||||
* Batch Processing
|
||||
*
|
||||
* @package Astra Sites
|
||||
* @since 1.0.14
|
||||
*/
|
||||
|
||||
use STImporter\Importer\Helpers\ST_Image_Importer;
|
||||
|
||||
if ( ! class_exists( 'Astra_Sites_Batch_Processing_Widgets' ) ) :
|
||||
|
||||
/**
|
||||
* Astra_Sites_Batch_Processing_Widgets
|
||||
*
|
||||
* @since 1.0.14
|
||||
*/
|
||||
class Astra_Sites_Batch_Processing_Widgets {
|
||||
|
||||
/**
|
||||
* WP Forms.
|
||||
*
|
||||
* @since 2.6.22
|
||||
* @var object Class object.
|
||||
*/
|
||||
public $wpforms_ids_mapping;
|
||||
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @since 1.0.14
|
||||
* @access private
|
||||
* @var object Class object.
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Initiator
|
||||
*
|
||||
* @since 1.0.14
|
||||
* @return object initialized object of class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 1.0.14
|
||||
*/
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Import
|
||||
*
|
||||
* @since 1.0.14
|
||||
* @return void
|
||||
*/
|
||||
public function import() {
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
WP_CLI::line( 'Importing Widgets Data' );
|
||||
}
|
||||
|
||||
// Catch mapping data.
|
||||
$this->wpforms_ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
|
||||
|
||||
// Process image widget data.
|
||||
$this->widget_media_image();
|
||||
|
||||
// Process text widget data.
|
||||
$this->widget_text();
|
||||
|
||||
// Process WP Forms widget data.
|
||||
$this->widget_wpform();
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget WP Forms
|
||||
*
|
||||
* @since 3.1.3
|
||||
* @return void
|
||||
*/
|
||||
public function widget_wpform() {
|
||||
|
||||
$data = get_option( 'widget_wpforms-widget', null );
|
||||
|
||||
if ( empty( $data ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Astra_Sites_Importer_Log::add( '---- Processing Contact Form Mapping from WP Forms Widgets -----' );
|
||||
|
||||
foreach ( $data as $key => $value ) {
|
||||
|
||||
if ( isset( $value['form_id'] ) && ! empty( $value['form_id'] ) ) {
|
||||
|
||||
$content = $value['form_id'];
|
||||
|
||||
// Empty mapping? Then return.
|
||||
if ( ! empty( $this->wpforms_ids_mapping ) ) {
|
||||
// Replace ID's.
|
||||
foreach ( $this->wpforms_ids_mapping as $old_id => $new_id ) {
|
||||
if ( $old_id === $content ) {
|
||||
$content = $new_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data[ $key ]['form_id'] = $content;
|
||||
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
WP_CLI::line( 'Updating Contact Form Mapping from WP Forms Widgets' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_option( 'widget_wpforms-widget', $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget Text
|
||||
*
|
||||
* @since 2.6.22
|
||||
* @return void
|
||||
*/
|
||||
public function widget_text() {
|
||||
|
||||
$data = get_option( 'widget_text', null );
|
||||
|
||||
if ( empty( $data ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Astra_Sites_Importer_Log::add( '---- Processing Contact Form Mapping from Text Widgets -----' );
|
||||
|
||||
foreach ( $data as $key => $value ) {
|
||||
|
||||
if ( isset( $value['text'] ) && ! empty( $value['text'] ) ) {
|
||||
|
||||
$content = $value['text'];
|
||||
|
||||
// Empty mapping? Then return.
|
||||
if ( ! empty( $this->wpforms_ids_mapping ) ) {
|
||||
// Replace ID's.
|
||||
foreach ( $this->wpforms_ids_mapping as $old_id => $new_id ) {
|
||||
$content = str_replace( '[wpforms id="' . $old_id, '[wpforms id="' . $new_id, $content );
|
||||
$content = str_replace( '{"formId":"' . $old_id . '"}', '{"formId":"' . $new_id . '"}', $content );
|
||||
}
|
||||
}
|
||||
|
||||
$data[ $key ]['text'] = $content;
|
||||
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
WP_CLI::line( 'Updating Contact Form Mapping from Text Widgets' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_option( 'widget_text', $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget Media Image
|
||||
*
|
||||
* @since 1.0.14
|
||||
* @return void
|
||||
*/
|
||||
public function widget_media_image() {
|
||||
|
||||
$data = get_option( 'widget_media_image', null );
|
||||
|
||||
if ( empty( $data ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Astra_Sites_Importer_Log::add( '---- Processing Images from Widgets -----' );
|
||||
|
||||
foreach ( $data as $key => $value ) {
|
||||
|
||||
if (
|
||||
isset( $value['url'] ) &&
|
||||
isset( $value['attachment_id'] )
|
||||
) {
|
||||
|
||||
$image = array(
|
||||
'url' => $value['url'],
|
||||
'id' => $value['attachment_id'],
|
||||
);
|
||||
|
||||
$downloaded_image = ST_Image_Importer::get_instance()->import( $image );
|
||||
|
||||
$data[ $key ]['url'] = $downloaded_image['url'];
|
||||
$data[ $key ]['attachment_id'] = $downloaded_image['id'];
|
||||
|
||||
if ( defined( 'WP_CLI' ) ) {
|
||||
WP_CLI::line( 'Importing Widgets Image: ' . $value['url'] . ' | New Image ' . $downloaded_image['url'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_option( 'widget_media_image', $data );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicking this off by calling 'get_instance()' method
|
||||
*/
|
||||
Astra_Sites_Batch_Processing_Widgets::get_instance();
|
||||
|
||||
endif;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* Customizer Data importer class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package Astra Addon
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Customizer Data importer class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Astra_Customizer_Import {
|
||||
|
||||
/**
|
||||
* Instance of Astra_Customizer_Import
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var Astra_Customizer_Import
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Instantiate Astra_Customizer_Import
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return (Object) Astra_Customizer_Import
|
||||
*/
|
||||
public static function instance() {
|
||||
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Import customizer options.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param (Array) $options customizer options from the demo.
|
||||
*/
|
||||
public function import( $options ) {
|
||||
|
||||
// Update Astra Theme customizer settings.
|
||||
if ( isset( $options['astra-settings'] ) ) {
|
||||
update_option( 'astra-settings', $options['astra-settings'] );
|
||||
}
|
||||
|
||||
// Add Custom CSS.
|
||||
if ( isset( $options['custom-css'] ) ) {
|
||||
wp_update_custom_css_post( $options['custom-css'] );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
<?php
|
||||
/**
|
||||
* Customizer Site options importer class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package Astra Addon
|
||||
*/
|
||||
|
||||
use STImporter\Importer\ST_Importer_Helper;
|
||||
use STImporter\Importer\Helpers\ST_Image_Importer;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customizer Site options importer class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Astra_Site_Options_Import {
|
||||
|
||||
/**
|
||||
* Instance of Astra_Site_Options_Importer
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @var (Object) Astra_Site_Options_Importer
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Instanciate Astra_Site_Options_Importer
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return (Object) Astra_Site_Options_Importer
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_filter( 'st_importer_site_options', array( $this, 'classic_templates_options' ), 10, 1 );
|
||||
add_action( 'st_importer_import_site_options', array( $this, 'import_classic_templates_options' ), 10, 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Classic templates options.
|
||||
*
|
||||
* @since 4.3.0
|
||||
* @param array<int, string> $default_options List of defined array.
|
||||
* @return array<int, string> List of defined array.
|
||||
*/
|
||||
public function classic_templates_options( $default_options ) {
|
||||
|
||||
$classic_templates_options = array(
|
||||
'custom_logo',
|
||||
'nav_menu_locations',
|
||||
'show_on_front',
|
||||
'page_on_front',
|
||||
'page_for_posts',
|
||||
'site_title',
|
||||
|
||||
// Plugin: Elementor.
|
||||
'elementor_container_width',
|
||||
'elementor_cpt_support',
|
||||
'elementor_css_print_method',
|
||||
'elementor_default_generic_fonts',
|
||||
'elementor_disable_color_schemes',
|
||||
'elementor_disable_typography_schemes',
|
||||
'elementor_editor_break_lines',
|
||||
'elementor_exclude_user_roles',
|
||||
'elementor_global_image_lightbox',
|
||||
'elementor_page_title_selector',
|
||||
'elementor_scheme_color',
|
||||
'elementor_scheme_color-picker',
|
||||
'elementor_scheme_typography',
|
||||
'elementor_space_between_widgets',
|
||||
'elementor_stretched_section_container',
|
||||
'elementor_load_fa4_shim',
|
||||
'elementor_active_kit',
|
||||
'elementor_experiment-container',
|
||||
|
||||
// Plugin: Beaver Builder.
|
||||
'_fl_builder_enabled_icons',
|
||||
'_fl_builder_enabled_modules',
|
||||
'_fl_builder_post_types',
|
||||
'_fl_builder_color_presets',
|
||||
'_fl_builder_services',
|
||||
'_fl_builder_settings',
|
||||
'_fl_builder_user_access',
|
||||
'_fl_builder_enabled_templates',
|
||||
|
||||
// Plugin: WooCommerce.
|
||||
// Pages.
|
||||
'woocommerce_shop_page_title',
|
||||
'woocommerce_cart_page_title',
|
||||
'woocommerce_checkout_page_title',
|
||||
'woocommerce_myaccount_page_title',
|
||||
'woocommerce_edit_address_page_title',
|
||||
'woocommerce_view_order_page_title',
|
||||
'woocommerce_change_password_page_title',
|
||||
'woocommerce_logout_page_title',
|
||||
|
||||
// Account & Privacy.
|
||||
'woocommerce_enable_guest_checkout',
|
||||
'woocommerce_enable_checkout_login_reminder',
|
||||
'woocommerce_enable_signup_and_login_from_checkout',
|
||||
'woocommerce_enable_myaccount_registration',
|
||||
'woocommerce_registration_generate_username',
|
||||
|
||||
// Plugin: Easy Digital Downloads - EDD.
|
||||
'edd_settings',
|
||||
|
||||
// Plugin: WPForms.
|
||||
'wpforms_settings',
|
||||
|
||||
// Categories.
|
||||
'woocommerce_product_cat',
|
||||
|
||||
// Plugin: LearnDash LMS.
|
||||
'learndash_settings_theme_ld30',
|
||||
'learndash_settings_courses_themes',
|
||||
|
||||
// Astra Theme Global Color Palette and Typography Preset options.
|
||||
'astra-color-palettes',
|
||||
'astra-typography-presets',
|
||||
);
|
||||
$options = array_merge( $default_options, $classic_templates_options );
|
||||
return $options;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Import Classic Templates Options.
|
||||
*
|
||||
* @since 4.3.0
|
||||
*
|
||||
* @param array<string, mixed> $options List of default options.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function import_classic_templates_options( $options ) {
|
||||
|
||||
if ( ! isset( $options ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
foreach ( $options as $option_name => $option_value ) {
|
||||
|
||||
// Is option exist in defined array site_options()?
|
||||
if ( null !== $option_value ) {
|
||||
|
||||
switch ( $option_name ) {
|
||||
|
||||
// Set WooCommerce page ID by page Title.
|
||||
case 'woocommerce_shop_page_title':
|
||||
case 'woocommerce_cart_page_title':
|
||||
case 'woocommerce_checkout_page_title':
|
||||
case 'woocommerce_myaccount_page_title':
|
||||
case 'woocommerce_edit_address_page_title':
|
||||
case 'woocommerce_view_order_page_title':
|
||||
case 'woocommerce_change_password_page_title':
|
||||
case 'woocommerce_logout_page_title':
|
||||
$this->update_woocommerce_page_id_by_option_value( $option_name, $option_value );
|
||||
break;
|
||||
|
||||
case 'page_for_posts':
|
||||
case 'page_on_front':
|
||||
$this->update_page_id_by_option_value( $option_name, $option_value );
|
||||
break;
|
||||
|
||||
// nav menu locations.
|
||||
case 'nav_menu_locations':
|
||||
$this->set_nav_menu_locations( $option_value );
|
||||
break;
|
||||
|
||||
// import WooCommerce category images.
|
||||
case 'woocommerce_product_cat':
|
||||
$this->set_woocommerce_product_cat( $option_value );
|
||||
break;
|
||||
|
||||
// insert logo.
|
||||
case 'custom_logo':
|
||||
$this->insert_logo( $option_value );
|
||||
break;
|
||||
|
||||
case 'elementor_active_kit':
|
||||
if ( '' !== $option_value ) {
|
||||
$this->set_elementor_kit();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'site_title':
|
||||
update_option( 'blogname', $option_value );
|
||||
break;
|
||||
|
||||
default:
|
||||
update_option( $option_name, $option_value );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch ( Exception $e ) {
|
||||
// Do nothing.
|
||||
astra_sites_error_log( 'Error while importing site options: ' . $e->getMessage() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Update post option
|
||||
*
|
||||
* @since 2.2.2
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function set_elementor_kit() {
|
||||
|
||||
// Update Elementor Theme Kit Option.
|
||||
$args = array(
|
||||
'post_type' => 'elementor_library',
|
||||
'post_status' => 'publish',
|
||||
'numberposts' => 1,
|
||||
'meta_query' => array( //phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query -- Setting elementor kit. WP Query would have been expensive.
|
||||
array(
|
||||
'key' => '_astra_sites_imported_post',
|
||||
'value' => '1',
|
||||
),
|
||||
array(
|
||||
'key' => '_elementor_template_type',
|
||||
'value' => 'kit',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$query = get_posts( $args );
|
||||
if ( ! empty( $query ) && isset( $query[0] ) && isset( $query[0]->ID ) ) {
|
||||
update_option( 'elementor_active_kit', $query[0]->ID );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get post from post title and post type.
|
||||
*
|
||||
* @since 4.0.6
|
||||
*
|
||||
* @param mixed $post_title post title.
|
||||
* @param string $post_type post type.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_page_by_title( $post_title, $post_type ) {
|
||||
$page = array();
|
||||
$query = new WP_Query(
|
||||
array(
|
||||
'post_type' => $post_type,
|
||||
'title' => $post_title,
|
||||
'posts_per_page' => 1,
|
||||
'no_found_rows' => true,
|
||||
'ignore_sticky_posts' => true,
|
||||
'update_post_term_cache' => false,
|
||||
'update_post_meta_cache' => false,
|
||||
'orderby' => 'ID',
|
||||
'order' => 'DESC',
|
||||
)
|
||||
);
|
||||
if ( $query->have_posts() ) {
|
||||
$page = $query->posts[0];
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update post option
|
||||
*
|
||||
* @since 1.0.2
|
||||
*
|
||||
* @param string $option_name Option name.
|
||||
* @param mixed $option_value Option value.
|
||||
* @return void
|
||||
*/
|
||||
private function update_page_id_by_option_value( $option_name, $option_value ) {
|
||||
if ( empty( $option_value ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$page = $this->get_page_by_title( $option_value, 'page' );
|
||||
|
||||
if ( is_object( $page ) ) {
|
||||
update_option( $option_name, $page->ID );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update WooCommerce page ids.
|
||||
*
|
||||
* @since 1.1.6
|
||||
*
|
||||
* @param string $option_name Option name.
|
||||
* @param mixed $option_value Option value.
|
||||
* @return void
|
||||
*/
|
||||
private function update_woocommerce_page_id_by_option_value( $option_name, $option_value ) {
|
||||
$option_name = str_replace( '_title', '_id', $option_name );
|
||||
$this->update_page_id_by_option_value( $option_name, $option_value );
|
||||
}
|
||||
|
||||
/**
|
||||
* In WP nav menu is stored as ( 'menu_location' => 'menu_id' );
|
||||
* In export we send 'menu_slug' like ( 'menu_location' => 'menu_slug' );
|
||||
* In import we set 'menu_id' from menu slug like ( 'menu_location' => 'menu_id' );
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param array $nav_menu_locations Array of nav menu locations.
|
||||
*/
|
||||
private function set_nav_menu_locations( $nav_menu_locations = array() ) {
|
||||
|
||||
$menu_locations = array();
|
||||
|
||||
// Update menu locations.
|
||||
if ( isset( $nav_menu_locations ) ) {
|
||||
|
||||
foreach ( $nav_menu_locations as $menu => $value ) {
|
||||
|
||||
$term = get_term_by( 'slug', $value, 'nav_menu' );
|
||||
|
||||
if ( is_object( $term ) ) {
|
||||
$menu_locations[ $menu ] = $term->term_id;
|
||||
}
|
||||
}
|
||||
|
||||
set_theme_mod( 'nav_menu_locations', $menu_locations );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set WooCommerce category images.
|
||||
*
|
||||
* @since 1.1.4
|
||||
*
|
||||
* @param array $cats Array of categories.
|
||||
*/
|
||||
private function set_woocommerce_product_cat( $cats = array() ) {
|
||||
|
||||
if ( isset( $cats ) ) {
|
||||
|
||||
foreach ( $cats as $key => $cat ) {
|
||||
|
||||
if ( ! empty( $cat['slug'] ) && ! empty( $cat['thumbnail_src'] ) ) {
|
||||
|
||||
$downloaded_image = ST_Image_Importer::get_instance()->import(
|
||||
array(
|
||||
'url' => $cat['thumbnail_src'],
|
||||
'id' => 0,
|
||||
)
|
||||
);
|
||||
|
||||
if ( $downloaded_image['id'] ) {
|
||||
|
||||
$term = get_term_by( 'slug', $cat['slug'], 'product_cat' );
|
||||
|
||||
if ( is_object( $term ) ) {
|
||||
update_term_meta( $term->term_id, 'thumbnail_id', $downloaded_image['id'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert Logo By URL
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param string $image_url Logo URL.
|
||||
* @return void
|
||||
*/
|
||||
private function insert_logo( $image_url = '' ) {
|
||||
|
||||
$downloaded_image = ST_Image_Importer::get_instance()->import(
|
||||
array(
|
||||
'url' => $image_url,
|
||||
'id' => 0,
|
||||
)
|
||||
);
|
||||
|
||||
if ( $downloaded_image['id'] ) {
|
||||
ST_Importer_Helper::track_post( $downloaded_image['id'] );
|
||||
set_theme_mod( 'custom_logo', $downloaded_image['id'] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicking this off by calling 'get_instance()' method
|
||||
*/
|
||||
Astra_Site_Options_Import::instance();
|
||||
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
/**
|
||||
* Astra Site Helper
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @package Astra Sites
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'Astra_Sites_Helper' ) ) :
|
||||
|
||||
/**
|
||||
* Astra_Sites_Helper
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Astra_Sites_Helper {
|
||||
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @access private
|
||||
* @var object Instance
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static $instance;
|
||||
|
||||
/**
|
||||
* Initiator
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return object initialized object of class.
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
add_filter( 'wie_import_data', array( $this, 'custom_menu_widget' ) );
|
||||
add_filter( 'wp_prepare_attachment_for_js', array( $this, 'add_svg_image_support' ), 10, 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add svg image support
|
||||
*
|
||||
* @since 1.1.5
|
||||
*
|
||||
* @param array $response Attachment response.
|
||||
* @param object $attachment Attachment object.
|
||||
* @param array $meta Attachment meta data.
|
||||
*/
|
||||
public function add_svg_image_support( $response, $attachment, $meta ) {
|
||||
if ( ! function_exists( 'simplexml_load_file' ) ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ( ! empty( $response['sizes'] ) ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
if ( 'image/svg+xml' !== $response['mime'] ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$svg_path = get_attached_file( $attachment->ID );
|
||||
|
||||
$dimensions = self::get_svg_dimensions( $svg_path );
|
||||
|
||||
$response['sizes'] = array(
|
||||
'full' => array(
|
||||
'url' => $response['url'],
|
||||
'width' => $dimensions->width,
|
||||
'height' => $dimensions->height,
|
||||
'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait',
|
||||
),
|
||||
);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SVG Dimensions
|
||||
*
|
||||
* @since 1.1.5
|
||||
*
|
||||
* @param string $svg SVG file path.
|
||||
* @return array Return SVG file height & width for valid SVG file.
|
||||
*/
|
||||
public static function get_svg_dimensions( $svg ) {
|
||||
|
||||
$svg = simplexml_load_file( $svg );
|
||||
|
||||
if ( false === $svg ) {
|
||||
$width = '0';
|
||||
$height = '0';
|
||||
} else {
|
||||
$attributes = $svg->attributes();
|
||||
$width = (string) $attributes->width;
|
||||
$height = (string) $attributes->height;
|
||||
}
|
||||
|
||||
return (object) array(
|
||||
'width' => $width,
|
||||
'height' => $height,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom Menu Widget
|
||||
*
|
||||
* In widget export we set the nav menu slug instead of ID.
|
||||
* So, In import process we check get menu id by slug and set
|
||||
* it in import widget process.
|
||||
*
|
||||
* @since 1.0.7
|
||||
*
|
||||
* @param object $all_sidebars Widget data.
|
||||
* @return object Set custom menu id by slug.
|
||||
*/
|
||||
public function custom_menu_widget( $all_sidebars ) {
|
||||
|
||||
// Get current menu ID & Slugs.
|
||||
$menu_locations = array();
|
||||
$nav_menus = (object) wp_get_nav_menus();
|
||||
if ( isset( $nav_menus ) ) {
|
||||
foreach ( $nav_menus as $menu_key => $menu ) {
|
||||
if ( is_object( $menu ) ) {
|
||||
$menu_locations[ $menu->term_id ] = $menu->slug;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Import widget data.
|
||||
$all_sidebars = (object) $all_sidebars;
|
||||
foreach ( $all_sidebars as $widgets_key => $widgets ) {
|
||||
foreach ( $widgets as $widget_key => $widget ) {
|
||||
|
||||
// Found slug in current menu list.
|
||||
if ( isset( $widget->nav_menu ) ) {
|
||||
$menu_id = array_search( $widget->nav_menu, $menu_locations, true );
|
||||
if ( ! empty( $menu_id ) ) {
|
||||
$all_sidebars->$widgets_key->$widget_key->nav_menu = $menu_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $all_sidebars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads an image from the specified URL.
|
||||
*
|
||||
* Taken from the core media_sideload_image() function and
|
||||
* modified to return an array of data instead of html.
|
||||
*
|
||||
* @since 1.0.10
|
||||
*
|
||||
* @param string $file The image file path.
|
||||
* @return array An array of image data.
|
||||
*/
|
||||
public static function sideload_image( $file ) {
|
||||
$data = new stdClass();
|
||||
|
||||
if ( ! function_exists( 'media_handle_sideload' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/media.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/image.php';
|
||||
}
|
||||
|
||||
if ( ! empty( $file ) ) {
|
||||
|
||||
// Set variables for storage, fix file filename for query strings.
|
||||
preg_match( '/[^\?]+\.(jpe?g|jpe|svg|gif|png)\b/i', $file, $matches );
|
||||
$file_array = array();
|
||||
$file_array['name'] = basename( $matches[0] );
|
||||
|
||||
// Download file to temp location.
|
||||
$file_array['tmp_name'] = download_url( $file );
|
||||
|
||||
// If error storing temporarily, return the error.
|
||||
if ( is_wp_error( $file_array['tmp_name'] ) ) {
|
||||
return $file_array['tmp_name'];
|
||||
}
|
||||
|
||||
// Do the validation and storage stuff.
|
||||
$id = media_handle_sideload( $file_array, 0 );
|
||||
|
||||
// If error storing permanently, unlink.
|
||||
if ( is_wp_error( $id ) ) {
|
||||
unlink( $file_array['tmp_name'] ); //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink -- Deleting the file from temp location.
|
||||
return $id;
|
||||
}
|
||||
|
||||
// Build the object to return.
|
||||
$meta = wp_get_attachment_metadata( $id );
|
||||
$data->attachment_id = $id;
|
||||
$data->url = wp_get_attachment_url( $id );
|
||||
$data->thumbnail_url = wp_get_attachment_thumb_url( $id );
|
||||
$data->height = isset( $meta['height'] ) ? $meta['height'] : '';
|
||||
$data->width = isset( $meta['width'] ) ? $meta['width'] : '';
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract image URLs and other URLs from a given HTML content.
|
||||
*
|
||||
* @since 2.6.10
|
||||
*
|
||||
* @param string $content HTML content string.
|
||||
* @return array Array of URLS.
|
||||
*/
|
||||
public static function extract_segregated_urls( $content ) {
|
||||
// Extract all links.
|
||||
preg_match_all( '#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $content, $match );
|
||||
|
||||
$extracts = array(
|
||||
'image' => array(),
|
||||
'other' => array(),
|
||||
);
|
||||
|
||||
$all_links = array_unique( $match[0] );
|
||||
|
||||
// Not have any link.
|
||||
if ( empty( $all_links ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$image_links = array();
|
||||
$other_links = array();
|
||||
|
||||
// Extract normal and image links.
|
||||
foreach ( $all_links as $key => $link ) {
|
||||
if ( preg_match( '/^((https?:\/\/)|(www\.))([a-z0-9-].?)+(:[0-9]+)?\/[\w\-]+\.(jpg|png|gif|jpeg)\/?$/i', $link ) ) {
|
||||
|
||||
// Get all image links.
|
||||
// Avoid *-150x, *-300x and *-1024x images.
|
||||
if (
|
||||
false === strpos( $link, '-150x' ) &&
|
||||
false === strpos( $link, '-300x' ) &&
|
||||
false === strpos( $link, '-1024x' )
|
||||
) {
|
||||
$image_links[] = $link;
|
||||
}
|
||||
} else {
|
||||
|
||||
// Collect other links.
|
||||
$other_links[] = $link;
|
||||
}
|
||||
}
|
||||
|
||||
$extracts['image'] = $image_links;
|
||||
$extracts['other'] = $other_links;
|
||||
|
||||
return $extracts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the client IP address.
|
||||
*
|
||||
* @since 2.6.4
|
||||
*/
|
||||
public static function get_client_ip() {
|
||||
$ipaddress = '';
|
||||
if ( getenv( 'HTTP_CLIENT_IP' ) ) {
|
||||
$ipaddress = getenv( 'HTTP_CLIENT_IP' );
|
||||
} elseif ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) {
|
||||
$ipaddress = getenv( 'HTTP_X_FORWARDED_FOR' );
|
||||
} elseif ( getenv( 'HTTP_X_FORWARDED' ) ) {
|
||||
$ipaddress = getenv( 'HTTP_X_FORWARDED' );
|
||||
} elseif ( getenv( 'HTTP_FORWARDED_FOR' ) ) {
|
||||
$ipaddress = getenv( 'HTTP_FORWARDED_FOR' );
|
||||
} elseif ( getenv( 'HTTP_FORWARDED' ) ) {
|
||||
$ipaddress = getenv( 'HTTP_FORWARDED' );
|
||||
} elseif ( getenv( 'REMOTE_ADDR' ) ) {
|
||||
$ipaddress = getenv( 'REMOTE_ADDR' );
|
||||
} else {
|
||||
$ipaddress = 'UNKNOWN';
|
||||
}
|
||||
return $ipaddress;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Kicking this off by calling 'get_instance()' method
|
||||
*/
|
||||
Astra_Sites_Helper::get_instance();
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,289 @@
|
||||
<?php
|
||||
/**
|
||||
* Widget Importer Exporter
|
||||
* https://github.com/churchthemes/widget-importer-exporter
|
||||
*
|
||||
* Released under the GNU General Public License v2.0
|
||||
* https://github.com/churchthemes/widget-importer-exporter/blob/master/license.txt
|
||||
*
|
||||
* Widget Data exporter class.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @package Astra Sites
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget Data exporter class.
|
||||
*/
|
||||
class Astra_Widget_Importer {
|
||||
|
||||
/**
|
||||
* Instance of Astra_Widget_Importer
|
||||
*
|
||||
* @var Astra_Widget_Importer
|
||||
*/
|
||||
private static $instance = null;
|
||||
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public static function instance() {
|
||||
|
||||
if ( ! isset( self::$instance ) ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Available widgets
|
||||
*
|
||||
* Gather site's widgets into array with ID base, name, etc.
|
||||
* Used by export and import functions.
|
||||
*
|
||||
* @since 0.4
|
||||
* @global array $wp_registered_widget_updates
|
||||
* @return array Widget information
|
||||
*/
|
||||
public function wie_available_widgets() {
|
||||
|
||||
global $wp_registered_widget_controls;
|
||||
|
||||
$widget_controls = $wp_registered_widget_controls;
|
||||
|
||||
$available_widgets = array();
|
||||
|
||||
foreach ( $widget_controls as $widget ) {
|
||||
|
||||
if ( ! empty( $widget['id_base'] ) && ! isset( $available_widgets[ $widget['id_base'] ] ) ) { // no dupes.
|
||||
|
||||
$available_widgets[ $widget['id_base'] ]['id_base'] = $widget['id_base'];
|
||||
$available_widgets[ $widget['id_base'] ]['name'] = $widget['name'];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return apply_filters( 'wie_available_widgets', $available_widgets );
|
||||
}
|
||||
|
||||
/**
|
||||
* Import widget JSON data
|
||||
*
|
||||
* @since 0.4
|
||||
* @global array $wp_registered_sidebars
|
||||
*
|
||||
* @param object $data JSON widget data from .wie file.
|
||||
*
|
||||
* @return array Results array
|
||||
*/
|
||||
public function import_widgets_data( $data ) {
|
||||
|
||||
global $wp_registered_sidebars;
|
||||
|
||||
// Have valid data?
|
||||
// If no data or could not decode.
|
||||
if ( empty( $data ) || ! is_object( $data ) ) {
|
||||
wp_die(
|
||||
esc_html__( 'Import data could not be read. Please try a different file.', 'astra-sites' ),
|
||||
'',
|
||||
array(
|
||||
'back_link' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Hook before import.
|
||||
do_action( 'wie_before_import' );
|
||||
$data = apply_filters( 'wie_import_data', $data );
|
||||
|
||||
// Get all available widgets site supports.
|
||||
$available_widgets = $this->wie_available_widgets();
|
||||
|
||||
// Get all existing widget instances.
|
||||
$widget_instances = array();
|
||||
foreach ( $available_widgets as $widget_data ) {
|
||||
$widget_instances[ $widget_data['id_base'] ] = get_option( 'widget_' . $widget_data['id_base'] );
|
||||
}
|
||||
|
||||
// Begin results.
|
||||
$results = array();
|
||||
|
||||
// Loop import data's sidebars.
|
||||
foreach ( $data as $sidebar_id => $widgets ) {
|
||||
|
||||
// Skip inactive widgets.
|
||||
// (should not be in export file).
|
||||
if ( 'wp_inactive_widgets' === $sidebar_id ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if sidebar is available on this site.
|
||||
// Otherwise add widgets to inactive, and say so.
|
||||
if ( isset( $wp_registered_sidebars[ $sidebar_id ] ) ) {
|
||||
$sidebar_available = true;
|
||||
$use_sidebar_id = $sidebar_id;
|
||||
$sidebar_message_type = 'success';
|
||||
$sidebar_message = '';
|
||||
} else {
|
||||
$sidebar_available = false;
|
||||
$use_sidebar_id = 'wp_inactive_widgets'; // add to inactive if sidebar does not exist in theme.
|
||||
$sidebar_message_type = 'error';
|
||||
$sidebar_message = esc_html__( 'Widget area does not exist in theme (using Inactive)', 'astra-sites' );
|
||||
}
|
||||
|
||||
// Result for sidebar.
|
||||
$results[ $sidebar_id ]['name'] = ! empty( $wp_registered_sidebars[ $sidebar_id ]['name'] ) ? $wp_registered_sidebars[ $sidebar_id ]['name'] : $sidebar_id; // sidebar name if theme supports it; otherwise ID.
|
||||
$results[ $sidebar_id ]['message_type'] = $sidebar_message_type;
|
||||
$results[ $sidebar_id ]['message'] = $sidebar_message;
|
||||
$results[ $sidebar_id ]['widgets'] = array();
|
||||
|
||||
// Loop widgets.
|
||||
foreach ( $widgets as $widget_instance_id => $widget ) {
|
||||
|
||||
$fail = false;
|
||||
|
||||
// Get id_base (remove -# from end) and instance ID number.
|
||||
$id_base = preg_replace( '/-[0-9]+$/', '', $widget_instance_id );
|
||||
$instance_id_number = str_replace( $id_base . '-', '', $widget_instance_id );
|
||||
|
||||
// Does site support this widget?
|
||||
if ( ! $fail && ! isset( $available_widgets[ $id_base ] ) ) {
|
||||
$fail = true;
|
||||
$widget_message_type = 'error';
|
||||
$widget_message = esc_html__( 'Site does not support widget', 'astra-sites' ); // explain why widget not imported.
|
||||
}
|
||||
|
||||
// Filter to modify settings object before conversion to array and import.
|
||||
// Leave this filter here for backwards compatibility with manipulating objects (before conversion to array below).
|
||||
// Ideally the newer wie_widget_settings_array below will be used instead of this.
|
||||
$widget = apply_filters( 'wie_widget_settings', $widget ); // object.
|
||||
|
||||
// Convert multidimensional objects to multidimensional arrays
|
||||
// Some plugins like Jetpack Widget Visibility store settings as multidimensional arrays
|
||||
// Without this, they are imported as objects and cause fatal error on Widgets page
|
||||
// If this creates problems for plugins that do actually intend settings in objects then may need to consider other approach: https://wordpress.org/support/topic/problem-with-array-of-arrays
|
||||
// It is probably much more likely that arrays are used than objects, however.
|
||||
$widget = json_decode( wp_json_encode( $widget ), true );
|
||||
|
||||
// Filter to modify settings array
|
||||
// This is preferred over the older wie_widget_settings filter above.
|
||||
// Do before identical check because changes may make it identical to end result (such as URL replacements).
|
||||
$widget = apply_filters( 'wie_widget_settings_array', $widget );
|
||||
|
||||
// Does widget with identical settings already exist in same sidebar?
|
||||
if ( ! $fail && isset( $widget_instances[ $id_base ] ) ) {
|
||||
|
||||
// Get existing widgets in this sidebar.
|
||||
$sidebars_widgets = get_option( 'sidebars_widgets' );
|
||||
$sidebar_widgets = isset( $sidebars_widgets[ $use_sidebar_id ] ) ? $sidebars_widgets[ $use_sidebar_id ] : array(); // check Inactive if that's where will go.
|
||||
|
||||
// Loop widgets with ID base.
|
||||
$single_widget_instances = ! empty( $widget_instances[ $id_base ] ) ? $widget_instances[ $id_base ] : array();
|
||||
foreach ( $single_widget_instances as $check_id => $check_widget ) {
|
||||
|
||||
// Is widget in same sidebar and has identical settings?
|
||||
if ( in_array( "$id_base-$check_id", $sidebar_widgets, true ) && (array) $widget === $check_widget ) {
|
||||
|
||||
$fail = true;
|
||||
$widget_message_type = 'warning';
|
||||
$widget_message = esc_html__( 'Widget already exists', 'astra-sites' ); // explain why widget not imported.
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No failure.
|
||||
if ( ! $fail ) {
|
||||
|
||||
// Add widget instance.
|
||||
$single_widget_instances = get_option( 'widget_' . $id_base ); // all instances for that widget ID base, get fresh every time.
|
||||
$single_widget_instances = ! empty( $single_widget_instances ) ? $single_widget_instances : array(
|
||||
'_multiwidget' => 1,
|
||||
); // start fresh if have to.
|
||||
$single_widget_instances[] = $widget; // add it.
|
||||
|
||||
// Get the key it was given.
|
||||
end( $single_widget_instances );
|
||||
$new_instance_id_number = key( $single_widget_instances );
|
||||
|
||||
// If key is 0, make it 1.
|
||||
// When 0, an issue can occur where adding a widget causes data from other widget to load, and the widget doesn't stick (reload wipes it).
|
||||
if ( '0' === strval( $new_instance_id_number ) ) {
|
||||
$new_instance_id_number = 1;
|
||||
$single_widget_instances[ $new_instance_id_number ] = $single_widget_instances[0];
|
||||
unset( $single_widget_instances[0] );
|
||||
}
|
||||
|
||||
// Move _multiwidget to end of array for uniformity.
|
||||
if ( isset( $single_widget_instances['_multiwidget'] ) ) {
|
||||
$multiwidget = $single_widget_instances['_multiwidget'];
|
||||
unset( $single_widget_instances['_multiwidget'] );
|
||||
$single_widget_instances['_multiwidget'] = $multiwidget;
|
||||
}
|
||||
|
||||
// Update option with new widget.
|
||||
$result = update_option( 'widget_' . $id_base, $single_widget_instances );
|
||||
|
||||
// Assign widget instance to sidebar.
|
||||
$sidebars_widgets = get_option( 'sidebars_widgets' ); // which sidebars have which widgets, get fresh every time.
|
||||
|
||||
// Avoid rarely fatal error when the option is an empty string.
|
||||
// https://github.com/churchthemes/widget-importer-exporter/pull/11.
|
||||
if ( ! $sidebars_widgets ) {
|
||||
$sidebars_widgets = array();
|
||||
}
|
||||
|
||||
$new_instance_id = $id_base . '-' . $new_instance_id_number; // use ID number from new widget instance.
|
||||
$sidebars_widgets[ $use_sidebar_id ][] = $new_instance_id; // add new instance to sidebar.
|
||||
update_option( 'sidebars_widgets', $sidebars_widgets ); // save the amended data.
|
||||
|
||||
// After widget import action.
|
||||
$after_widget_import = array(
|
||||
'sidebar' => $use_sidebar_id,
|
||||
'sidebar_old' => $sidebar_id,
|
||||
'widget' => $widget,
|
||||
'widget_type' => $id_base,
|
||||
'widget_id' => $new_instance_id,
|
||||
'widget_id_old' => $widget_instance_id,
|
||||
'widget_id_num' => $new_instance_id_number,
|
||||
'widget_id_num_old' => $instance_id_number,
|
||||
);
|
||||
do_action( 'wie_after_widget_import', $after_widget_import );
|
||||
|
||||
// Success message.
|
||||
if ( $sidebar_available ) {
|
||||
$widget_message_type = 'success';
|
||||
$widget_message = esc_html__( 'Imported', 'astra-sites' );
|
||||
} else {
|
||||
$widget_message_type = 'warning';
|
||||
$widget_message = esc_html__( 'Imported to Inactive', 'astra-sites' );
|
||||
}
|
||||
}
|
||||
|
||||
// Result for widget instance.
|
||||
$results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['name'] = isset( $available_widgets[ $id_base ]['name'] ) ? $available_widgets[ $id_base ]['name'] : $id_base; // widget name or ID if name not available (not supported by site).
|
||||
$results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['title'] = ! empty( $widget['title'] ) ? $widget['title'] : esc_html__( 'No Title', 'astra-sites' ); // show "No Title" if widget instance is untitled.
|
||||
$results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message_type'] = $widget_message_type;
|
||||
$results[ $sidebar_id ]['widgets'][ $widget_instance_id ]['message'] = $widget_message;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Hook after import.
|
||||
do_action( 'wie_after_import' );
|
||||
|
||||
// Return results.
|
||||
return apply_filters( 'wie_import_results', $results );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user