Initial commit: Atomaste website

This commit is contained in:
2025-12-10 12:17:30 -05:00
commit 0b9e5d1605
19260 changed files with 5206382 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
<?php
/**
* Astra_Sites_Elementor_Images class
*
* This class is used to manage Pixabay Images.
*
* @package Astra Sites
* @since 2.0.0
*/
use Elementor\Utils;
// If plugin - 'Elementor' not exist then return.
if ( class_exists( 'Astra_Sites_Elementor_Images' ) ) {
return;
}
/**
* Astra_Sites_Elementor_Images
*/
class Astra_Sites_Elementor_Images {
/**
* Instance of Astra_Sites
*
* @since 2.0.0
* @var (Object) Astra_Sites
*/
private static $instance = null;
/**
* Instance of Astra_Sites_Elementor_Images.
*
* @since 2.0.0
*
* @return object Class object.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Import Image.
*
* @since 2.0.0
* @param array $image Downloaded Image array.
*/
public function get_attachment_data( $image ) {
if ( ! empty( $image ) ) {
return array(
'content' => array(
array(
'id' => \Elementor\Utils::generate_random_string(),
'elType' => 'section',
'settings' => array(),
'isInner' => false,
'elements' => array(
array(
'id' => \Elementor\Utils::generate_random_string(),
'elType' => 'column',
'elements' => array(
array(
'id' => \Elementor\Utils::generate_random_string(),
'elType' => 'widget',
'settings' => array(
'image' => array(
'url' => wp_get_attachment_url( $image ),
'id' => $image,
),
'image_size' => 'full',
),
'widgetType' => 'image',
),
),
'isInner' => false,
),
),
),
),
);
}
return array();
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Astra_Sites_Elementor_Images::get_instance();

View File

@@ -0,0 +1,95 @@
<?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\DB;
use Elementor\Core\Settings\Page\Manager as PageSettingsManager;
use Elementor\Core\Settings\Manager as SettingsManager;
use Elementor\Core\Settings\Page\Model;
use Elementor\Editor;
use Elementor\Plugin;
use Elementor\Settings;
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 2.0.0 Added compatibility for Elemetnor v2.5.0
*/
class Astra_Sites_Elementor_Pages extends Source_Local {
/**
* Update post meta.
*
* @since 2.0.0
* @param integer $post_id Post ID.
* @param array $data Elementor Data.
* @return array $data Elementor Imported Data.
*/
public function import( $post_id = 0, $data = array() ) {
if ( ! empty( $post_id ) && ! empty( $data ) ) {
$data = wp_json_encode( $data );
// Update WP form IDs.
$ids_mapping = get_option( 'astra_sites_wpforms_ids_mapping', array() );
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 = json_decode( $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();
if ( isset( $demo_data['astra-site-url'] ) ) {
$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 );
if ( ! is_array( $data ) ) {
$data = str_replace( $demo_site_url, $site_url, $data );
} else {
$data = wp_json_encode( $data );
if ( ! empty( $data ) ) {
$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 );
// !important, Clear the cache after images import.
Plugin::$instance->posts_css_manager->clear_cache();
return $data;
}
return array();
}
}

View File

@@ -0,0 +1,164 @@
<?php
/**
* Astra Sites
*
* @since 3.0.23
* @package Astra Sites
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Astra_Sites_Error_Handler
*/
class Astra_Sites_Error_Handler {
/**
* Instance of Astra_Sites_Error_Handler
*
* @since 3.0.23
* @var (Object) Astra_Sites_Error_Handler
*/
private static $instance = null;
/**
* Instance of Astra_Sites_Error_Handler.
*
* @since 3.0.23
*
* @return object Class object.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
public function __construct() {
require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer-log.php';
if ( true === astra_sites_has_import_started() ) {
$this->start_error_handler();
}
add_action( 'shutdown', array( $this, 'stop_handler' ) );
}
/**
* Stop the shutdown handlers.
*
* @return void
*/
public function stop_handler() {
if ( true === astra_sites_has_import_started() ) {
$this->stop_error_handler();
}
}
/**
* Start the error handling.
*/
public function start_error_handler() {
if ( ! interface_exists( 'Throwable' ) ) {
// Fatal error handler for PHP < 7.
register_shutdown_function( array( $this, 'shutdown_handler' ) );
}
// Fatal error handler for PHP >= 7, and uncaught exception handler for all PHP versions.
set_exception_handler( array( $this, 'exception_handler' ) );
}
/**
* Stop and restore the error handlers.
*/
public function stop_error_handler() {
// Restore the error handlers.
restore_error_handler();
restore_exception_handler();
}
/**
* Uncaught exception handler.
*
* In PHP >= 7 this will receive a Throwable object.
* In PHP < 7 it will receive an Exception object.
*
* @throws Exception Exception that is catched.
* @param Throwable|Exception $e The error or exception.
*/
public function exception_handler( $e ) {
if ( is_a( $e, 'Exception' ) ) {
$error = 'Uncaught Exception';
} else {
$error = 'Uncaught Error';
}
Astra_Sites_Importer_Log::add( 'There was an error on website: ' . $error );
Astra_Sites_Importer_Log::add( $e );
if ( wp_doing_ajax() ) {
wp_send_json_error(
array(
'message' => __( 'There was an error on your website.', 'astra-sites' ),
'stack' => array(
'error-message' => sprintf(
'%s: %s',
$error,
$e->getMessage()
),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTrace(),
),
)
);
}
throw $e;
}
/**
* Displays fatal error output for sites running PHP < 7.
*/
public function shutdown_handler() {
$e = error_get_last();
if ( empty( $e ) || ! ( $e['type'] & ST_ERROR_FATALS ) ) {
return;
}
if ( $e['type'] & E_RECOVERABLE_ERROR ) {
$error = 'Catchable fatal error';
} else {
$error = 'Fatal error';
}
Astra_Sites_Importer_Log::add( 'There was an error on website: ' . $error );
Astra_Sites_Importer_Log::add( $e );
if ( wp_doing_ajax() ) {
wp_send_json_error(
array(
'message' => __( 'There was an error your website.', 'astra-sites' ),
'stack' => array(
'error-message' => $error,
'error' => $e,
),
)
);
}
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Astra_Sites_Error_Handler::get_instance();

View File

@@ -0,0 +1,202 @@
<?php
/**
* Astra Sites File System
*
* @since 4.2.0
* @package Astra Sites
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Astra_Sites_File_System' ) ) {
/**
* Astra_Sites_File_System
*/
class Astra_Sites_File_System {
/**
* Instance of Astra_Sites
*
* @since 4.2.0
* @var (self) Astra_Sites
*/
private static $instance = null;
/**
* Folder name for the json files.
*
* @var string
* @since 4.2.0
*/
public static $folder_name = 'json';
/**
* Instance of Astra_Sites.
*
* @since 4.2.0
* @return self Class object.
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Create files for demo content.
*
* @return void
* @since 4.2.0
*/
public function create_file() {
$upload_dir = wp_upload_dir();
$file = array(
'file_base' => $upload_dir['basedir'] . '/astra-sites/' . self::$folder_name,
'file_name' => 'astra_sites_import_data.json',
'file_content' => array(),
);
$this->create_single_file( $file );
}
/**
* Delete a JSON file from the uploads directory.
*
* @param string $file_name File name to be deleted.
* @return void True on success, false on failure.
*/
public function delete_json_file( $file_name ) {
$upload_dir = wp_upload_dir();
$file_name = $upload_dir['basedir'] . '/astra-sites/' . self::$folder_name . '/' . $file_name;
if ( file_exists( $file_name ) ) {
wp_delete_file( $file_name );
} else {
astra_sites_error_log( 'File not found: ' . $file_name );
}
}
/**
* Getting json file for templates from uploads.
*
* @param string $file_name File data.
* @param bool $array_format Is The file content array.
*
* @return mixed
*/
public function get_json_file_content( $file_name, $array_format = true ) {
$upload_dir = wp_upload_dir();
$file_name = $upload_dir['basedir'] . '/astra-sites/' . self::$folder_name . '/' . $file_name;
if ( file_exists( $file_name ) ) {
// Ignoring the rule as it is not a remote file.
$file_content = file_get_contents( $file_name ); //phpcs:ignore WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown
if ( $array_format ) {
return json_decode( (string) $file_content, true );
} else {
return $file_content;
}
}
return '';
}
/**
* Getter for get_json_file_content
*
* @since 4.2.0
*
* @return mixed
*/
public function get_demo_content() {
return $this->get_json_file_content( 'astra_sites_import_data.json' );
}
/**
* Delete for get_json_file_content
*
* @since 4.2.0
*
* @return mixed
*/
public function delete_demo_content() {
$this->delete_json_file( 'astra_sites_import_data.json' );
}
/**
* Create single json file.
*
* @since 4.2.2
* @param array<string, mixed> $file file data.
*
* @return void
*/
public function create_single_file( $file ) {
if ( wp_mkdir_p( $file['file_base'] ) ) {
$file_handle = @fopen( trailingslashit( $file['file_base'] ) . $file['file_name'], 'w' ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.WP.AlternativeFunctions.file_system_read_fopen
if ( $file_handle ) {
if ( is_string( wp_json_encode( $file['file_content'] ) ) ) {
fwrite( $file_handle, wp_json_encode( $file['file_content'] ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite, WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_fwrite
fclose( $file_handle ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose
astra_sites_error_log( 'File: ' . $file['file_name'] . ' Created Successfully!' );
}
}
}
}
/**
* Update files/directories.
*
* @param string $file_name The file name.
* @param mixed $file_content The file content.
*
* @return void
*/
public function update_json_file( $file_name, $file_content ) {
$upload_dir = wp_upload_dir();
$dir_info = array(
'path' => $upload_dir['basedir'] . '/astra-sites/' . self::$folder_name . '/',
);
if ( ! file_exists( $dir_info['path'] . $file_name ) ) {
$file = array(
'file_base' => $dir_info['path'],
'file_name' => $file_name,
'file_content' => '',
);
$this->create_single_file( $file );
}
if ( file_exists( $dir_info['path'] . $file_name ) && file_put_contents( $dir_info['path'] . $file_name, wp_json_encode( $file_content ) ) !== false ) { //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_file_put_contents
astra_sites_error_log( 'File: ' . $file_name . ' Updated Successfully!' );
} else {
astra_sites_error_log( 'File: ' . $file_name . ' Not Updated!' );
}
}
/**
* Setter for update_json_file()
*
* @param string|int $file_content The file content.
*
* @return mixed
*/
public function update_demo_data( $file_content ) {
$this->update_json_file( 'astra_sites_import_data.json', $file_content );
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Astra_Sites_File_System::get_instance();
}

View File

@@ -0,0 +1,537 @@
<?php
/**
* Astra Sites Importer Log
*
* @since 1.1.0
* @package Astra Sites
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Astra_Sites_Importer_Log' ) ) :
/**
* Astra Sites Importer
*/
class Astra_Sites_Importer_Log {
/**
* Instance
*
* @since 1.1.0
* @var (Object) Class object
*/
private static $instance = null;
/**
* Log File
*
* @since 1.1.0
* @var (Object) Class object
*/
private static $log_file = null;
/**
* Set Instance
*
* @since 1.1.0
*
* @return object Class object.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor.
*
* @since 1.1.0
*/
private function __construct() {
// Check file read/write permissions.
if ( current_user_can( 'edit_posts' ) ) {
add_action( 'admin_init', array( $this, 'has_file_read_write' ) );
}
}
/**
* Check file read/write permissions and process.
*
* @since 1.1.0
* @return null
*/
public function has_file_read_write() {
$upload_dir = self::log_dir();
$file_created = Astra_Sites::get_instance()->get_filesystem()->put_contents( $upload_dir['path'] . 'index.html', '' );
if ( ! $file_created ) {
add_action( 'admin_notices', array( $this, 'file_permission_notice' ) );
return;
}
// Set log file.
self::set_log_file();
// Initial AJAX Import Hooks.
add_action( 'astra_sites_import_start', array( $this, 'start' ), 10, 2 );
}
/**
* File Permission Notice
*
* @since 2.0.0
* @return void
*/
public function file_permission_notice() {
$upload_dir = self::log_dir();
$plugin_name = ASTRA_SITES_NAME;
if ( is_callable( 'Astra_Sites_White_Label::get_instance' ) ) {
$is_white_label = Astra_Sites_White_Label::get_instance()->is_white_labeled();
$plugin_name = $is_white_label ? Astra_Sites_White_Label::get_instance()->get_white_label_name() : ASTRA_SITES_NAME;
}
/* translators: %1$s refers to the plugin name */
$notice = sprintf( __( 'Required File Permissions to import the templates from %s are missing.', 'astra-sites' ), $plugin_name );
?>
<div class="notice notice-error astra-sites-must-notices astra-sites-file-permission-issue">
<p><?php echo esc_html( $notice ); ?></p>
<?php if ( defined( 'FS_METHOD' ) ) { ?>
<p><?php esc_html_e( 'This is usually due to inconsistent file permissions.', 'astra-sites' ); ?></p>
<p><code><?php echo esc_html( $upload_dir['path'] ); ?></code></p>
<?php } else { ?>
<p><?php esc_html_e( 'You can easily update permissions by adding the following code into the wp-config.php file.', 'astra-sites' ); ?></p>
<p><code>define( 'FS_METHOD', 'direct' );</code></p>
<?php } ?>
</div>
<?php
}
/**
* Add log file URL in UI response.
*
* @since 1.1.0
*/
public static function add_log_file_url() {
$upload_dir = self::log_dir();
$upload_path = trailingslashit( $upload_dir['url'] );
$file_abs_url = get_option( 'astra_sites_recent_import_log_file', self::$log_file );
$file_url = $upload_path . basename( $file_abs_url );
return array(
'abs_url' => $file_abs_url,
'url' => $file_url,
);
}
/**
* Current Time for log.
*
* @since 1.1.0
* @return string Current time with time zone.
*/
public static function current_time() {
return gmdate( 'H:i:s' ) . ' ' . date_default_timezone_get();
}
/**
* Import Start
*
* @since 1.1.0
* @param array $data Import Data.
* @param string $demo_api_uri Import site API URL.
* @return void
*/
public function start( $data = array(), $demo_api_uri = '' ) {
self::add( 'Started Import Process' );
self::add( '# System Details: ' );
self::add( "Debug Mode \t\t: " . self::get_debug_mode() );
self::add( "Operating System \t: " . self::get_os() );
self::add( "Software \t\t: " . self::get_software() );
self::add( "MySQL version \t\t: " . self::get_mysql_version() );
self::add( "XML Reader \t\t: " . self::get_xmlreader_status() );
self::add( "PHP Version \t\t: " . self::get_php_version() );
self::add( "PHP Max Input Vars \t: " . self::get_php_max_input_vars() );
self::add( "PHP Max Post Size \t: " . self::get_php_max_post_size() );
self::add( "PHP Extension GD \t: " . self::get_php_extension_gd() );
self::add( "PHP Max Execution Time \t: " . self::get_max_execution_time() );
self::add( "Max Upload Size \t: " . size_format( wp_max_upload_size() ) );
self::add( "Memory Limit \t\t: " . self::get_memory_limit() );
self::add( "Timezone \t\t: " . self::get_timezone() );
self::add( PHP_EOL . '-----' . PHP_EOL );
self::add( 'Importing Started! - ' . self::current_time() );
self::add( '---' . PHP_EOL );
self::add( 'WHY IMPORT PROCESS CAN FAIL? READ THIS - ' );
self::add( 'https://wpastra.com/docs/?p=1314&utm_source=demo-import-panel&utm_campaign=import-error&utm_medium=wp-dashboard' . PHP_EOL );
self::add( '---' . PHP_EOL );
}
/**
* Get Log File
*
* @since 1.1.0
* @return string log file URL.
*/
public static function get_log_file() {
return self::$log_file;
}
/**
* Log file directory
*
* @since 1.1.0
* @param string $dir_name Directory Name.
* @return array Uploads directory array.
*/
public static function log_dir( $dir_name = 'astra-sites' ) {
$upload_dir = wp_upload_dir();
// Build the paths.
$dir_info = array(
'path' => $upload_dir['basedir'] . '/' . $dir_name . '/',
'url' => $upload_dir['baseurl'] . '/' . $dir_name . '/',
);
// Create the upload dir if it doesn't exist.
if ( ! file_exists( $dir_info['path'] ) ) {
// Create the directory.
wp_mkdir_p( $dir_info['path'] );
// Add an index file for security.
Astra_Sites::get_instance()->get_filesystem()->put_contents( $dir_info['path'] . 'index.html', '' );
// Add an .htaccess for security.
Astra_Sites::get_instance()->get_filesystem()->put_contents( $dir_info['path'] . '.htaccess', 'deny from all' );
}
return $dir_info;
}
/**
* Set log file
*
* @since 1.1.0
*/
public static function set_log_file() {
$upload_dir = self::log_dir();
$upload_path = trailingslashit( $upload_dir['path'] );
// File format e.g. 'import-31-Oct-2017-06-39-12-hashcode.log'.
self::$log_file = $upload_path . 'import-' . gmdate( 'd-M-Y-h-i-s' ) . '-' . wp_hash( 'starter-templates-log' ) . '.log';
if ( ! get_option( 'astra_sites_recent_import_log_file', false ) ) {
update_option( 'astra_sites_recent_import_log_file', self::$log_file, 'no' );
}
}
/**
* Write content to a file.
*
* @since 1.1.0
* @param string $content content to be saved to the file.
*/
public static function add( $content ) {
if ( get_option( 'astra_sites_recent_import_log_file', false ) ) {
$log_file = get_option( 'astra_sites_recent_import_log_file', self::$log_file );
} else {
$log_file = self::$log_file;
}
if ( apply_filters( 'astra_sites_debug_logs', false ) ) {
error_log( $content ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- This is for the debug logs while importing. This is conditional and will not be logged in the debug.log file for normal users.
}
$existing_data = '';
if ( file_exists( $log_file ) ) {
$existing_data = Astra_Sites::get_instance()->get_filesystem()->get_contents( $log_file );
}
// Style separator.
$separator = PHP_EOL;
Astra_Sites::get_instance()->get_filesystem()->put_contents( $log_file, $existing_data . $separator . $content, FS_CHMOD_FILE );
}
/**
* Debug Mode
*
* @since 1.1.0
* @return string Enabled for Debug mode ON and Disabled for Debug mode Off.
*/
public static function get_debug_mode() {
if ( WP_DEBUG ) {
return __( 'Enabled', 'astra-sites' );
}
return __( 'Disabled', 'astra-sites' );
}
/**
* Memory Limit
*
* @since 1.1.0
* @return string Memory limit.
*/
public static function get_memory_limit() {
$required_memory = '64M';
$memory_limit_in_bytes_current = wp_convert_hr_to_bytes( WP_MEMORY_LIMIT );
$memory_limit_in_bytes_required = wp_convert_hr_to_bytes( $required_memory );
if ( $memory_limit_in_bytes_current < $memory_limit_in_bytes_required ) {
return sprintf(
/* translators: %1$s Memory Limit, %2$s Recommended memory limit. */
_x( 'Current memory limit %1$s. We recommend setting memory to at least %2$s.', 'Recommended Memory Limit', 'astra-sites' ),
WP_MEMORY_LIMIT,
$required_memory
);
}
return WP_MEMORY_LIMIT;
}
/**
* Timezone
*
* @since 1.1.0
* @see https://codex.wordpress.org/Option_Reference/
*
* @return string Current timezone.
*/
public static function get_timezone() {
$timezone = get_option( 'timezone_string' );
if ( ! $timezone ) {
return get_option( 'gmt_offset' );
}
return $timezone;
}
/**
* Operating System
*
* @since 1.1.0
* @return string Current Operating System.
*/
public static function get_os() {
return PHP_OS;
}
/**
* Server Software
*
* @since 1.1.0
* @return string Current Server Software.
*/
public static function get_software() {
return isset( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( $_SERVER['SERVER_SOFTWARE'] ) : '';
}
/**
* MySql Version
*
* @since 1.1.0
* @return string Current MySql Version.
*/
public static function get_mysql_version() {
global $wpdb;
return $wpdb->db_version();
}
/**
* XML Reader
*
* @since 1.2.8
* @return string Current XML Reader status.
*/
public static function get_xmlreader_status() {
if ( class_exists( 'XMLReader' ) ) {
return __( 'Yes', 'astra-sites' );
}
return __( 'No', 'astra-sites' );
}
/**
* PHP Version
*
* @since 1.1.0
* @return string Current PHP Version.
*/
public static function get_php_version() {
if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
return _x( 'We recommend to use php 5.4 or higher', 'PHP Version', 'astra-sites' );
}
return PHP_VERSION;
}
/**
* PHP Max Input Vars
*
* @since 1.1.0
* @return string Current PHP Max Input Vars
*/
public static function get_php_max_input_vars() {
return ini_get( 'max_input_vars' ); // phpcs:disable PHPCompatibility.IniDirectives.NewIniDirectives.max_input_varsFound
}
/**
* PHP Max Post Size
*
* @since 1.1.0
* @return string Current PHP Max Post Size
*/
public static function get_php_max_post_size() {
return ini_get( 'post_max_size' );
}
/**
* PHP Max Execution Time
*
* @since 1.1.0
* @return string Current Max Execution Time
*/
public static function get_max_execution_time() {
return ini_get( 'max_execution_time' );
}
/**
* PHP GD Extension
*
* @since 1.1.0
* @return string Current PHP GD Extension
*/
public static function get_php_extension_gd() {
if ( extension_loaded( 'gd' ) ) {
return __( 'Yes', 'astra-sites' );
}
return __( 'No', 'astra-sites' );
}
/**
* Display Data
*
* @since 2.0.0
* @return void
*/
public function display_data() {
$crons = _get_cron_array();
$events = array();
if ( empty( $crons ) ) {
esc_html_e( 'You currently have no scheduled cron events.', 'astra-sites' );
}
foreach ( $crons as $time => $cron ) {
$keys = array_keys( $cron );
$key = $keys[0];
$events[ $key ] = $time;
}
$expired = get_site_transient( 'astra-sites-import-check' );
if ( $expired ) {
global $wpdb;
$transient = 'astra-sites-import-check';
$transient_timeout = $wpdb->get_col(
$wpdb->prepare(
"SELECT option_value
FROM $wpdb->options
WHERE option_name
LIKE %s",
'%_transient_timeout_' . $transient . '%'
)
); // WPCS: cache ok. // WPCS: db call ok.
$older_date = $transient_timeout[0];
$transient_status = 'Transient: Not Expired! Recheck in ' . human_time_diff( time(), $older_date );
} else {
$transient_status = 'Transient: Starting.. Process for each 5 minutes.';
}
$temp = get_site_option( 'astra-sites-batch-status-string', '' );
$temp .= isset( $events['wp_astra_site_importer_cron'] ) ? '<br/>Batch: Recheck batch in ' . human_time_diff( time(), $events['wp_astra_site_importer_cron'] ) : '<br/>Batch: Not Started! Until the Transient expire.';
$upload_dir = self::get_instance()->log_dir();
$list_files = list_files( $upload_dir['path'] );
$backup_files = array();
$log_files = array();
foreach ( $list_files as $key => $file ) {
if ( strpos( $file, '.json' ) ) {
$backup_files[] = $file;
}
if ( strpos( $file, '.txt' ) ) {
$log_files[] = $file;
}
}
?>
<table>
<tr>
<td>
<h2>Log Files</h2>
<ul>
<?php
foreach ( $log_files as $key => $file ) {
$file_name = basename( $file );
$file = str_replace( $upload_dir['path'], $upload_dir['url'], $file );
?>
<li>
<a target="_blank" href="<?php echo esc_url( $file ); ?>"><?php echo esc_html( $file_name ); ?></a>
</li>
<?php } ?>
</ul>
</td>
<td>
<h2>Backup Files</h2>
<ul>
<?php
foreach ( $backup_files as $key => $file ) {
$file_name = basename( $file );
$file = str_replace( $upload_dir['path'], $upload_dir['url'], $file );
?>
<li>
<a target="_blank" href="<?php echo esc_url( $file ); ?>"><?php echo esc_html( $file_name ); ?></a>
</li>
<?php } ?>
</ul>
</td>
<td>
<div class="batch-log">
<p><?php echo wp_kses_post( $temp ); ?></p>
<p><?php echo wp_kses_post( $transient_status ); ?></p>
</div>
</td>
</tr>
</table>
<?php
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Astra_Sites_Importer_Log::get_instance();
endif;

View File

@@ -0,0 +1,678 @@
<?php
/**
* Astra Sites Importer
*
* @since 1.0.0
* @package Astra Sites
*/
use STImporter\Importer\ST_Importer_Helper;
use STImporter\Importer\WXR_Importer\ST_WXR_Importer;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
if ( ! class_exists( 'Astra_Sites_Importer' ) ) {
/**
* Astra Sites Importer
*/
class Astra_Sites_Importer {
/**
* Instance
*
* @since 1.0.0
* @var (Object) Class object
*/
public static $instance = null;
/**
* Set Instance
*
* @since 1.0.0
*
* @return object Class object.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct() {
require_once ASTRA_SITES_DIR . 'inc/classes/class-astra-sites-importer-log.php';
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-sites-helper.php';
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-widget-importer.php';
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-customizer-import.php';
require_once ASTRA_SITES_DIR . 'inc/importers/class-astra-site-options-import.php';
// Hooks in AJAX.
add_action( 'wp_ajax_astra-sites-import-wpforms', array( $this, 'import_wpforms' ) );
add_action( 'wp_ajax_astra-sites-import-cartflows', array( $this, 'import_cartflows' ) );
add_action( 'wp_ajax_astra-sites-import-latepoint', array( $this, 'import_latepoint' ) );
add_action( 'astra_sites_import_complete', array( $this, 'clear_related_cache' ) );
require_once ASTRA_SITES_DIR . 'inc/importers/batch-processing/class-astra-sites-batch-processing.php';
if ( version_compare( get_bloginfo( 'version' ), '5.1.0', '>=' ) ) {
add_filter( 'http_request_timeout', array( $this, 'set_timeout_for_images' ), 10, 2 ); //phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_timeout -- We need this to avoid timeout on slow servers while installing theme, plugin etc.
}
add_action( 'init', array( $this, 'disable_default_woo_pages_creation' ), 2 );
add_filter( 'upgrader_package_options', array( $this, 'plugin_install_clear_directory' ) );
}
/**
* Delete imported posts
*
* @since 1.3.0
* @since 1.4.0 The `$post_id` was added.
* Note: This function can be deleted after a few releases since we are performing the delete operation in chunks.
*
* @param integer $post_id Post ID.
* @return void
*/
public function delete_imported_posts( $post_id = 0 ) {
if ( wp_doing_ajax() ) {
// Verify Nonce.
check_ajax_referer( 'astra-sites', '_ajax_nonce' );
if ( ! current_user_can( 'customize' ) ) {
wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
}
}
$post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : $post_id;
$message = 'Deleted - Post ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
$message = '';
if ( $post_id ) {
$post_type = get_post_type( $post_id );
$message = 'Deleted - Post ID ' . $post_id . ' - ' . $post_type . ' - ' . get_the_title( $post_id );
do_action( 'astra_sites_before_delete_imported_posts', $post_id, $post_type );
Astra_Sites_Importer_Log::add( $message );
wp_delete_post( $post_id, true );
}
if ( defined( 'WP_CLI' ) ) {
WP_CLI::line( $message );
} elseif ( wp_doing_ajax() ) {
wp_send_json_success( $message );
}
}
/**
* Delete imported WP forms
*
* @since 1.3.0
* @since 1.4.0 The `$post_id` was added.
* Note: This function can be deleted after a few releases since we are performing the delete operation in chunks.
*
* @param integer $post_id Post ID.
* @return void
*/
public function delete_imported_wp_forms( $post_id = 0 ) {
if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) {
// Verify Nonce.
check_ajax_referer( 'astra-sites', '_ajax_nonce' );
if ( ! current_user_can( 'customize' ) ) {
wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
}
}
$post_id = isset( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : $post_id;
$message = '';
if ( $post_id ) {
do_action( 'astra_sites_before_delete_imported_wp_forms', $post_id );
$message = 'Deleted - Form ID ' . $post_id . ' - ' . get_post_type( $post_id ) . ' - ' . get_the_title( $post_id );
Astra_Sites_Importer_Log::add( $message );
wp_delete_post( $post_id, true );
}
if ( defined( 'WP_CLI' ) ) {
WP_CLI::line( $message );
} elseif ( wp_doing_ajax() ) {
wp_send_json_success( $message );
}
}
/**
* Delete imported terms
*
* @since 1.3.0
* @since 1.4.0 The `$post_id` was added.
* Note: This function can be deleted after a few releases since we are performing the delete operation in chunks.
*
* @param integer $term_id Term ID.
* @return void
*/
public function delete_imported_terms( $term_id = 0 ) {
if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) {
// Verify Nonce.
check_ajax_referer( 'astra-sites', '_ajax_nonce' );
if ( ! current_user_can( 'customize' ) ) {
wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
}
}
$term_id = isset( $_REQUEST['term_id'] ) ? absint( $_REQUEST['term_id'] ) : $term_id;
$message = '';
if ( $term_id ) {
$term = get_term( $term_id );
if ( ! is_wp_error( $term ) && ! empty( $term ) && is_object( $term ) ) {
do_action( 'astra_sites_before_delete_imported_terms', $term_id, $term );
$message = 'Deleted - Term ' . $term_id . ' - ' . $term->name . ' ' . $term->taxonomy;
Astra_Sites_Importer_Log::add( $message );
wp_delete_term( $term_id, $term->taxonomy );
}
}
if ( defined( 'WP_CLI' ) ) {
WP_CLI::line( $message );
} elseif ( wp_doing_ajax() ) {
wp_send_json_success( $message );
}
}
/**
* Delete related transients
*
* @since 3.1.3
*/
public function delete_related_transient() {
delete_option( 'astra_sites_batch_process_started' );
Astra_Sites_File_System::get_instance()->delete_demo_content();
delete_option( 'ast_ai_import_current_url' );
delete_option( 'astra_sites_ai_import_started' );
}
/**
* Delete directory when installing plugin.
*
* Set by enabling `clear_destination` option in the upgrader.
*
* @since 3.0.10
* @param array $options Options for the upgrader.
* @return array $options The options.
*/
public function plugin_install_clear_directory( $options ) {
if ( true !== astra_sites_has_import_started() ) {
return $options;
}
$is_ast_request = isset( $_REQUEST['is_ast_request'] ) && 'true' === $_REQUEST['is_ast_request']; //phpcs:ignore
if ( ! $is_ast_request ) {
return $options;
}
// Verify Nonce.
check_ajax_referer( 'astra-sites', 'ajax_nonce' );
if ( isset( $_REQUEST['clear_destination'] ) && 'true' === $_REQUEST['clear_destination'] ) {
$options['clear_destination'] = true;
}
return $options;
}
/**
* Restrict WooCommerce Pages Creation process
*
* Why? WooCommerce creates set of pages on it's activation
* These pages are re created via our XML import step.
* In order to avoid the duplicacy we restrict these page creation process.
*
* @since 3.0.0
*/
public function disable_default_woo_pages_creation() {
if ( astra_sites_has_import_started() ) {
add_filter( 'woocommerce_create_pages', '__return_empty_array' );
}
}
/**
* Set the timeout for the HTTP request by request URL.
*
* E.g. If URL is images (jpg|png|gif|jpeg) are from the domain `https://websitedemos.net` then we have set the timeout by 30 seconds. Default 5 seconds.
*
* @since 1.3.8
*
* @param int $timeout_value Time in seconds until a request times out. Default 5.
* @param string $url The request URL.
*/
public function set_timeout_for_images( $timeout_value, $url ) {
// URL not contain `https://websitedemos.net` then return $timeout_value.
if ( strpos( $url, 'https://websitedemos.net' ) === false ) {
return $timeout_value;
}
// Check is image URL of type jpg|png|gif|jpeg.
if ( astra_sites_is_valid_image( $url ) ) {
$timeout_value = 300;
}
return $timeout_value;
}
/**
* Change flow status
*
* @since 2.0.0
*
* @param array $args Flow query args.
* @return array Flow query args.
*/
public function change_flow_status( $args ) {
$args['post_status'] = 'publish';
return $args;
}
/**
* Track Flow
*
* @since 2.0.0
*
* @param integer $flow_id Flow ID.
* @return void
*/
public function track_flows( $flow_id ) {
Astra_Sites_Importer_Log::add( 'Flow ID ' . $flow_id );
ST_Importer_Helper::track_post( $flow_id );
}
/**
* Import WP Forms
*
* @since 1.2.14
* @since 1.4.0 The `$wpforms_url` was added.
*
* @param string $wpforms_url WP Forms JSON file URL.
* @return void
*/
public function import_wpforms( $wpforms_url = '' ) {
if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) {
// Verify Nonce.
check_ajax_referer( 'astra-sites', '_ajax_nonce' );
if ( ! current_user_can( 'customize' ) ) {
wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
}
}
$screen = ( isset( $_REQUEST['screen'] ) ) ? sanitize_text_field( $_REQUEST['screen'] ) : '';
$id = ( isset( $_REQUEST['id'] ) ) ? absint( $_REQUEST['id'] ) : '';
$wpforms_url = ( 'elementor' === $screen ) ? astra_sites_get_wp_forms_url( $id ) : astra_get_site_data( 'astra-site-wpforms-path' );
$ids_mapping = array();
if ( ! astra_sites_is_valid_url( $wpforms_url ) ) {
/* Translators: %s is WP Forms URL. */
wp_send_json_error( sprintf( __( 'Invalid WPform Request URL - %s', 'astra-sites' ), $wpforms_url ) );
}
if ( ! empty( $wpforms_url ) && function_exists( 'wpforms_encode' ) ) {
// Download JSON file.
$file_path = ST_WXR_Importer::download_file( $wpforms_url );
if ( $file_path['success'] ) {
if ( isset( $file_path['data']['file'] ) ) {
$ext = strtolower( pathinfo( $file_path['data']['file'], PATHINFO_EXTENSION ) );
if ( 'json' === $ext ) {
$forms = json_decode( Astra_Sites::get_instance()->get_filesystem()->get_contents( $file_path['data']['file'] ), true );
if ( ! empty( $forms ) ) {
foreach ( $forms as $form ) {
$title = ! empty( $form['settings']['form_title'] ) ? $form['settings']['form_title'] : '';
$desc = ! empty( $form['settings']['form_desc'] ) ? $form['settings']['form_desc'] : '';
$new_id = post_exists( $title );
if ( ! $new_id ) {
$new_id = wp_insert_post(
array(
'post_title' => $title,
'post_status' => 'publish',
'post_type' => 'wpforms',
'post_excerpt' => $desc,
)
);
if ( defined( 'WP_CLI' ) ) {
WP_CLI::line( 'Imported Form ' . $title );
}
// Set meta for tracking the post.
update_post_meta( $new_id, '_astra_sites_imported_wp_forms', true );
Astra_Sites_Importer_Log::add( 'Inserted WP Form ' . $new_id );
}
if ( $new_id ) {
// ID mapping.
$ids_mapping[ $form['id'] ] = $new_id;
$form['id'] = $new_id;
wp_update_post(
array(
'ID' => $new_id,
'post_content' => wpforms_encode( $form ),
)
);
}
}
}
} else {
wp_send_json_error( __( 'Invalid JSON file for WP Forms.', 'astra-sites' ) );
}
} else {
wp_send_json_error( __( 'There was an error downloading the WP Forms file.', 'astra-sites' ) );
}
} else {
wp_send_json_error( __( 'There was an error downloading the WP Forms file.', 'astra-sites' ) );
}
}
update_option( 'astra_sites_wpforms_ids_mapping', $ids_mapping, 'no' );
if ( defined( 'WP_CLI' ) ) {
WP_CLI::line( 'WP Forms Imported.' );
} elseif ( wp_doing_ajax() ) {
wp_send_json_success( $ids_mapping );
}
}
/**
* Import CartFlows
*
* @since 2.0.0
*
* @param string $url Cartflows JSON file URL.
* @return void
*/
public function import_cartflows( $url = '' ) {
if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) {
// Verify Nonce.
check_ajax_referer( 'astra-sites', '_ajax_nonce' );
if ( ! current_user_can( 'edit_posts' ) ) {
wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
}
}
// Disable CartFlows import logging.
add_filter( 'cartflows_enable_log', '__return_false' );
// Make the flow publish.
add_filter( 'cartflows_flow_importer_args', array( $this, 'change_flow_status' ) );
add_action( 'cartflows_flow_imported', array( $this, 'track_flows' ) );
add_action( 'cartflows_step_imported', array( $this, 'track_flows' ) );
add_filter( 'cartflows_enable_imported_content_processing', '__return_false' );
$url = astra_get_site_data( 'astra-site-cartflows-path' );
if ( ! empty( $url ) && is_callable( 'CartFlows_Importer::get_instance' ) ) {
// Download JSON file.
$file_path = ST_WXR_Importer::download_file( $url );
if ( $file_path['success'] ) {
if ( isset( $file_path['data']['file'] ) ) {
$ext = strtolower( pathinfo( $file_path['data']['file'], PATHINFO_EXTENSION ) );
if ( 'json' === $ext ) {
$flows = json_decode( Astra_Sites::get_instance()->get_filesystem()->get_contents( $file_path['data']['file'] ), true );
if ( ! empty( $flows ) && class_exists( 'CartFlows_Importer' ) ) {
CartFlows_Importer::get_instance()->import_from_json_data( $flows );
}
} else {
wp_send_json_error( __( 'Invalid file for CartFlows flows', 'astra-sites' ) );
}
} else {
wp_send_json_error( __( 'There was an error downloading the CartFlows flows file.', 'astra-sites' ) );
}
} else {
wp_send_json_error( __( 'There was an error downloading the CartFlows flows file.', 'astra-sites' ) );
}
} else {
wp_send_json_error( __( 'Empty file for CartFlows flows', 'astra-sites' ) );
}
if ( defined( 'WP_CLI' ) ) {
WP_CLI::line( 'Imported from ' . $url );
} elseif ( wp_doing_ajax() ) {
wp_send_json_success( $url );
}
}
/**
* Import LatePoint
*
* @since 2.0.0
*
* @param string $url LatePoint JSON file URL.
* @return void
*/
public function import_latepoint( $url = '' ) {
if ( ! defined( 'WP_CLI' ) && wp_doing_ajax() ) {
// Verify Nonce.
check_ajax_referer( 'astra-sites', '_ajax_nonce' );
if ( ! current_user_can( 'edit_posts' ) ) {
wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
}
}
$url = astra_get_site_data( 'astra-site-latepoint-path' );
if ( ! empty( $url ) && class_exists( 'OsSettingsHelper' ) ) {
// Download JSON file.
$file_path = ST_WXR_Importer::download_file( $url );
if ( $file_path['success'] ) {
if ( isset( $file_path['data']['file'] ) ) {
$ext = strtolower( pathinfo( $file_path['data']['file'], PATHINFO_EXTENSION ) );
if ( 'json' === $ext ) {
$content = Astra_Sites::get_instance()->get_filesystem()->get_contents( $file_path['data']['file'] );
if ( ! empty( $content ) && is_callable( 'OsSettingsHelper::import_data' ) ) {
OsSettingsHelper::import_data( $content );
}
} else {
wp_send_json_error( __( 'Invalid file for Latepoint tables', 'astra-sites' ) );
}
} else {
wp_send_json_error( __( 'There was an error downloading the Latepoint tables file.', 'astra-sites' ) );
}
} else {
wp_send_json_error( __( 'There was an error downloading the Latepoint tables file.', 'astra-sites' ) );
}
} else {
wp_send_json_error( __( 'Empty file for Latepoint tables', 'astra-sites' ) );
}
if ( defined( 'WP_CLI' ) ) {
WP_CLI::line( 'Imported from ' . $url );
} elseif ( wp_doing_ajax() ) {
wp_send_json_success( $url );
}
}
/**
* Get single demo.
*
* @since 1.0.0
*
* @param (String) $demo_api_uri API URL of a demo.
*
* @return (Array) $astra_demo_data demo data for the demo.
*/
public static function get_single_demo( $demo_api_uri ) {
if ( is_int( $demo_api_uri ) ) {
$demo_api_uri = Astra_Sites::get_instance()->get_api_url() . 'astra-sites/' . $demo_api_uri;
}
// default values.
$remote_args = array();
$defaults = array(
'id' => '',
'astra-site-widgets-data' => '',
'astra-site-customizer-data' => '',
'astra-site-options-data' => '',
'astra-post-data-mapping' => '',
'astra-site-wxr-path' => '',
'astra-site-wpforms-path' => '',
'astra-enabled-extensions' => '',
'astra-custom-404' => '',
'required-plugins' => '',
'astra-site-taxonomy-mapping' => '',
'license-status' => '',
'site-type' => '',
'astra-site-url' => '',
);
$api_args = apply_filters(
'astra_sites_api_args',
array(
'timeout' => 15,
)
);
// Use this for premium demos.
$request_params = apply_filters(
'astra_sites_api_params',
array(
'purchase_key' => '',
'site_url' => '',
)
);
$demo_api_uri = add_query_arg( $request_params, trailingslashit( $demo_api_uri ) );
// API Call.
$response = wp_safe_remote_get( $demo_api_uri, $api_args );
if ( is_wp_error( $response ) || ( isset( $response->status ) && 0 === $response->status ) ) {
if ( isset( $response->status ) ) {
$data = json_decode( $response, true );
} else {
return new WP_Error( 'api_invalid_response_code', $response->get_error_message() );
}
}
if ( wp_remote_retrieve_response_code( $response ) !== 200 ) {
return new WP_Error( 'api_invalid_response_code', wp_remote_retrieve_body( $response ) );
} else {
$data = json_decode( wp_remote_retrieve_body( $response ), true );
}
$data = json_decode( wp_remote_retrieve_body( $response ), true );
if ( ! isset( $data['code'] ) ) {
$remote_args['id'] = $data['id'];
$remote_args['astra-site-widgets-data'] = json_decode( $data['astra-site-widgets-data'] );
$remote_args['astra-site-customizer-data'] = $data['astra-site-customizer-data'];
$remote_args['astra-site-options-data'] = $data['astra-site-options-data'];
$remote_args['astra-post-data-mapping'] = $data['astra-post-data-mapping'];
$remote_args['astra-site-wxr-path'] = $data['astra-site-wxr-path'];
$remote_args['astra-site-wpforms-path'] = $data['astra-site-wpforms-path'];
$remote_args['astra-enabled-extensions'] = $data['astra-enabled-extensions'];
$remote_args['astra-custom-404'] = $data['astra-custom-404'];
$remote_args['required-plugins'] = $data['required-plugins'];
$remote_args['astra-site-taxonomy-mapping'] = $data['astra-site-taxonomy-mapping'];
$remote_args['license-status'] = $data['license-status'];
$remote_args['site-type'] = $data['astra-site-type'];
$remote_args['astra-site-url'] = $data['astra-site-url'];
}
// Merge remote demo and defaults.
return wp_parse_args( $remote_args, $defaults );
}
/**
* Clear Cache.
*
* @since 1.0.9
*/
public function clear_related_cache() {
// Clear 'Builder Builder' cache.
if ( is_callable( 'FLBuilderModel::delete_asset_cache_for_all_posts' ) ) {
FLBuilderModel::delete_asset_cache_for_all_posts();
Astra_Sites_Importer_Log::add( 'Cache for Beaver Builder cleared.' );
}
// Clear 'Astra Addon' cache.
if ( is_callable( 'Astra_Minify::refresh_assets' ) ) {
Astra_Minify::refresh_assets();
Astra_Sites_Importer_Log::add( 'Cache for Astra Addon cleared.' );
}
Astra_Sites_Utils::third_party_cache_plugins_clear_cache();
$this->update_latest_checksums();
// Flush permalinks.
flush_rewrite_rules(); //phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.flush_rewrite_rules_flush_rewrite_rules -- This function is called only after import is completed
}
/**
* Update Latest Checksums
*
* Store latest checksum after batch complete.
*
* @since 2.0.0
* @return void
*/
public function update_latest_checksums() {
$latest_checksums = get_site_option( 'astra-sites-last-export-checksums-latest', '' );
update_site_option( 'astra-sites-last-export-checksums', $latest_checksums );
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Astra_Sites_Importer::get_instance();
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* Init
*
* @since 1.0.0
* @package NPS Survey
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Astra_Sites_Nps_Notice' ) ) :
/**
* Admin
*/
class Astra_Sites_Nps_Notice {
/**
* Instance
*
* @since 1.0.0
* @var (Object) Astra_Sites_Nps_Notice
*/
private static $instance = null;
/**
* Get Instance
*
* @since 1.0.0
*
* @return object Class object.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor.
*
* @since 1.0.0
*/
private function __construct() {
add_action( 'admin_footer', array( $this, 'render_nps_survey' ), 999 );
}
/**
* Render NPS Survey
*
* @return void
*/
public function render_nps_survey() {
if ( ! class_exists( 'Nps_Survey' ) ) {
return;
}
if ( class_exists( 'Astra_Sites_White_Label' ) && is_callable( 'Astra_Sites_White_Label::get_instance' ) && Astra_Sites_White_Label::get_instance()->is_white_labeled() ) {
return;
}
$allowed_screens = array( 'appearance_page_starter-templates', 'appearance_page_ai-builder' );
Nps_Survey::show_nps_notice(
'nps-survey-astra-sites',
array(
'show_if' => get_option( 'astra_sites_import_complete', false ),
'dismiss_timespan' => 2 * WEEK_IN_SECONDS,
'display_after' => 0,
'plugin_slug' => 'astra-sites',
'show_on_screens' => $allowed_screens,
'message' => array(
// Step 1 i.e rating input.
'logo' => esc_url( INTELLIGENT_TEMPLATES_URI . 'assets/images/logo.svg' ),
'plugin_name' => __( 'Starter Templates', 'astra-sites' ),
'nps_rating_message' => __( 'How likely are you to recommend #pluginname to your friends or colleagues?', 'astra-sites' ),
// Step 2A i.e. positive.
'feedback_title' => __( 'Thanks a lot for your feedback! 😍', 'astra-sites' ),
'feedback_content' => __( 'Could you please do us a favor and give us a 5-star rating on WordPress? It would help others choose Starter Templates with confidence. Thank you!', 'astra-sites' ),
'plugin_rating_link' => esc_url( 'https://wordpress.org/support/plugin/astra-sites/reviews/#new-post' ),
// Step 2B i.e. negative.
'plugin_rating_title' => __( 'Thank you for your feedback', 'astra-sites' ),
'plugin_rating_content' => __( 'We value your input. How can we improve your experience?', 'astra-sites' ),
),
)
);
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Astra_Sites_Nps_Notice::get_instance();
endif;

View File

@@ -0,0 +1,613 @@
<?php
/**
* Astra Sites Page
*
* @since 1.0.6
* @package Astra Sites
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Astra_Sites_Page' ) ) {
/**
* Astra Admin Settings
*/
class Astra_Sites_Page {
/**
* View all actions
*
* @since 1.0.6
* @var array $view_actions
*/
public $view_actions = array();
/**
* Member Variable
*
* @var instance
*/
private static $instance;
/**
* Initiator
*
* @since 1.3.0
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*
* @since 1.3.0
*/
public function __construct() {
if ( ! current_user_can( 'edit_posts' ) ) {
return;
}
add_action( 'wp_ajax_astra-sites-change-page-builder', array( $this, 'save_page_builder_on_ajax' ) );
add_action( 'wp_ajax_astra-sites-dismiss-ai-promotion', array( $this, 'dismiss_ai_promotion' ) );
add_action( 'admin_init', array( $this, 'getting_started' ) );
}
/**
* Admin notice
*
* @since 1.3.5
*
* @return void
*/
public function getting_started() {
$current_screen = get_current_screen();
// Bail if not on Astra Sites screen.
if ( ! is_object( $current_screen ) && null === $current_screen ) {
return;
}
if ( 'plugins' === $current_screen->base ) {
$processed = get_option( '_astra_sites_gettings_started', 'no' );
$product_name = Astra_Sites_White_Label::get_instance()->get_white_label_name( 'Astra' );
if ( 'yes' === $processed ) {
return;
}
$arguments = array(
'page' => 'starter-templates',
);
$url = add_query_arg( $arguments, admin_url( 'themes.php' ) );
?>
<div class="notice notice-info is-dismissible astra-sites-notice astra-sites-getting-started-notice">
<?php /* translators: %1$s is the admin page URL, %2$s is product name. */ ?>
<p><?php printf( esc_attr__( 'Thank you for choosing %1$s! Check the library of <a class="astra-sites-getting-started-btn" href="%2$s">ready starter templates here »</a>', 'astra-sites' ), esc_html( $product_name ), esc_url( $url ) ); ?></p>
</div>
<?php
}
}
/**
* Save Page Builder
*
* @since 1.4.0 The `$page_builder_slug` was added.
*
* @param string $page_builder_slug Page Builder Slug.
* @return mixed
*/
public function save_page_builder_on_submit( $page_builder_slug = '' ) {
// Only admins can save settings.
if ( ! defined( 'WP_CLI' ) && ! current_user_can( 'manage_options' ) ) {
return;
}
if ( ! defined( 'WP_CLI' ) && ( ! isset( $_REQUEST['astra-sites-page-builder'] ) || ! wp_verify_nonce( sanitize_text_field( $_REQUEST['astra-sites-page-builder'] ), 'astra-sites-welcome-screen' ) ) ) {
return;
}
// Stored Settings.
$stored_data = $this->get_settings();
$page_builder = isset( $_REQUEST['page_builder'] ) ? sanitize_key( $_REQUEST['page_builder'] ) : sanitize_key( $page_builder_slug );
if ( ! empty( $page_builder ) ) {
// New settings.
$new_data = array(
'page_builder' => $page_builder,
);
// Merge settings.
$data = wp_parse_args( $new_data, $stored_data );
// Update settings.
update_option( 'astra_sites_settings', $data );
}
if ( ! defined( 'WP_CLI' ) ) {
wp_safe_redirect( admin_url( '/themes.php?page=astra-sites' ) );
exit;
}
}
/**
* Save Page Builder
*
* @return void
*/
public function save_page_builder_on_ajax() {
check_ajax_referer( 'astra-sites', '_ajax_nonce' );
// Only admins can save settings.
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error();
}
// Stored Settings.
$stored_data = $this->get_settings();
// New settings.
$new_data = array(
'page_builder' => ( isset( $_REQUEST['page_builder'] ) ) ? sanitize_key( $_REQUEST['page_builder'] ) : '',
);
// Merge settings.
$data = wp_parse_args( $new_data, $stored_data );
// Update settings.
update_option( 'astra_sites_settings', $data, 'no' );
$sites = $this->get_sites_by_page_builder( $new_data['page_builder'] );
wp_send_json_success( $sites );
}
/**
* Dismiss AI Promotion
*
* @return void
*/
public function dismiss_ai_promotion() {
check_ajax_referer( 'astra-sites', '_ajax_nonce' );
// Only admins can save settings.
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( __( 'You are not allowed to perform this action', 'astra-sites' ) );
}
// Stored Settings.
$stored_data = $this->get_settings();
// New settings.
$new_data = array(
'dismiss_ai_promotion' => ( isset( $_REQUEST['dismiss_ai_promotion'] ) ) ? sanitize_key( $_REQUEST['dismiss_ai_promotion'] ) : false,
);
// Merge settings.
$data = wp_parse_args( $new_data, $stored_data );
// Update settings.
update_option( 'astra_sites_settings', $data, 'no' );
wp_send_json_success( __( 'Notice Dismissed!', 'astra-sites' ) );
}
/**
* Get Page Builder Sites
*
* @since 2.0.0
*
* @param string $default_page_builder default page builder slug.
* @return array page builder sites.
*/
public function get_sites_by_page_builder( $default_page_builder = '' ) {
$sites_and_pages = Astra_Sites::get_instance()->get_all_sites();
$current_page_builder_sites = array();
if ( ! empty( $sites_and_pages ) ) {
$page_builder_keys = wp_list_pluck( $sites_and_pages, 'astra-site-page-builder' );
foreach ( $page_builder_keys as $site_id => $page_builder ) {
if ( $default_page_builder === $page_builder ) {
$current_page_builder_sites[ $site_id ] = $sites_and_pages[ $site_id ];
}
}
}
return $current_page_builder_sites;
}
/**
* Get single setting value
*
* @param string $key Setting key.
* @param mixed $defaults Setting value.
* @return mixed Stored setting value.
*/
public function get_setting( $key = '', $defaults = '' ) {
$settings = $this->get_settings();
if ( empty( $settings ) ) {
return $defaults;
}
if ( array_key_exists( $key, $settings ) ) {
return $settings[ $key ];
}
return $defaults;
}
/**
* Get Settings
*
* @return array Stored settings.
*/
public function get_settings() {
$defaults = array(
'page_builder' => 'gutenberg',
);
$stored_data = get_option( 'astra_sites_settings', $defaults );
return wp_parse_args( $stored_data, $defaults );
}
/**
* Update Settings
*
* @param array $args Arguments.
*/
public function update_settings( $args = array() ) {
$stored_data = get_option( 'astra_sites_settings', array() );
$new_data = wp_parse_args( $args, $stored_data );
update_option( 'astra_sites_settings', $new_data, 'no' );
}
/**
* View actions
*
* @since 1.0.11
*/
public function get_view_actions() {
if ( empty( $this->view_actions ) ) {
$this->view_actions = apply_filters(
'astra_sites_menu_item',
array()
);
}
return $this->view_actions;
}
/**
* Site Filters
*
* @since 2.0.0
*
* @return void
*/
public function site_filters() {
?>
<div class="wp-filter hide-if-no-js">
<div class="section-left">
<div class="search-form">
<?php
$categories = Astra_Sites_File_System::get_instance()->get_json_file_content( 'astra-sites-all-site-categories.json' );
if ( ! empty( $categories ) ) {
?>
<div id="astra-sites__category-filter" class="dropdown-check-list" tabindex="100">
<span class="astra-sites__category-filter-anchor" data-slug=""><?php esc_html_e( 'All', 'astra-sites' ); ?></span>
<ul class="astra-sites__category-filter-items">
<li class="ast-sites__filter-wrap category-active" data-slug=""><?php esc_html_e( 'All', 'astra-sites' ); ?> </li>
<?php
foreach ( $categories as $key => $value ) {
if ( 'free' !== $value['slug'] ) {
?>
<li class="ast-sites__filter-wrap" data-slug="<?php echo esc_attr( $value['slug'] ); ?>"><?php echo esc_html( $value['name'] ); ?> </li>
<?php
}
}
?>
<li class="ast-sites__filter-wrap-checkbox first-wrap">
<label>
<input id="radio-all" type="radio" name="ast-sites-radio" class="checkbox active" value="" checked /><?php esc_html_e( 'All', 'astra-sites' ); ?>
</label>
</li>
<li class="ast-sites__filter-wrap-checkbox">
<label>
<input id="radio-free" type="radio" name="ast-sites-radio" class="checkbox" value="free" /><?php esc_html_e( 'Free', 'astra-sites' ); ?>
</label>
</li>
<li class="ast-sites__filter-wrap-checkbox">
<label>
<input id="radio-agency" type="radio" name="ast-sites-radio" class="checkbox" value="agency" /><?php esc_html_e( 'Premium', 'astra-sites' ); ?>
</label>
</li>
</ul>
</div>
<?php
}
?>
<input autocomplete="off" placeholder="<?php esc_attr_e( 'Search...', 'astra-sites' ); ?>" type="search" aria-describedby="live-search-desc" id="wp-filter-search-input" class="wp-filter-search">
<span class="ast-icon-search search-icon"></span>
<div class="astra-sites-autocomplete-result"></div>
</div>
</div>
</div>
<?php
}
/**
* Get Default Page Builder
*
* @since 2.0.0
*
* @return mixed page builders or empty string.
*/
public function get_default_page_builder() {
$default_page_builder = $this->get_setting( 'page_builder' );
$page_builders = Astra_Sites::get_instance()->get_page_builders();
foreach ( $page_builders as $key => $page_builder ) {
if ( $page_builder['slug'] === $default_page_builder ) {
return $page_builder;
}
}
return '';
}
/**
* Get Page Builders
*
* @since 2.0.0
*
* @param string $slug Page Builder Slug.
* @return array page builders.
*/
public function get_page_builder_image( $slug ) {
$image = '';
switch ( $slug ) {
case 'elementor':
$image = ASTRA_SITES_URI . 'inc/assets/images/elementor.jpg';
break;
case 'beaver-builder':
$image = ASTRA_SITES_URI . 'inc/assets/images/beaver-builder.jpg';
break;
case 'gutenberg':
$image = ASTRA_SITES_URI . 'inc/assets/images/block-editor.png';
break;
case 'brizy':
$image = ASTRA_SITES_URI . 'inc/assets/images/brizy.jpg';
break;
}
return $image;
}
/**
* Page Builder List
*
* @since 1.4.0
* @return array
*/
public function get_page_builders() {
return array(
'gutenberg' => array(
'slug' => 'gutenberg',
'name' => esc_html__( 'Gutenberg', 'astra-sites' ),
'image_url' => ASTRA_SITES_URI . 'inc/assets/images/block-editor.jpg',
'title' => esc_html__( 'The default WordPress editor', 'astra-sites' ),
),
'elementor' => array(
'slug' => 'elementor',
'name' => esc_html__( 'Elementor', 'astra-sites' ),
'image_url' => ASTRA_SITES_URI . 'inc/assets/images/elementor.jpg',
),
'beaver-builder' => array(
'slug' => 'beaver-builder',
'name' => esc_html__( 'Beaver Builder', 'astra-sites' ),
'image_url' => ASTRA_SITES_URI . 'inc/assets/images/beaver-builder.jpg',
),
'brizy' => array(
'slug' => 'brizy',
'name' => esc_html__( 'Brizy', 'astra-sites' ),
'image_url' => ASTRA_SITES_URI . 'inc/assets/images/brizy.jpg',
),
);
}
/**
* Get and return page URL
*
* @param string $menu_slug Menu name.
* @since 1.0.6
* @return string page url
*/
public function get_page_url( $menu_slug ) {
$current_slug = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : 'starter-templates'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Fetching GET parameter, no nonce associated with this action.
$parent_page = 'themes.php';
if ( strpos( $parent_page, '?' ) !== false ) {
$query_var = '&page=' . $current_slug;
} else {
$query_var = '?page=' . $current_slug;
}
$parent_page_url = admin_url( $parent_page . $query_var );
$url = $parent_page_url . '&action=' . $menu_slug;
return esc_url( $url );
}
/**
* Converts a period of time in seconds into a human-readable format representing the interval.
*
* @since 2.0.0
*
* Example:
*
* echo self::interval( 90 );
* // 1 minute 30 seconds
*
* @param int $since A period of time in seconds.
* @return string An interval represented as a string.
*/
public function interval( $since ) {
// Array of time period chunks.
$chunks = array(
/* translators: 1: The number of years in an interval of time. */
array( 60 * 60 * 24 * 365, _n_noop( '%s year', '%s years', 'astra-sites' ) ),
/* translators: 1: The number of months in an interval of time. */
array( 60 * 60 * 24 * 30, _n_noop( '%s month', '%s months', 'astra-sites' ) ),
/* translators: 1: The number of weeks in an interval of time. */
array( 60 * 60 * 24 * 7, _n_noop( '%s week', '%s weeks', 'astra-sites' ) ),
/* translators: 1: The number of days in an interval of time. */
array( 60 * 60 * 24, _n_noop( '%s day', '%s days', 'astra-sites' ) ),
/* translators: 1: The number of hours in an interval of time. */
array( 60 * 60, _n_noop( '%s hour', '%s hours', 'astra-sites' ) ),
/* translators: 1: The number of minutes in an interval of time. */
array( 60, _n_noop( '%s minute', '%s minutes', 'astra-sites' ) ),
/* translators: 1: The number of seconds in an interval of time. */
array( 1, _n_noop( '%s second', '%s seconds', 'astra-sites' ) ),
);
if ( $since <= 0 ) {
return esc_html__( 'now', 'astra-sites' );
}
/**
* We only want to output two chunks of time here, eg:
* x years, xx months
* x days, xx hours
* so there's only two bits of calculation below:
*/
$j = count( $chunks );
// Step one: the first chunk.
for ( $i = 0; $i < $j; $i++ ) {
$seconds = $chunks[ $i ][0];
$name = $chunks[ $i ][1];
// Finding the biggest chunk (if the chunk fits, break).
$count = floor( $since / $seconds );
if ( $count ) {
break;
}
}
// Set output var.
$output = sprintf( translate_nooped_plural( $name, $count, 'astra-sites' ), $count );
// Step two: the second chunk.
if ( $i + 1 < $j ) {
$seconds2 = $chunks[ $i + 1 ][0];
$name2 = $chunks[ $i + 1 ][1];
$count2 = floor( ( $since - ( $seconds * $count ) ) / $seconds2 );
if ( $count2 ) {
// Add to output var.
$output .= ' ' . sprintf( translate_nooped_plural( $name2, $count2, 'astra-sites' ), $count2 );
}
}
return $output;
}
/**
* Check Cron Status
*
* Gets the current cron status by performing a test spawn. Cached for one hour when all is well.
*
* @since 2.0.0
*
* @param bool $cache Whether to use the cached result from previous calls.
* @return true|WP_Error Boolean true if the cron spawner is working as expected, or a WP_Error object if not.
*/
public static function test_cron( $cache = true ) {
global $wp_version;
if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
return new WP_Error( 'astra_sites_cron_error', esc_html__( 'ERROR! Cron schedules are disabled by setting constant DISABLE_WP_CRON to true.<br/>To start the import process please enable the cron by setting the constant to false. E.g. define( \'DISABLE_WP_CRON\', false );', 'astra-sites' ) );
}
if ( defined( 'ALTERNATE_WP_CRON' ) && ALTERNATE_WP_CRON ) {
return new WP_Error( 'astra_sites_cron_error', esc_html__( 'ERROR! Cron schedules are disabled by setting constant ALTERNATE_WP_CRON to true.<br/>To start the import process please enable the cron by setting the constant to false. E.g. define( \'ALTERNATE_WP_CRON\', false );', 'astra-sites' ) );
}
$cached_status = get_transient( 'astra-sites-cron-test-ok' );
if ( $cache && $cached_status ) {
return true;
}
$sslverify = version_compare( $wp_version, 4.0, '<' );
$doing_wp_cron = sprintf( '%.22F', microtime( true ) );
$cron_request = apply_filters(
'cron_request',
array(
'url' => site_url( 'wp-cron.php?doing_wp_cron=' . $doing_wp_cron ),
'key' => $doing_wp_cron,
'args' => array(
'timeout' => 3,
'blocking' => true,
'sslverify' => apply_filters( 'https_local_ssl_verify', $sslverify ),
),
)
);
$cron_request['args']['blocking'] = true;
$result = wp_safe_remote_post( $cron_request['url'], $cron_request['args'] );
if ( is_wp_error( $result ) ) {
return $result;
} elseif ( wp_remote_retrieve_response_code( $result ) >= 300 ) {
return new WP_Error(
'unexpected_http_response_code',
sprintf(
/* translators: 1: The HTTP response code. */
__( 'Unexpected HTTP response code: %s', 'astra-sites' ),
intval( wp_remote_retrieve_response_code( $result ) )
)
);
} else {
set_transient( 'astra-sites-cron-test-ok', 1, 3600 );
return true;
}
}
}
Astra_Sites_Page::get_instance();
}// End if.

View File

@@ -0,0 +1,149 @@
<?php
/**
* Astra Sites Update
*
* @package Astra Sites
*/
if ( ! class_exists( 'Astra_Sites_Update' ) ) :
/**
* Astra Sites Update
*
* @since 4.2.2
*/
class Astra_Sites_Update {
/**
* Instance
*
* @access private
* @var object Class object.
* @since 4.2.2
*/
private static $instance = null;
/**
* Initiator
*
* @since 4.2.2
* @return object initialized object of class.
*/
public static function set_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*
* @since 4.2.2
*/
public function __construct() {
add_action( 'astra_update_before', __CLASS__ . '::init' );
}
/**
* Update
*
* @since 4.2.2
* @return void
*/
public static function init() {
do_action( 'astra_sites_update_before' );
// Get auto saved version number.
$saved_version = get_option( 'astra-sites-auto-version', '0' );
// If equals then return.
if ( version_compare( $saved_version, ASTRA_SITES_VER, '=' ) ) {
return;
}
if ( version_compare( $saved_version, '4.2.2 ', '<' ) ) {
// Run batch process to create the json files for existing users.
delete_site_option( 'astra-sites-fresh-site' );
delete_site_option( 'astra-sites-last-export-checksums' );
$site_pages = get_option( 'astra-sites-requests' );
if ( ! empty( $site_pages ) ) {
// Delete all sites.
for ( $site_page = 1; $site_page <= $site_pages; $site_page++ ) {
delete_site_option( 'astra-sites-and-pages-page-' . $site_page );
}
}
$old_options = array(
'astra-blocks-1',
'astra-blocks-2',
'astra-blocks-3',
'astra-blocks-4',
'astra-sites-site-category',
'astra-sites-all-site-categories',
'astra-sites-page-builders',
'astra-blocks-categories',
'astra-sites-requests',
);
foreach ( $old_options as $option ) {
delete_site_option( $option );
}
delete_site_transient( 'astra-sites-import-check' );
}
if ( version_compare( $saved_version, '4.3.1', '<' ) ) {
if ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) {
delete_site_option( 'astra-sites-fresh-site' );
delete_site_option( 'astra-sites-batch-status' );
delete_site_transient( 'astra-sites-import-check' );
}
}
if ( version_compare( $saved_version, '4.4.2', '<' ) ) {
$transient_name = 'nps-survay-form-dismissed';
$expiration_time = get_option( '_transient_timeout_' . $transient_name );
$nps_transient = get_transient( $transient_name );
if ( $nps_transient && $expiration_time ) {
$transient_duration = 2 * WEEK_IN_SECONDS;
$creation_time = $expiration_time - $transient_duration;
$status = get_option( 'nps-survay-form-dismiss-status', array() );
$status['dismiss_time'] = $creation_time;
update_option( 'nps-survay-form-dismiss-status', $status );
}
}
if ( version_compare( $saved_version, '4.4.6', '<' ) ) {
$old_dismiss_varible = get_option( 'nps-survay-form-dismiss-status' );
if ( ! empty( $old_dismiss_varible ) ) {
update_option( 'nps-survey-astra-sites', $old_dismiss_varible );
delete_option( 'nps-survay-form-dismiss-status' );
}
}
// Auto update product latest version.
update_option( 'astra-sites-auto-version', ASTRA_SITES_VER, 'no' );
do_action( 'astra_sites_update_after' );
}
}
/**
* Kicking this off by calling 'set_instance()' method
*/
Astra_Sites_Update::set_instance();
endif;

View File

@@ -0,0 +1,59 @@
<?php
/**
* Astra Sites Utlis
*
* @since 1.0.0
* @package Astra Sites
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Astra_Sites_Utils' ) ) :
/**
* Astra_Sites_Utils
*/
class Astra_Sites_Utils {
/**
* Third party cache plugin clear cache.
*
* @since 4.0.0
* @return void
*/
public static function third_party_cache_plugins_clear_cache() {
// Clear LiteSpeed cache.
if ( class_exists( '\LiteSpeed\Purge' ) ) {
\LiteSpeed\Purge::purge_all();
}
// Clear cloudways cache.
self::clear_cloudways_cache();
}
/**
* This function helps to purge all cache in clodways envirnoment.
* In presence of Breeze plugin (https://wordpress.org/plugins/breeze/)
*
* @since 4.0.0
* @return void
*/
public static function clear_cloudways_cache() {
if ( ! class_exists( 'Breeze_Configuration' ) || ! class_exists( 'Breeze_CloudFlare_Helper' ) || ! class_exists( 'Breeze_Admin' ) ) {
return;
}
// clear varnish cache.
$admin = new Breeze_Admin();
$admin->breeze_clear_varnish();
// clear static cache.
Breeze_Configuration::breeze_clean_cache();
Breeze_CloudFlare_Helper::reset_all_cache();
}
}
endif;

View File

@@ -0,0 +1,328 @@
<?php
/**
* Astra Sites White Label
*
* @package Astra Sites
* @since 1.0.12
*/
if ( ! class_exists( 'Astra_Sites_White_Label' ) ) :
/**
* Astra_Sites_White_Label
*
* @since 1.0.12
*/
class Astra_Sites_White_Label {
/**
* Instance
*
* @since 1.0.12
*
* @var object Class Object.
* @access private
*/
private static $instance;
/**
* Member Variable
*
* @since 1.0.12
*
* @var array branding
* @access private
*/
private static $branding;
/**
* Settings
*
* @since 1.2.11
*
* @var array settings
*
* @access private
*/
private $settings;
/**
* Initiator
*
* @since 1.0.12
*
* @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.12
*/
public function __construct() {
add_filter( 'all_plugins', array( $this, 'plugins_page' ) );
add_filter( 'astra_addon_branding_options', __CLASS__ . '::settings' );
add_action( 'astra_pro_white_label_add_form', __CLASS__ . '::add_white_label_form' );
add_filter( 'astra_sites_menu_page_title', array( $this, 'get_white_label_name' ) );
add_filter( 'astra_sites_page_title', array( $this, 'get_white_label_name' ) );
// Update Astra's admin top level menu position.
add_filter( 'astra_menu_priority', array( $this, 'update_admin_menu_position' ) );
// Display the link with the plugin meta.
if ( is_admin() ) {
add_filter( 'plugin_row_meta', array( $this, 'plugin_links' ), 10, 4 );
}
add_filter( 'gutenberg_templates_localize_vars', array( $this, 'add_white_label_name' ) );
add_filter( 'ast_block_templates_white_label', array( $this, 'is_white_labeled' ) );
add_filter( 'ast_block_templates_white_label_name', array( $this, 'get_white_label' ) );
}
/**
* Update Astra's menu priority to show after Dashboard menu.
*
* @param int $menu_priority top level menu priority.
* @since 3.1.22
*/
public function update_admin_menu_position( $menu_priority ) {
return 2.1;
}
/**
* Add White Label data
*
* @param array $args White label.
* @since 2.6.0
*/
public function add_white_label_name( $args = array() ) {
$args['white_label_name'] = $this->get_white_label();
return $args;
}
/**
* White labels the plugins page.
*
* @since 1.0.12
*
* @param array $plugins Plugins Array.
* @return array
*/
public function plugins_page( $plugins ) {
if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
return $plugins;
}
if ( ! isset( $plugins[ ASTRA_SITES_BASE ] ) ) {
return $plugins;
}
// Set White Labels.
$name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
$description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' );
$author = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author' );
$author_uri = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'author_url' );
if ( ! empty( $name ) ) {
$plugins[ ASTRA_SITES_BASE ]['Name'] = $name;
// Remove Plugin URI if Agency White Label name is set.
$plugins[ ASTRA_SITES_BASE ]['PluginURI'] = '';
}
if ( ! empty( $description ) ) {
$plugins[ ASTRA_SITES_BASE ]['Description'] = $description;
}
if ( ! empty( $author ) ) {
$plugins[ ASTRA_SITES_BASE ]['Author'] = $author;
}
if ( ! empty( $author_uri ) ) {
$plugins[ ASTRA_SITES_BASE ]['AuthorURI'] = $author_uri;
}
return $plugins;
}
/**
* Get value of single key from option array.
*
* @since 2.0.0.
* @param string $type Option type.
* @param string $key Option key.
* @param string $default Default value if key not found.
* @return mixed Return stored option value.
*/
public static function get_option( $type = '', $key = '', $default = null ) {
if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_white_label' ) ) {
return $default;
}
$value = Astra_Ext_White_Label_Markup::get_white_label( $type, $key );
if ( ! empty( $value ) ) {
return $value;
}
return $default;
}
/**
* Remove a "view details" link from the plugin list table
*
* @since 1.0.12
*
* @param array $plugin_meta List of links.
* @param string $plugin_file Relative path to the main plugin file from the plugins directory.
* @param array $plugin_data Data from the plugin headers.
* @return array
*/
public function plugin_links( $plugin_meta, $plugin_file, $plugin_data ) {
if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
return $plugin_meta;
}
// Set White Labels.
if ( ASTRA_SITES_BASE === $plugin_file ) {
$name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
$description = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'description' );
// Remove Plugin URI if Agency White Label name is set.
if ( ! empty( $name ) ) {
unset( $plugin_meta[2] );
}
}
return $plugin_meta;
}
/**
* Add White Label setting's
*
* @since 1.0.12
*
* @param array $settings White label setting.
* @return array
*/
public static function settings( $settings = array() ) {
$settings['astra-sites'] = array(
'name' => '',
'description' => '',
);
return $settings;
}
/**
* Add White Label form
*
* @since 1.0.12
*
* @param array $settings White label setting.
* @return void
*/
public static function add_white_label_form( $settings = array() ) {
/* translators: %1$s product name */
$plugin_name = sprintf( __( '%1$s Branding', 'astra-sites' ), ASTRA_SITES_NAME );
require_once ASTRA_SITES_DIR . 'inc/includes/white-label.php';
}
/**
* Page Title
*
* @since 1.0.12
*
* @param string $title Page Title.
* @return string Filtered Page Title.
*/
public function get_white_label_name( $title = '' ) {
if ( is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
$astra_sites_name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
if ( ! empty( $astra_sites_name ) ) {
return Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
}
}
return ASTRA_SITES_NAME;
}
/**
* White Label Link
*
* @since 2.0.0
*
* @param string $link Default link.
* @return string Filtered Page Title.
*/
public function get_white_label_link( $link = '' ) {
if ( is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
$white_label_link = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-agency', 'licence' );
if ( ! empty( $white_label_link ) ) {
return $white_label_link;
}
}
return $link;
}
/**
* Is Astra sites White labeled
*
* @since 1.2.13
*
* @return string
*/
public function is_white_labeled() {
$white_label = $this->get_white_label();
if ( empty( $white_label ) ) {
return false;
}
return true;
}
/**
* Get white label name
*
* @since 2.6.0
*
* @return string
*/
public function get_white_label() {
if ( ! is_callable( 'Astra_Ext_White_Label_Markup::get_whitelabel_string' ) ) {
return '';
}
$name = Astra_Ext_White_Label_Markup::get_whitelabel_string( 'astra-sites', 'name' );
if ( ! empty( $name ) ) {
return $name;
}
return '';
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Astra_Sites_White_Label::get_instance();
endif;

View File

@@ -0,0 +1,812 @@
<?php
/**
* Astra Sites WP CLI
*
* 1. Run `wp astra-sites list` List of all astra sites.
* 2. Run `wp astra-sites import <id>` Import site.
*
* @package Astra Sites
* @since 1.4.0
*/
use STImporter\Importer\WXR_Importer\ST_WXR_Importer;
use STImporter\Importer\Batch\ST_Batch_Processing;
use AiBuilder\Inc\Traits\Helper;
if ( class_exists( 'WP_CLI_Command' ) && ! class_exists( 'Astra_Sites_WP_CLI' ) ) :
/**
* WP-Cli commands to manage Astra Starter Sites.
*
* @since 1.4.0
*/
class Astra_Sites_WP_CLI extends WP_CLI_Command {
/**
* Site Data
*
* @var array
*/
protected $current_site_data;
/**
* Process Batch
*
* ## EXAMPLES
*
* $ wp astra-sites batch
* Processing Site: http://example.com/
* Batch Process Started..
* ..
*
* @since 2.1.0
* @param array $args Arguments.
* @param array $assoc_args Associated Arguments.
*/
public function batch( $args, $assoc_args ) {
WP_CLI::line( 'Processing Site: ' . site_url() );
ST_Batch_Processing::get_instance()->start_process();
}
/**
* Generates the list of all Astra Sites.
*
* ## OPTIONS
*
* [--per-page=<number>]
* : No of sites to show in the list. Default its showing 10 sites.
*
* [--search=<text>]
* : Show the sites from particular search term.
*
* [--category=<text>]
* : Show the site from the specific category.
*
* [--page-builder=<text>]
* : List the sites from the particular page builder.
*
* [--type=<text>]
* : List the sites from the particular site type.
*
* ## EXAMPLES
*
* # List all the sites.
* $ wp astra-sites list
* +-------+-------------------+-----------------------------------------+---------+----------------+--------------+
* | id | title | url | type | categories | page-builder |
* +-------+-------------------+-----------------------------------------+---------+----------------+--------------+
* | 34184 | Nutritionist | //websitedemos.net/nutritionist-01 | free | Business, Free | Elementor |
* | 34055 | Law Firm | //websitedemos.net/law-firm-03 | premium | Business | Elementor |
* +-------+-------------------+-----------------------------------------+---------+----------------+--------------+
*
* @since 1.4.0
* @param array $args Arguments.
* @param array $assoc_args Associated Arguments.
*
* @alias list
*/
public function list_sites( $args, $assoc_args ) {
$per_page = isset( $assoc_args['per-page'] ) ? $assoc_args['per-page'] : 10;
$search = isset( $assoc_args['search'] ) ? $assoc_args['search'] : '';
$rest_args = array(
'_fields' => 'id,title,slug,astra-sites-site-category,astra-site-page-builder,astra-site-type,astra-site-url',
'per_page' => $per_page,
);
if ( ! empty( $search ) ) {
$rest_args['search'] = $search;
}
$list = (array) $this->get_sites( 'astra-sites', $rest_args, true, $assoc_args );
// Modify the output.
foreach ( $list as $key => $item ) {
$list[ $key ]['categories'] = implode( ', ', $list[ $key ]['categories'] );
$list[ $key ]['page-builder'] = implode( ', ', $list[ $key ]['page_builders'] );
}
if ( ! empty( $list ) ) {
$display_fields = array(
'id',
'title',
'url',
'type',
'categories',
'page-builder',
);
$formatter = $this->get_formatter( $assoc_args, $display_fields );
$formatter->display_items( $list );
} else {
WP_CLI::error( __( 'No sites found! Try another query.', 'astra-sites' ) );
}
}
/**
* Import the site by site ID.
*
* ## OPTIONS
*
* <id>
* : Site id of the import site.
*
* [--reset]
* : Reset the recently imported site data. Including post, pages, customizer settings, widgets etc.
*
* [--yes]
* : Forcefully import the site without asking any prompt message.
*
*
* ## EXAMPLES
*
* # Import demo site.
* $ wp astra-sites import 34184 --reset --yes --license_key={{YOUR_KEY}}
* Activating Plugins..
* Reseting Posts..
* ..
*
* @since 1.4.0
* @param array $args Arguments.
* @param array $assoc_args Associated Arguments.
*/
public function import( $args, $assoc_args ) {
// Force import.
$yes = isset( $assoc_args['yes'] ) ? true : false;
if ( ! $yes ) {
WP_CLI::confirm( __( 'Are you sure you want to import the site?', 'astra-sites' ) );
}
// Valid site ID?
$id = isset( $args[0] ) ? absint( $args[0] ) : 0;
if ( ! $id ) {
WP_CLI::error( __( 'Invalid Site ID,', 'astra-sites' ) );
}
$reset = isset( $assoc_args['reset'] ) ? true : false;
$site_url = get_site_url();
$demo_data = $this->get_site_data( $id );
// Invalid Site ID.
if ( is_wp_error( $demo_data ) ) {
/* Translators: %s is the error message. */
WP_CLI::error( sprintf( __( 'Site Import failed due to error: %s', 'astra-sites' ), $demo_data->get_error_message() ) );
}
// License Status.
$license_status = false;
if ( is_callable( 'BSF_License_Manager::bsf_is_active_license' ) ) {
$license_status = BSF_License_Manager::bsf_is_active_license( 'astra-pro-sites' );
}
if ( 'free' !== $demo_data['site-type'] && 'upgrade' === $demo_data['license-status'] && ! $license_status ) {
if ( ! defined( 'ASTRA_PRO_SITES_NAME' ) ) {
WP_CLI::line( __( 'This is Premium site. Please activate the "Starter Templates" license!', 'astra-sites' ) );
WP_CLI::line( __( 'Use `wp plugin deactivate astra-sites` and then `wp plugin activate astra-pro-sites`', 'astra-sites' ) );
}
/* translators: %s is the activate plugin license link. */
WP_CLI::error( __( 'Use CLI command `wp brainstormforce license activate astra-pro-sites {YOUR_LICENSE_KEY}`', 'astra-sites' ) );
}
/**
* Check File System permissions.
*/
Helper::filesystem_permission();
/**
* Install & Activate Required Plugins.
*/
if ( isset( $demo_data['required-plugins'] ) ) {
$plugins = (array) $demo_data['required-plugins'];
if ( ! empty( $plugins ) ) {
$plugin_status = Helper::required_plugins( $plugins, $demo_data['astra-site-options-data'], $demo_data['astra-enabled-extensions'] );
// Install Plugins.
if ( ! empty( $plugin_status['required_plugins']['notinstalled'] ) ) {
WP_CLI::line( __( 'Installing Plugins..', 'astra-sites' ) );
foreach ( $plugin_status['required_plugins']['notinstalled'] as $key => $plugin ) {
if ( isset( $plugin['slug'] ) ) {
// Install plugin.
WP_CLI::runcommand( 'plugin install ' . $plugin['slug'] );
// Activate plugin.
WP_CLI::runcommand( 'plugin activate ' . $plugin['slug'] );
}
}
}
// Activate Plugins.
if ( ! empty( $plugin_status['required_plugins']['inactive'] ) ) {
WP_CLI::line( __( 'Activating Plugins..', 'astra-sites' ) );
foreach ( $plugin_status['required_plugins']['inactive'] as $key => $plugin ) {
if ( isset( $plugin['init'] ) ) {
Helper::required_plugin_activate( $plugin['init'], $demo_data['astra-site-options-data'], $demo_data['astra-enabled-extensions'] );
}
}
}
}
}
/**
* Backup Customizer Settings
*/
Helper::backup_settings();
/**
* Reset Site Data
*/
if ( $reset ) {
WP_CLI::runcommand( 'astra-sites reset --yes' );
}
/**
* Import Flows & Steps for CartFlows.
*/
if ( isset( $demo_data['astra-site-cartflows-path'] ) && ! empty( $demo_data['astra-site-cartflows-path'] ) ) {
Astra_Sites_Importer::get_instance()->import_cartflows( $demo_data['astra-site-cartflows-path'] );
}
/**
* Import WP Forms.
*/
if ( isset( $demo_data['astra-site-wpforms-path'] ) && ! empty( $demo_data['astra-site-wpforms-path'] ) ) {
Astra_Sites_Importer::get_instance()->import_wpforms( $demo_data['astra-site-wpforms-path'] );
}
/**
* Import Customizer Settings.
*/
WP_CLI::runcommand( 'astra-sites import_customizer_settings ' . $id );
/**
* Import Content from XML/WXR.
*/
if ( isset( $demo_data['astra-site-wxr-path'] ) && ! empty( $demo_data['astra-site-wxr-path'] ) ) {
WP_CLI::runcommand( 'astra-sites import_wxr ' . $demo_data['astra-site-wxr-path'] );
}
/**
* Import Site Options.
*/
if ( isset( $demo_data['astra-site-options-data'] ) && ! empty( $demo_data['astra-site-options-data'] ) ) {
WP_CLI::line( __( 'Importing Site Options..', 'astra-sites' ) );
Helper::import_options( $demo_data['astra-site-options-data'] );
}
/**
* Import Widgets.
*/
if ( isset( $demo_data['astra-site-widgets-data'] ) && ! empty( $demo_data['astra-site-widgets-data'] ) ) {
WP_CLI::line( __( 'Importing Widgets..', 'astra-sites' ) );
Helper::import_widgets( $demo_data['astra-site-widgets-data'] );
}
/**
* Import End.
*/
WP_CLI::runcommand( 'astra-sites import_end' );
/* translators: %s is the site URL. */
WP_CLI::line( sprintf( __( "Site Imported Successfully!\nVisit: %s", 'astra-sites' ), $site_url ) );
}
/**
* Import End
*
* @since 1.4.3
* @return void
*/
public function import_end() {
Helper::import_end();
}
/**
* Import form XML.
*
* ## OPTIONS
*
* <url>
* : XML/WXR file URL.
*
* ## EXAMPLES
*
* $ wp astra-sites import_wxr <url>
*
* @since 1.4.3
* @param array $args Arguments.
* @param array $assoc_args Associated Arguments.
* @return void.
*/
public function import_wxr( $args = array(), $assoc_args = array() ) {
// Valid site ID?
$url = isset( $args[0] ) ? esc_url_raw( $args[0] ) : '';
if ( empty( $url ) ) {
WP_CLI::error( esc_html__( 'Invalid XML URL.', 'astra-sites' ) );
}
// Download XML file.
/* translators: %s is the XML file URL. */
WP_CLI::line( sprintf( esc_html__( 'Downloading %s', 'astra-sites' ), $url ) );
$xml_path = ST_WXR_Importer::download_file( $url );
if ( $xml_path['success'] && isset( $xml_path['data']['file'] ) ) {
WP_CLI::line( esc_html__( 'Importing WXR..', 'astra-sites' ) );
ST_WXR_Importer::get_instance()->sse_import( $xml_path['data']['file'] );
} else {
/* translators: %s is error message. */
WP_CLI::line( printf( esc_html__( 'WXR file Download Failed. Error %s', 'astra-sites' ), esc_html( $xml_path['data'] ) ) );
}
}
/**
* Reset
*
* Delete all pages, post, custom post type, customizer settings and site options.
*
* ## OPTIONS
*
* [--yes]
* : Reset previously imported site data without asking the prompt message.
*
* ## EXAMPLES
*
* $ wp astra-sites reset
*
* @since 1.4.0
* @param array $args Arguments.
* @param array $assoc_args Associated Arguments.
* @return void.
*/
public function reset( $args = array(), $assoc_args = array() ) {
$yes = isset( $assoc_args['yes'] ) ? true : false;
if ( ! $yes ) {
WP_CLI::confirm( __( 'Are you sure you want to delete imported site data?', 'astra-sites' ) );
}
// Get tracked data.
$reset_data = Astra_Sites::get_instance()->get_reset_data();
// Delete tracked posts.
if ( isset( $reset_data['reset_posts'] ) && ! empty( $reset_data['reset_posts'] ) ) {
WP_CLI::line( __( 'Reseting Posts..', 'astra-sites' ) );
foreach ( $reset_data['reset_posts'] as $key => $post_id ) {
Astra_Sites_Importer::get_instance()->delete_imported_posts( $post_id );
}
}
// Delete tracked terms.
if ( isset( $reset_data['reset_terms'] ) && ! empty( $reset_data['reset_terms'] ) ) {
WP_CLI::line( __( 'Reseting Terms..', 'astra-sites' ) );
foreach ( $reset_data['reset_terms'] as $key => $post_id ) {
Astra_Sites_Importer::get_instance()->delete_imported_terms( $post_id );
}
}
// Delete tracked WP forms.
if ( isset( $reset_data['reset_wp_forms'] ) && ! empty( $reset_data['reset_wp_forms'] ) ) {
WP_CLI::line( __( 'Resting WP Forms...', 'astra-sites' ) );
foreach ( $reset_data['reset_wp_forms'] as $key => $post_id ) {
Astra_Sites_Importer::get_instance()->delete_imported_terms( $post_id );
}
}
// Delete Customizer Data.
Helper::reset_customizer_data();
// Delete Site Options.
Helper::reset_site_options();
// Delete Widgets Data.
Helper::reset_widgets_data();
}
/**
* Import Customizer Settings
*
* ## OPTIONS
*
* <id>
* : Site ID.
*
* ## EXAMPLES
*
* $ wp astra-sites import_customizer_settings <id>
*
* @since 1.4.0
*
* @param array $args Arguments.
* @param array $assoc_args Associated Arguments.
* @return void
*/
public function import_customizer_settings( $args, $assoc_args ) {
// Valid site ID?
$id = isset( $args[0] ) ? absint( $args[0] ) : 0;
if ( ! $id ) {
WP_CLI::error( __( 'Invalid Site ID,', 'astra-sites' ) );
}
$demo_data = $this->get_site_data( $id );
WP_CLI::line( __( 'Importing customizer settings..', 'astra-sites' ) );
Helper::import_customizer_settings( $demo_data['astra-site-customizer-data'] );
}
/**
* Page Builders
*
* ### OPTIONS
*
* [<list>]
* : List all page builders.
*
* OR
*
* [<set>]
* : Set the current page builder with given page builder slug.
*
* [<slug>]
* : Page builder slug.
*
* ### EXAMPLES
*
* # List all the page builders.
* λ wp astra-sites page_builder list
* +----------------+----------------+
* | slug | name |
* +----------------+----------------+
* | gutenberg | Gutenberg |
* | elementor | Elementor |
* | beaver-builder | Beaver Builder |
* | brizy | Brizy |
* +----------------+----------------+
*
* # Set `Elementor` as default page builder.
* λ wp astra-sites page_builder set elementor
* "Elementor" is set as default page builder.
*
* # Set `Beaver Builder` as default page builder.
* λ wp astra-sites page_builder set beaver-builder
* "Beaver Builder" is set as default page builder.
*
* @since 1.4.0
* @param array $args Arguments.
* @param array $assoc_args Associated Arguments.
*/
public function page_builder( $args, $assoc_args ) {
$action = isset( $args[0] ) ? $args[0] : '';
if ( empty( $action ) ) {
WP_CLI::error( __( 'Please add valid parameter.', 'astra-sites' ) );
}
$page_builders = Astra_Sites_Page::get_instance()->get_page_builders();
if ( 'list' === $action ) {
$display_fields = array(
'slug',
'name',
);
$formatter = $this->get_formatter( $assoc_args, $display_fields );
$formatter->display_items( $page_builders );
$default_page_builder = isset( $page_builders[ Astra_Sites_Page::get_instance()->get_setting( 'page_builder' ) ] ) ? $page_builders[ Astra_Sites_Page::get_instance()->get_setting( 'page_builder' ) ]['name'] : '';
if ( ! empty( $default_page_builder ) ) {
/* translators: %s is the current page builder name. */
WP_CLI::line( sprintf( __( 'Default page builder is "%s".', 'astra-sites' ), $default_page_builder ) );
}
} elseif ( 'set' === $action ) {
$page_builder_slugs = array_keys( $page_builders );
$page_builder_slug = isset( $args[1] ) ? $args[1] : '';
if ( in_array( $page_builder_slug, $page_builder_slugs, true ) ) {
Astra_Sites_Page::get_instance()->save_page_builder_on_submit( $page_builder_slug );
/* translators: %s is the page builder name. */
WP_CLI::line( sprintf( __( '"%s" is set as default page builder.', 'astra-sites' ), $page_builders[ $page_builder_slug ]['name'] ) );
} else {
WP_CLI::error( __( "Invalid page builder slug. \nCheck all page builder slugs with command `wp astra-sites page_builder list`", 'astra-sites' ) );
}
} else {
WP_CLI::error( __( "Invalid parameter! \nPlease use `list` or `set` parameter.", 'astra-sites' ) );
}
}
/**
* Get Formatter
*
* @since 1.4.0
* @param array $assoc_args Associate arguments.
* @param string $fields Fields.
* @param string $prefix Prefix.
* @return object Class object.
*/
protected function get_formatter( &$assoc_args, $fields = '', $prefix = '' ) {
return new \WP_CLI\Formatter( $assoc_args, $fields, $prefix );
}
/**
* Get Site Data by Site ID
*
* @since 1.4.0
*
* @param int $id Site ID.
* @return array
*/
private function get_site_data( $id ) {
if ( empty( $this->current_site_data ) ) {
// @todo Use Astra_Sites::get_instance()->api_request() instead of below function.
$this->current_site_data = Astra_Sites_Importer::get_instance()->get_single_demo( $id );
Astra_Sites_File_System::get_instance()->update_demo_data( $this->current_site_data );
}
return $this->current_site_data;
}
/**
* Get Sites
*
* @since 1.4.0
*
* @param string $post_slug Post slug.
* @param array $args Post query arguments.
* @param boolean $force Force import.
* @param array $assoc_args Associate arguments.
* @return array
*/
private function get_sites( $post_slug = '', $args = array(), $force = false, $assoc_args = array() ) {
// Add page builders.
$page_builder = isset( $assoc_args['page-builder'] ) ? $assoc_args['page-builder'] : Astra_Sites_Page::get_instance()->get_setting( 'page_builder' );
$response = $this->get_term_ids( 'astra-site-page-builder', $page_builder, $args );
$args = $response['args'];
$page_builders = $response['terms'];
if ( empty( $page_builders['data'] ) ) {
WP_CLI::error( __( 'This page builder plugin is not installed. Please try a different page builder.', 'astra-sites' ) );
}
// Add type.
$type = isset( $assoc_args['type'] ) ? $assoc_args['type'] : '';
$response = $this->get_term_ids( 'astra-sites-type', $type, $args );
$args = $response['args'];
$types = $response['terms'];
if ( empty( $types['data'] ) ) {
WP_CLI::error( __( 'This site type does not exist. Please try a different site type.', 'astra-sites' ) );
}
// Add categories.
$category = isset( $assoc_args['category'] ) ? $assoc_args['category'] : '';
$response = $this->get_term_ids( 'astra-sites-site-category', $category, $args );
$args = $response['args'];
$categories = $response['terms'];
if ( empty( $categories['data'] ) ) {
WP_CLI::error( __( 'This site category does not exist. Please try a different site category.', 'astra-sites' ) );
}
// Site list.
$sites = (array) $this->get_posts( 'astra-sites', $args, $force );
$list = array();
if ( $sites['success'] ) {
foreach ( $sites['data'] as $key => $site ) {
$single_site = array(
'id' => $site['id'],
'slug' => $site['slug'],
'title' => $site['title']['rendered'],
'url' => $site['astra-site-url'],
'type' => ( 'premium' === $site['astra-site-type'] ) ? 'Premium' : ucwords( $site['astra-site-type'] ),
'categories' => array(),
'page_builders' => array(),
);
if ( isset( $site['astra-sites-site-category'] ) && ! empty( $categories['data'] ) ) {
foreach ( $site['astra-sites-site-category'] as $category_key => $category_id ) {
if ( isset( $categories['data'][ $category_id ] ) ) {
$single_site['categories'][ $category_id ] = $categories['data'][ $category_id ];
}
}
}
if ( isset( $site['astra-site-page-builder'] ) && ! empty( $page_builders['data'] ) ) {
foreach ( $site['astra-site-page-builder'] as $page_builder_key => $page_builder_id ) {
if ( isset( $page_builders['data'][ $page_builder_id ] ) ) {
$single_site['page_builders'][ $page_builder_id ] = $page_builders['data'][ $page_builder_id ];
}
}
}
$list[] = $single_site;
}
}
return $list;
}
/**
* Get Term IDs
*
* @since 1.4.0
*
* @param string $term_slug Term slug.
* @param string $search_term Search term.
* @param array $args Term query arguments.
* @return array Term response.
*/
private function get_term_ids( $term_slug = '', $search_term = '', $args = array() ) {
$term_args = array();
if ( ! empty( $search_term ) ) {
$term_args = array(
'search' => $search_term,
);
}
$term_response = (array) $this->get_terms( $term_slug, $term_args, true );
if ( ! empty( $search_term ) ) {
if ( ! empty( $term_response ) && is_array( $term_response['data'] ) ) {
$args[ $term_slug ] = implode( ',', array_keys( $term_response['data'] ) );
}
}
return array(
'args' => $args,
'terms' => $term_response,
);
}
/**
* Get Terms
*
* @since 1.0.0
*
* @param array $term_slug Term Slug.
* @param array $args For selecting the demos (Search terms, pagination etc).
* @param string $force Force import.
* @return $array Term response.
*/
private function get_terms( $term_slug = '', $args = array(), $force = false ) {
$defaults = array(
'_fields' => 'id,name,slug,count',
);
$args = wp_parse_args( (array) $args, $defaults );
$success = false;
$terms_data = get_transient( 'astra-sites-term-' . $term_slug );
if ( empty( $terms_data ) || $force ) {
$url = add_query_arg( $args, Astra_Sites::get_instance()->get_api_url() . $term_slug );
$api_args = array(
'timeout' => 60,
);
$response = wp_safe_remote_get( $url, $api_args );
if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) {
$request_term_data = json_decode( wp_remote_retrieve_body( $response ), true );
if ( ! isset( $request_term_data['code'] ) ) {
$success = true;
$new_terms_data = array();
foreach ( $request_term_data as $key => $request_term ) {
$new_terms_data[ $request_term['id'] ] = $request_term['name'];
}
if ( set_transient( 'astra-sites-term-' . $term_slug, $new_terms_data, WEEK_IN_SECONDS ) ) {
return array(
'success' => $success,
'data' => $new_terms_data,
);
}
}
}
}
return array(
'success' => $success,
'data' => $terms_data,
);
}
/**
* Get Posts
*
* @since 1.4.0
*
* @param string $post_slug Post slug.
* @param array $args Post query arguments.
* @param boolean $force Force import.
* @return array
*/
private function get_posts( $post_slug = '', $args = array(), $force = false ) {
$args = wp_parse_args( (array) $args, array() );
$all_posts = get_transient( 'astra-sites-post-' . $post_slug );
if ( empty( $all_posts ) || $force ) {
$url = add_query_arg( $args, Astra_Sites::get_instance()->get_api_url() . $post_slug );
$api_args = array(
'timeout' => 60,
);
$success = false;
$response = wp_safe_remote_get( $url, $api_args );
if ( ! is_wp_error( $response ) || wp_remote_retrieve_response_code( $response ) === 200 ) {
$all_posts = json_decode( wp_remote_retrieve_body( $response ), true );
if ( ! isset( $all_posts['code'] ) ) {
$success = true;
set_transient( 'astra-sites-post-' . $post_slug, $all_posts, WEEK_IN_SECONDS );
}
}
} else {
$success = true;
}
return array(
'success' => $success,
'data' => $all_posts,
);
}
/**
* Sync Library.
*
* Sync the library and create the .json files.
*
* Use: `wp astra-sites sync`
*
* @since 2.0.0
* @param array $args Arguments.
* @param array $assoc_args Associated Arguments.
* @return void.
*/
public function sync( $args = array(), $assoc_args = array() ) {
Astra_Sites_Batch_Processing::get_instance()->process_batch();
}
/**
* Init.
*/
public static function init() {
add_filter( 'wp_check_filetype_and_ext', array( 'Astra_Sites_WP_CLI', 'real_mime_types' ), 10, 5 );
}
/**
* Different MIME type of different PHP version
*
* Filters the "real" file type of the given file.
*
* @since 1.2.9
*
* @param array $defaults File data array containing 'ext', 'type', and
* 'proper_filename' keys.
* @param string $file Full path to the file.
* @param string $filename The name of the file (may differ from $file due to
* $file being in a tmp directory).
* @param array<string, string> $mimes Key is the file extension with value as the mime type.
* @param string $real_mime Real MIME type of the uploaded file.
*/
public static function real_mime_types( $defaults, $file, $filename, $mimes, $real_mime ) {
return ST_WXR_Importer::get_instance()->real_mime_types_5_1_0( $defaults, $file, $filename, $mimes, $real_mime );
}
}
/**
* Add Command
*/
WP_CLI::add_command( 'starter-templates', 'Astra_Sites_WP_CLI' );
WP_CLI::add_command( 'astra-sites', 'Astra_Sites_WP_CLI' );
Astra_Sites_WP_CLI::init();
endif;

View File

@@ -0,0 +1,315 @@
<?php
/**
* Astra Sites Compatibility for 'Astra Pro'
*
* @see https://wordpress.org/plugins/astra-pro/
*
* @package Astra Sites
* @since 1.0.0
*/
use STImporter\Importer\Helpers\ST_Image_Importer;
if ( ! class_exists( 'Astra_Sites_Compatibility_Astra_Pro' ) ) :
/**
* Astra_Sites_Compatibility_Astra_Pro
*
* @since 1.0.0
*/
class Astra_Sites_Compatibility_Astra_Pro {
/**
* Instance
*
* @access private
* @var object Class object.
* @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_action( 'astra_sites_after_plugin_activation', array( $this, 'astra_pro' ), 10, 2 );
add_action( 'astra_sites_import_start', array( $this, 'import_enabled_extension' ), 10, 2 );
add_action( 'astra_sites_import_complete', array( $this, 'clear_cache' ) );
}
/**
* Import
*
* @since 1.1.6
* @return void
*/
public function import() {
if ( defined( 'WP_CLI' ) ) {
WP_CLI::line( 'Processing "Astra Pro" Batch Import' );
}
Astra_Sites_Importer_Log::add( '---- Processing Mapping - for Astra Pro ----' );
self::start_post_mapping();
}
/**
* Update Site Origin Active Widgets
*
* @since 1.0.0
*
* @param string $plugin_init Plugin init file.
* @param array $data Data.
* @return void
*/
public function astra_pro( $plugin_init = '', $data = array() ) {
if ( 'astra-addon/astra-addon.php' === $plugin_init && ! empty( $data ) ) {
if ( is_array( $data ) ) {
$data = json_decode( wp_json_encode( $data ), true );
}
if ( isset( $data['enabled_extensions'] ) ) {
$extensions = $data['enabled_extensions'];
if ( ! empty( $extensions ) ) {
if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_enabled_extensions', $extensions );
}
}
}
}
}
/**
* Import custom 404 section.
*
* @since 1.0.0
* @param array $demo_data Site all data render from API call.
* @param array $demo_api_uri Demo URL.
*/
public function import_custom_404( $demo_data = array(), $demo_api_uri = '' ) {
if ( isset( $demo_data['astra-custom-404'] ) ) {
if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
$options_404 = $demo_data['astra-custom-404'];
Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_custom_404', $options_404 );
}
}
}
/**
* Import settings enabled Astra extensions from the demo.
*
* @since 1.0.0
* @param array $demo_data Site all data render from API call.
* @param array $demo_api_uri Demo URL.
*/
public function import_enabled_extension( $demo_data = array(), $demo_api_uri = '' ) {
if ( isset( $demo_data['astra-enabled-extensions'] ) ) {
if ( is_callable( 'Astra_Admin_Helper::update_admin_settings_option' ) ) {
Astra_Admin_Helper::update_admin_settings_option( '_astra_ext_enabled_extensions', $demo_data['astra-enabled-extensions'] );
}
}
}
/**
* Start post meta mapping of Astra Addon
*
* @since 1.1.6
*
* @return null If there is no import option data found.
*/
public static function start_post_mapping() {
$demo_data = Astra_Sites_File_System::get_instance()->get_demo_content();
if ( ! isset( $demo_data['astra-post-data-mapping'] ) ) {
return;
}
$post_type = 'astra-advanced-hook';
$posts = ( isset( $demo_data['astra-post-data-mapping'][ $post_type ] ) ) ? $demo_data['astra-post-data-mapping'][ $post_type ] : array();
if ( ! empty( $posts ) ) {
foreach ( $posts as $key => $post ) {
$page = Astra_Site_Options_Import::instance()->get_page_by_title( $post['post_title'], $post_type );
if ( is_object( $page ) ) {
if ( defined( 'WP_CLI' ) ) {
WP_CLI::line( 'Setting Location Rules for ' . $post['post_title'] );
}
self::update_location_rules( $page->ID, 'ast-advanced-hook-location', $post['mapping']['ast-advanced-hook-location'] );
}
}
}
$post_type = 'astra_adv_header';
$posts = ( isset( $demo_data['astra-post-data-mapping'][ $post_type ] ) ) ? $demo_data['astra-post-data-mapping'][ $post_type ] : array();
if ( ! empty( $posts ) ) {
foreach ( $posts as $key => $post ) {
$page = Astra_Site_Options_Import::instance()->get_page_by_title( $post['post_title'], $post_type );
if ( is_object( $page ) ) {
if ( defined( 'WP_CLI' ) ) {
WP_CLI::line( 'Setting Location Rules for ' . $post['post_title'] );
}
self::update_location_rules( $page->ID, 'ast-advanced-headers-location', $post['mapping']['ast-advanced-headers-location'] );
self::update_location_rules( $page->ID, 'ast-advanced-headers-exclusion', $post['mapping']['ast-advanced-headers-exclusion'] );
self::update_header_mapping( $page->ID, 'ast-advanced-headers-design', $post['mapping']['ast-advanced-headers-design'] );
}
}
}
}
/**
* Update Header Mapping Data
*
* @since 1.1.6
*
* @param int $post_id Post ID.
* @param string $meta_key Post meta key.
* @param array $mapping Mapping array.
* @return void
*/
public static function update_header_mapping( $post_id = '', $meta_key = '', $mapping = array() ) {
Astra_Sites_Importer_Log::add( 'Mapping "' . $meta_key . '" for ' . $post_id );
$headers_old = get_post_meta( $post_id, $meta_key, true );
$headers_new = self::get_header_mapping( $headers_old, $mapping );
update_post_meta( $post_id, $meta_key, $headers_new );
}
/**
* Update Location Rules
*
* @since 1.1.6
*
* @param int $post_id Post ID.
* @param string $meta_key Post meta key.
* @param array $mapping Mapping array.
* @return void
*/
public static function update_location_rules( $post_id = '', $meta_key = '', $mapping = array() ) {
Astra_Sites_Importer_Log::add( 'Mapping "' . $meta_key . '" for ' . $post_id );
$location_new = self::get_location_mappings( $mapping );
update_post_meta( $post_id, $meta_key, $location_new );
}
/**
* Get mapping locations.
*
* @since 1.1.6
*
* @param array $location Location data.
* @return array Location mapping data.
*/
public static function get_location_mappings( $location = array() ) {
if ( empty( $location ) ) {
return $location;
}
if ( ! isset( $location['specific'] ) || empty( $location['specific'] ) ) {
return $location;
}
$mapping = array();
if ( isset( $location['specific']['post'] ) ) {
foreach ( $location['specific']['post'] as $post_type => $old_post_data ) {
if ( is_array( $old_post_data ) ) {
foreach ( $old_post_data as $post_key => $post ) {
$post_object = get_page_by_path( $post['slug'] );
if ( $post_object ) {
$mapping[] = 'post-' . absint( $post_object->ID );
}
}
}
}
}
if ( isset( $location['specific']['tax'] ) ) {
foreach ( $location['specific']['tax'] as $taxonomy_type => $old_term_data ) {
if ( is_array( $old_term_data ) ) {
foreach ( $old_term_data as $term_key => $term_data ) {
$term = get_term_by( 'slug', $term_data['slug'], $taxonomy_type );
if ( is_object( $term ) ) {
$mapping[] = 'tax-' . absint( $term->term_id );
}
}
}
}
}
$location['specific'] = $mapping;
return $location;
}
/**
* Get advanced header mapping data
*
* @since 1.1.6
*
* @param array $headers_old Header mapping stored data.
* @param array $headers_data Header mapping data.
* @return array Filtered header mapping data.
*/
public static function get_header_mapping( $headers_old = array(), $headers_data = array() ) {
// Set menu location by menu slug.
if ( isset( $headers_data['menus'] ) && ! empty( $headers_data['menus'] ) ) {
foreach ( $headers_data['menus'] as $header_option_name => $menu_data ) {
$term = get_term_by( 'slug', $menu_data['slug'], 'nav_menu' );
if ( is_object( $term ) ) {
$headers_old[ $header_option_name ] = $term->term_id;
}
}
}
// Set image ID & URL after importing these on website.
if ( isset( $headers_data['images'] ) && ! empty( $headers_data['images'] ) ) {
foreach ( $headers_data['images'] as $key => $image_data ) {
if ( isset( $image_data['image'] ) && ! empty( $image_data['image'] ) ) {
$downloaded_image = ST_Image_Importer::get_instance()->import( $image_data['image'] );
$headers_old[ $image_data['key_map']['url'] ] = $downloaded_image['url'];
$headers_old[ $image_data['key_map']['id'] ] = $downloaded_image['id'];
}
}
}
return $headers_old;
}
/**
* Clear Cache
*
* @since 1.2.3
* @return void
*/
public function clear_cache() {
if ( is_callable( 'Astra_Minify::refresh_assets' ) ) {
Astra_Minify::refresh_assets();
}
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Astra_Sites_Compatibility_Astra_Pro::get_instance();
endif;

View File

@@ -0,0 +1,62 @@
<?php
/**
* Astra Sites Compatibility for 'Beaver Builder'
*
* @package Astra Sites
* @since 3.0.21
*/
defined( 'ABSPATH' ) || exit;
/**
* Beaver Builder Compatibility
*
* @since 3.0.21
*/
class Astra_Sites_Compatibility_BB {
/**
* Instance
*
* @access private
* @var object Class object.
* @since 3.0.21
*/
private static $instance;
/**
* Initiator
*
* @since 3.0.21
* @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.21
*/
public function __construct() {
add_action( 'fl_builder_activated', array( $this, 'bb_activated' ) );
}
/**
* Disable redirection for Beaver Builder plugin when activated via Starter templates import process.
*/
public function bb_activated() {
if ( astra_sites_has_import_started() ) {
delete_transient( '_fl_builder_activation_admin_notice' );
}
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Astra_Sites_Compatibility_BB::get_instance();

View File

@@ -0,0 +1,60 @@
<?php
/**
* Astra Sites Compatibility for 'Checkout Plugins Stripe for WooCommerce'
*
* @see https://wordpress.org/plugins/checkout-plugins-stripe-woo/
*
* @package Astra Sites
* @since 3.0.23
*/
/**
* Checkout Plugins - Stripe compatibility for Starter Templates.
*/
class Astra_Sites_Checkout_Plugins_Stripe_WOO {
/**
* Instance
*
* @access private
* @var object Class object.
* @since 3.0.23
*/
private static $instance;
/**
* Initiator
*
* @since 3.0.23
* @return object initialized object of class.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor.
*/
public function __construct() {
add_action( 'astra_sites_after_plugin_activation', array( $this, 'checkout_plugins' ), 10, 2 );
}
/**
* Disable redirec after installing and activating Checkout Plugins - Stripe.
*
* @param string $plugin_init Plugin init file used for activation.
* @return void
*/
public function checkout_plugins( $plugin_init ) {
if ( 'checkout-plugins-stripe-woo/checkout-plugins-stripe-woo.php' === $plugin_init ) {
delete_option( 'cpsw_start_onboarding' );
}
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Astra_Sites_Checkout_Plugins_Stripe_WOO::get_instance();

View File

@@ -0,0 +1,78 @@
<?php
/**
* Astra Sites Compatibility for 3rd party plugins.
*
* @package Astra Sites
* @since 1.0.11
*/
if ( ! class_exists( 'Astra_Sites_Compatibility' ) ) :
/**
* Astra Sites Compatibility
*
* @since 1.0.11
*/
class Astra_Sites_Compatibility {
/**
* Instance
*
* @access private
* @var object Class object.
* @since 1.0.11
*/
private static $instance;
/**
* Initiator
*
* @since 1.0.11
* @return object initialized object of class.
*/
public static function instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*
* @since 1.0.11
*/
public function __construct() {
// Plugin - Astra Pro.
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/astra-pro/class-astra-sites-compatibility-astra-pro.php';
// Plugin - WooCommerce.
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/woocommerce/class-astra-sites-compatibility-woocommerce.php';
// Plugin - LearnDash LMS.
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/sfwd-lms/class-astra-sites-compatibility-sfwd-lms.php';
// Plugin - Elementor.
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/elementor/class-astra-sites-compatibility-elementor.php';
// Plugin - Beaver Builder.
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/beaver-builder/class-astra-sites-compatibility-bb.php';
// Plugin - LearnDash.
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/learndash/class-astra-sites-compatibility-learndash.php';
// Plugin - UABB.
require_once ASTRA_SITES_DIR . 'inc/classes/compatibility/uabb/class-astra-sites-compatibility-uabb.php';
}
}
/**
* Kicking this off by calling 'instance()' method
*/
Astra_Sites_Compatibility::instance();
endif;

View File

@@ -0,0 +1,187 @@
<?php
/**
* Astra Sites Compatibility for 'Elementor'
*
* @package Astra Sites
* @since 2.0.0
*/
namespace AstraSites\Elementor;
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( '\Elementor\Plugin' ) ) {
return;
}
if ( ! class_exists( 'Astra_Sites_Compatibility_Elementor' ) ) :
/**
* Elementor Compatibility
*
* @since 2.0.0
*/
class Astra_Sites_Compatibility_Elementor {
/**
* Instance
*
* @access private
* @var object Class object.
* @since 2.0.0
*/
private static $instance;
/**
* Initiator
*
* @since 2.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 2.0.0
*/
public function __construct() {
/**
* Add Slashes
*
* @todo Elementor already have below code which works on defining the constant `WP_LOAD_IMPORTERS`.
* After defining the constant `WP_LOAD_IMPORTERS` in WP CLI it was not works.
* Try to remove below duplicate code in future.
*/
if ( ! wp_doing_ajax() || ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '3.0.0', '>=' ) ) ) {
remove_filter( 'wp_import_post_meta', array( 'Elementor\Compatibility', 'on_wp_import_post_meta' ) );
remove_filter( 'wxr_importer.pre_process.post_meta', array( 'Elementor\Compatibility', 'on_wxr_importer_pre_process_post_meta' ) );
add_filter( 'wp_import_post_meta', array( $this, 'on_wp_import_post_meta' ) );
add_filter( 'wxr_importer.pre_process.post_meta', array( $this, 'on_wxr_importer_pre_process_post_meta' ) );
}
add_action( 'astra_sites_before_delete_imported_posts', array( $this, 'force_delete_kit' ), 10, 2 );
add_action( 'astra_sites_before_sse_import', array( $this, 'disable_attachment_metadata' ) );
add_action( 'init', array( $this, 'init' ) );
add_action( 'astra_sites_after_plugin_activation', array( $this, 'disable_elementor_redirect' ) );
}
/**
* Disable Elementor redirect.
*
* @return void.
*/
public function disable_elementor_redirect() {
$elementor_redirect = get_transient( 'elementor_activation_redirect' );
if ( ! empty( $elementor_redirect ) && '' !== $elementor_redirect ) {
delete_transient( 'elementor_activation_redirect' );
}
}
/**
* Remove the transient update check for plugins callback from Elementor.
* This reduces the extra code execution for Elementor.
*/
public function init() {
if ( astra_sites_has_import_started() && null !== \Elementor\Plugin::$instance->admin ) {
remove_filter( 'pre_set_site_transient_update_plugins', array( \Elementor\Plugin::$instance->admin->get_component( 'canary-deployment' ), 'check_version' ) );
}
}
/**
* Disable the attachment metadata
*/
public function disable_attachment_metadata() {
remove_filter(
'wp_update_attachment_metadata', array(
\Elementor\Plugin::$instance->uploads_manager->get_file_type_handlers( 'svg' ),
'set_svg_meta_data',
), 10, 2
);
}
/**
* Force Delete Elementor Kit
*
* Delete the previously imported Elementor kit.
*
* @param int $post_id Post name.
* @param string $post_type Post type.
*/
public function force_delete_kit( $post_id = 0, $post_type = '' ) {
if ( ! $post_id ) {
return;
}
if ( 'elementor_library' === $post_type ) {
$_GET['force_delete_kit'] = true;
}
}
/**
* Process post meta before WP importer.
*
* Normalize Elementor post meta on import, We need the `wp_slash` in order
* to avoid the unslashing during the `add_post_meta`.
*
* Fired by `wp_import_post_meta` filter.
*
* @since 1.4.3
* @access public
*
* @param array $post_meta Post meta.
*
* @return array Updated post meta.
*/
public function on_wp_import_post_meta( $post_meta ) {
foreach ( $post_meta as &$meta ) {
if ( '_elementor_data' === $meta['key'] ) {
$meta['value'] = wp_slash( $meta['value'] );
break;
}
}
return $post_meta;
}
/**
* Process post meta before WXR importer.
*
* Normalize Elementor post meta on import with the new WP_importer, We need
* the `wp_slash` in order to avoid the unslashing during the `add_post_meta`.
*
* Fired by `wxr_importer.pre_process.post_meta` filter.
*
* @since 1.4.3
* @access public
*
* @param array $post_meta Post meta.
*
* @return array Updated post meta.
*/
public function on_wxr_importer_pre_process_post_meta( $post_meta ) {
if ( '_elementor_data' === $post_meta['key'] ) {
$post_meta['value'] = wp_slash( $post_meta['value'] );
}
return $post_meta;
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Astra_Sites_Compatibility_Elementor::get_instance();
endif;

View File

@@ -0,0 +1,71 @@
<?php
/**
* Astra Sites Compatibility for 'LatePoint'
*
* @see https://wordpress.org/plugins/latepoint/
*
* @package Astra Sites
* @since 4.4.14
*/
if ( ! class_exists( 'Astra_Sites_Compatibility_LatePoint' ) ) :
/**
* LatePoint Compatibility
*
* @since 4.4.14
*/
class Astra_Sites_Compatibility_LatePoint {
/**
* Instance
*
* @access private
* @var object Class object.
* @since 4.4.14
*/
private static $instance;
/**
* Initiator
*
* @since 4.4.14
* @return object initialized object of class.
*/
public static function instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*
* @since 4.4.14
*/
public function __construct() {
add_action( 'astra_sites_after_plugin_activation', array( $this, 'disable_latepoint_redirection' ) );
}
/**
* Disables LatePoint redirection during plugin activation.
*
* @param string $plugin_init The path to the plugin file that was just activated.
*
* @since 4.4.14
*/
public function disable_latepoint_redirection( $plugin_init ) {
if ( 'latepoint/latepoint.php' === $plugin_init ) {
update_option( 'latepoint_redirect_to_wizard', false );
update_option( 'latepoint_show_version_5_modal', false );
}
}
}
/**
* Kicking this off by calling 'instance()' method
*/
Astra_Sites_Compatibility_LatePoint::instance();
endif;

View File

@@ -0,0 +1,62 @@
<?php
/**
* Compatibility for 'LearnDash'
*
* @see https://wordpress.org/plugins/astra-pro/
*
* @package Astra Sites
* @since 2.3.8
*/
// If LearnDash is not defined then return false.
if ( ! defined( 'LEARNDASH_COURSE_GRID_VERSION' ) ) {
return;
}
if ( ! class_exists( 'Astra_Sites_Compatibility_LearnDash' ) ) :
/**
* Astra Sites Compatibility LearnDash
*
* @since 2.3.8
*/
class Astra_Sites_Compatibility_LearnDash {
/**
* Instance
*
* @access private
* @var object Class object.
* @since 2.3.8
*/
private static $instance;
/**
* Initiator
*
* @since 2.3.8
* @return object initialized object of class.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*
* @since 2.3.8
*/
public function __construct() {
add_filter( 'astra_sites_pre_process_post_disable_content', '__return_false' );
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Astra_Sites_Compatibility_LearnDash::get_instance();
endif;

View File

@@ -0,0 +1,108 @@
<?php
/**
* Astra Sites Compatibility for 'LearnDash LMS'
*
* @see https://www.learndash.com/
*
* @package Astra Sites
* @since 1.3.13
*/
if ( ! class_exists( 'Astra_Sites_Compatibility_SFWD_LMS' ) ) :
/**
* Astra_Sites_Compatibility_SFWD_LMS
*
* @since 1.3.13
*/
class Astra_Sites_Compatibility_SFWD_LMS {
/**
* Instance
*
* @access private
* @var object Class object.
* @since 1.3.13
*/
private static $instance;
/**
* Initiator
*
* @since 1.3.13
* @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.3.13
*/
public function __construct() {
add_filter( 'astra_sites_gutenberg_batch_process_post_types', array( $this, 'set_post_types' ) );
add_action( 'astra_sites_import_complete', array( $this, 'process_landing_pages_mapping' ) );
}
/**
* Set LearnDash Landing pages with respect to Cartflows.
*
* @since 2.3.2
*/
public function process_landing_pages_mapping() {
$demo_data = Astra_Sites_File_System::get_instance()->get_demo_content();
if ( ! isset( $demo_data['astra-post-data-mapping'] ) || ! isset( $demo_data['astra-post-data-mapping']['ld_landing_pages'] ) ) {
return;
}
$index = 'ld_landing_pages';
$posts = ( isset( $demo_data['astra-post-data-mapping'][ $index ] ) ) ? $demo_data['astra-post-data-mapping'][ $index ] : array();
if ( ! empty( $posts ) ) {
foreach ( $posts as $key => $post ) {
if ( '' !== $post['landing_page'] ) {
// Get course by Title.
$course = Astra_Site_Options_Import::instance()->get_page_by_title( $post['course'], 'sfwd-courses' );
// Get landing step by Title.
$landing_page = Astra_Site_Options_Import::instance()->get_page_by_title( $post['landing_page'], 'cartflows_step' );
if ( is_object( $course ) && is_object( $landing_page ) ) {
if ( defined( 'WP_CLI' ) ) {
WP_CLI::line( 'Setting LearnDash - CartFlows Landing page - ' . $course->post_title . ' - ( ' . $course->ID . ' )' );
}
$ld_meta = get_post_meta( $course->ID, '_sfwd-courses', true );
$ld_meta['sfwd-courses_wcf_course_template'] = $landing_page->ID;
// Update the imported landing step to the course.
update_post_meta( $course->ID, '_sfwd-courses', $ld_meta );
}
}
}
}
}
/**
* Set post types
*
* @since 1.3.13
*
* @param array $post_types Post types.
*/
public function set_post_types( $post_types = array() ) {
return array_merge( $post_types, array( 'sfwd-courses', 'sfwd-lessons', 'sfwd-topic', 'sfwd-quiz', 'sfwd-certificates', 'sfwd-assignment' ) );
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Astra_Sites_Compatibility_SFWD_LMS::get_instance();
endif;

View File

@@ -0,0 +1,57 @@
<?php
/**
* Astra Sites Compatibility for 'UABB - Lite'
*
* @see https://wordpress.org/plugins/ultimate-addons-for-beaver-builder-lite/
*
* @package Astra Sites
* @since 3.0.23
*/
/**
* UABB compatibility for Starter Templates.
*/
class Astra_Sites_Compatibility_UABB {
/**
* Instance
*
* @access private
* @var object Class object.
* @since 3.0.23
*/
private static $instance;
/**
* Initiator
*
* @since 3.0.23
* @return object initialized object of class.
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor.
*/
public function __construct() {
add_action( 'astra_sites_after_plugin_activation', array( $this, 'uabb_activation' ), 10, 2 );
}
/**
* Disable redirec after installing and activating UABB.
*
* @return void
*/
public function uabb_activation() {
update_option( 'uabb_lite_redirect', false );
}
}
/**
* Kicking this off by calling 'get_instance()' method
*/
Astra_Sites_Compatibility_UABB::get_instance();

View File

@@ -0,0 +1,184 @@
<?php
/**
* Astra Sites Compatibility for 'WooCommerce'
*
* @see https://wordpress.org/plugins/woocommerce/
*
* @package Astra Sites
* @since 1.1.4
*/
if ( ! class_exists( 'Astra_Sites_Compatibility_WooCommerce' ) ) :
/**
* WooCommerce Compatibility
*
* @since 1.1.4
*/
class Astra_Sites_Compatibility_WooCommerce {
/**
* Instance
*
* @access private
* @var object Class object.
* @since 1.1.4
*/
private static $instance;
/**
* Initiator
*
* @since 1.1.4
* @return object initialized object of class.
*/
public static function instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*
* @since 1.1.4
*/
public function __construct() {
add_action( 'astra_sites_import_start', array( $this, 'add_attributes' ), 10, 2 );
add_action( 'astra_sites_after_plugin_activation', array( $this, 'install_wc' ), 10, 2 );
// WooCommerce product attributes registration.
if ( class_exists( 'WooCommerce' ) ) {
add_filter( 'wxr_importer.pre_process.term', array( $this, 'woocommerce_product_attributes_registration' ), 10, 1 );
add_action( 'astra_sites_import_complete', array( $this, 'update_wc_lookup_table' ) );
}
add_filter( 'astra_sites_pre_process_post_disable_content', '__return_false' );
add_filter( 'astra_sites_pre_process_post_empty_excerpt', '__return_false' );
}
/**
* Add product attributes.
*
* @since 1.1.4
*
* @param string $demo_data Import data.
* @param array $demo_api_uri Demo site URL.
* @return void
*/
public function add_attributes( $demo_data = array(), $demo_api_uri = '' ) {
$attributes = ( isset( $demo_data['astra-site-options-data']['woocommerce_product_attributes'] ) ) ? $demo_data['astra-site-options-data']['woocommerce_product_attributes'] : array();
if ( ! empty( $attributes ) && function_exists( 'wc_create_attribute' ) ) {
foreach ( $attributes as $key => $attribute ) {
$args = array(
'name' => $attribute['attribute_label'],
'slug' => $attribute['attribute_name'],
'type' => $attribute['attribute_type'],
'order_by' => $attribute['attribute_orderby'],
'has_archives' => $attribute['attribute_public'],
);
$id = wc_create_attribute( $args );
}
}
}
/**
* Create default WooCommerce tables
*
* @param string $plugin_init Plugin file which is activated.
* @return void
*/
public function install_wc( $plugin_init ) {
if ( 'woocommerce/woocommerce.php' !== $plugin_init ) {
return;
}
// Create WooCommerce database tables.
if ( is_callable( '\Automattic\WooCommerce\Admin\Install::create_tables' ) ) {
\Automattic\WooCommerce\Admin\Install::create_tables();
\Automattic\WooCommerce\Admin\Install::create_events();
}
if ( is_callable( 'WC_Install::install' ) ) {
WC_Install::install();
}
}
/**
* Hook into the pre-process term filter of the content import and register the
* custom WooCommerce product attributes, so that the terms can then be imported normally.
*
* This should probably be removed once the WP importer 2.0 support is added in WooCommerce.
*
* Fixes: [WARNING] Failed to import pa_size L warnings in content import.
* Code from: woocommerce/includes/admin/class-wc-admin-importers.php (ver 2.6.9).
*
* Github issue: https://github.com/proteusthemes/one-click-demo-import/issues/71
*
* @since 3.0.0
* @param array $data The term data to import.
* @return array The unchanged term data.
*/
public function woocommerce_product_attributes_registration( $data ) {
global $wpdb;
if ( strstr( $data['taxonomy'], 'pa_' ) ) {
if ( ! taxonomy_exists( $data['taxonomy'] ) ) {
$attribute_name = wc_sanitize_taxonomy_name( str_replace( 'pa_', '', $data['taxonomy'] ) );
// Create the taxonomy.
if ( ! in_array( $attribute_name, wc_get_attribute_taxonomies(), true ) ) {
$attribute = array(
'attribute_label' => $attribute_name,
'attribute_name' => $attribute_name,
'attribute_type' => 'select',
'attribute_orderby' => 'menu_order',
'attribute_public' => 0,
);
$wpdb->insert( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery -- WP Query would be expensive here, we are adding taxonomy attributes for WooCommerce.
delete_transient( 'wc_attribute_taxonomies' );
}
// Register the taxonomy now so that the import works!
register_taxonomy(
$data['taxonomy'],
apply_filters( 'woocommerce_taxonomy_objects_' . $data['taxonomy'], array( 'product' ) ),
apply_filters(
'woocommerce_taxonomy_args_' . $data['taxonomy'], array(
'hierarchical' => true,
'show_ui' => false,
'query_var' => true,
'rewrite' => false,
)
)
);
}
}
return $data;
}
/**
* Update WooCommerce Lookup Table.
*
* @since 3.0.0
*
* @return void
*/
public function update_wc_lookup_table() {
if ( function_exists( 'wc_update_product_lookup_tables' ) ) {
if ( ! wc_update_product_lookup_tables_is_running() ) {
wc_update_product_lookup_tables();
}
}
}
}
/**
* Kicking this off by calling 'instance()' method
*/
Astra_Sites_Compatibility_WooCommerce::instance();
endif;

View File

@@ -0,0 +1,138 @@
<?php
/**
* Functions
*
* @since 2.0.0
* @package Astra Sites
*/
if ( ! function_exists( 'astra_sites_error_log' ) ) :
/**
* Error Log
*
* A wrapper function for the error_log() function.
*
* @since 2.0.0
*
* @param mixed $message Error message.
* @return void
*/
function astra_sites_error_log( $message = '' ) {
if ( defined( 'WP_DEBUG_LOG' ) && WP_DEBUG_LOG ) {
if ( is_array( $message ) ) {
$message = wp_json_encode( $message );
}
if ( apply_filters( 'astra_sites_debug_logs', false ) ) {
error_log( $message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- This is for the debug logs while importing. This is conditional and will not be logged in the debug.log file for normal users.
}
}
}
endif;
if ( ! function_exists( 'astra_sites_get_suggestion_link' ) ) :
/**
*
* Get suggestion link.
*
* @since 2.6.1
*
* @return suggestion link.
*/
function astra_sites_get_suggestion_link() {
$white_label_link = Astra_Sites_White_Label::get_option( 'astra-agency', 'licence' );
if ( empty( $white_label_link ) ) {
$white_label_link = 'https://wpastra.com/sites-suggestions/?utm_source=demo-import-panel&utm_campaign=astra-sites&utm_medium=suggestions';
}
return apply_filters( 'astra_sites_suggestion_link', $white_label_link );
}
endif;
if ( ! function_exists( 'astra_sites_is_valid_image' ) ) :
/**
* Check for the valid image
*
* @param string $link The Image link.
*
* @since 2.6.2
* @return boolean
*/
function astra_sites_is_valid_image( $link = '' ) {
return preg_match( '/^((https?:\/\/)|(www\.))([a-z0-9-].?)+(:[0-9]+)?\/[\w\-\@]+\.(jpg|png|gif|jpeg|svg)\/?$/i', $link );
}
endif;
if ( ! function_exists( 'astra_get_site_data' ) ) :
/**
* Returns the value of the index for the Site Data
*
* @param string $index The index value of the data.
*
* @since 2.6.14
* @return mixed
*/
function astra_get_site_data( $index = '' ) {
$demo_data = Astra_Sites_File_System::get_instance()->get_demo_content();
if ( ! empty( $demo_data ) && isset( $demo_data[ $index ] ) ) {
return $demo_data[ $index ];
}
return '';
}
endif;
if ( ! function_exists( 'astra_sites_get_reset_form_data' ) ) :
/**
* Get all the forms to be reset.
*
* @since 3.0.3
* @return array
*/
function astra_sites_get_reset_form_data() {
global $wpdb;
$form_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_astra_sites_imported_wp_forms'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- We need this to get all the WP forms. Traditional WP_Query would have been expensive here.
return $form_ids;
}
endif;
if ( ! function_exists( 'astra_sites_get_reset_term_data' ) ) :
/**
* Get all the terms to be reset.
*
* @since 3.0.3
* @return array
*/
function astra_sites_get_reset_term_data() {
global $wpdb;
$term_ids = $wpdb->get_col( "SELECT term_id FROM {$wpdb->termmeta} WHERE meta_key='_astra_sites_imported_term'" ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- We need this to get all the terms and taxonomy. Traditional WP_Query would have been expensive here.
return $term_ids;
}
endif;
if ( ! function_exists( 'astra_sites_empty_post_excerpt' ) ) :
/**
* Remove the post excerpt
*
* @param int $post_id The post ID.
* @since 3.1.0
*/
function astra_sites_empty_post_excerpt( $post_id = 0 ) {
if ( ! $post_id ) {
return;
}
wp_update_post(
array(
'ID' => $post_id,
'post_excerpt' => '',
)
);
}
endif;