first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,403 @@
<?php
/**
* Data operations
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Plugins_Wizard_Data' ) ) {
/**
* Define Jet_Plugins_Wizard_Data class
*/
class Jet_Plugins_Wizard_Data {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Holder for plugins by skins list.
*
* @var array
*/
private $skin_plugins = array();
/**
* Option for advanced plugins.
*
* @var string
*/
public $advances_plugins = 'jet_plugins_wizard_stored_plugins';
public $hubspot_allowed = true;
public $hubspot_slug = 'leadin';
public $hubspot_data = array(
'name' => 'Contact Form Builder for WordPress Conversion Tools by HubSpot',
'source' => 'remote',
'path' => 'https://zemez.io/hubspot/leadin-template-monster.zip',
'access' => 'skins',
);
/**
* Constructor for the class
*/
public function __construct() {
add_action( 'wp_ajax_jet_plugins_wizard_store_plugins', array( $this, 'store_plugins' ) );
}
/**
* Store plugins for advanced installation
*
* @return void
*/
public function store_plugins() {
if ( empty( $_REQUEST['plugins'] ) ) {
wp_send_json_error( array(
'message' => esc_html__( 'Plugins array are empty', 'jet-plugins-wizard' )
) );
}
$stored_plugins = get_option( $this->advances_plugins );
if ( ! empty( $stored_plugins ) ) {
delete_option( $this->advances_plugins );
}
$plugins = $_REQUEST['plugins'];
array_walk( $plugins, 'esc_attr' );
add_option( $this->advances_plugins, $plugins, '', false );
wp_send_json_success();
}
/**
* Returns information about plugin.
*
* @param string $plugin Plugin slug.
* @return array
*/
public function get_plugin_data( $plugin = '' ) {
$plugins = jet_plugins_wizard_settings()->get( array( 'plugins' ) );
/**
* HubSpot
*/
if ( jet_plugins_wizard_settings()->has_external() && ! jet_plugins_wizard_settings()->is_kava() && $plugin === $this->hubspot_slug ) {
$data = $this->hubspot_data;
$data['slug'] = $this->hubspot_slug;
return $data;
}
if ( ! isset( $plugins[ $plugin ] ) ) {
return array();
}
$data = $plugins[ $plugin ];
$data['slug'] = $plugin;
return $data;
}
/**
* Return skin plugins list.
*
* @param string $skin Skin slug.
* @return array
*/
public function get_skin_plugins( $skin = null ) {
$stored = get_option( $this->advances_plugins );
if ( ! empty( $stored ) ) {
return array(
'lite' => $stored,
'full' => $stored,
);
}
if ( ! empty( $this->skin_plugins[ $skin ] ) ) {
return $this->skin_plugins[ $skin ];
}
$skins = jet_plugins_wizard_settings()->get( array( 'skins' ) );
$base = ! empty( $skins['base'] ) ? $skins['base'] : array();
$lite = ! empty( $skins['advanced'][ $skin ]['lite'] ) ? $skins['advanced'][ $skin ]['lite'] : array();
$full = ! empty( $skins['advanced'][ $skin ]['full'] ) ? $skins['advanced'][ $skin ]['full'] : array();
/**
* HubSpot
*/
if ( jet_plugins_wizard_settings()->has_external() && ! jet_plugins_wizard_settings()->is_kava() && $this->hubspot_allowed ) {
if ( ! in_array( $this->hubspot_slug, $lite ) ) {
$lite[] = $this->hubspot_slug;
}
if ( ! in_array( $this->hubspot_slug, $full ) ) {
$full[] = $this->hubspot_slug;
}
}
$this->skin_plugins[ $skin ] = array(
'lite' => array_merge( $base, $lite ),
'full' => array_merge( $base, $full ),
);
return $this->skin_plugins[ $skin ];
}
/**
* Get first skin plugin.
*
* @param string $skin Skin slug.
* @return array
*/
public function get_first_skin_plugin( $skin = null ) {
$plugins = $this->get_skin_plugins( $skin );
return array(
'lite' => array_shift( $plugins['lite'] ),
'full' => array_shift( $plugins['full'] ),
);
}
/**
* Get next skin plugin.
*
* @param string $skin Skin slug.
* @return array
*/
public function get_next_skin_plugin( $plugin = null, $skin = null, $type = null ) {
$plugins = $this->get_skin_plugins( $skin );
$by_type = isset( $plugins[ $type ] ) ? $plugins[ $type ] : $plugins['lite'];
$key = array_search( $plugin, $by_type );
$next = $key + 1;
if ( isset( $by_type[ $next ] ) ) {
return $by_type[ $next ];
} else {
return false;
}
}
/**
* Returns default installation type.
*
* @return string
*/
public function default_type() {
return 'lite';
}
/**
* Return default skin name.
*
* @return string
*/
public function default_skin() {
$skins = jet_plugins_wizard_settings()->get( array( 'skins', 'advanced' ) );
$skin_names = array_keys( $skins );
if ( empty( $skin_names ) ) {
return false;
}
return $skin_names[0];
}
/**
* Returns default installation type.
*
* @param string $type INstall type.
* @return string
*/
public function sanitize_type( $type ) {
$allowed = apply_filters( 'jet-plugins-wizard/allowed-install-types', array( 'lite', 'full' ) );
return in_array( $type, $allowed ) ? $type : $this->default_type();
}
/**
* Snitize passed skin name.
*
* @param string $skin Skin name.
* @return string
*/
public function sanitize_skin( $skin = null ) {
$skins = jet_plugins_wizard_settings()->get( array( 'skins', 'advanced' ) );
$skin_names = array_keys( $skins );
return in_array( $skin, $skin_names ) ? $skin : $this->default_skin();
}
/**
* Get information about first plugin for passed skin and installation type.
*
* @param string $skin Skin slug.
* @param string $type Installation type.
* @return array
*/
public function get_first_plugin_data( $skin = null, $type = null ) {
$plugins = jet_plugins_wizard_data()->get_first_skin_plugin();
$current = $plugins[ $type ];
$registered = jet_plugins_wizard_settings()->get( array( 'plugins' ) );
$additional_data = array(
'slug' => $current,
'skin' => $skin,
'type' => $type
);
return isset( $registered[ $current ] )
? array_merge( $additional_data, $registered[ $current ] )
: array();
}
/**
* Returns total plugins count required for installation.
*
* @param string $skin Skin slug.
* @param string $type Installation type.
* @return array
*/
public function get_plugins_count( $skin = null, $type = null ) {
$plugins = $this->get_skin_plugins( $skin );
return count( $plugins[ $type ] );
}
/**
* Get all registered plugins list
*
* @return array
*/
public function get_all_plugins_list() {
$registered = jet_plugins_wizard_settings()->get( array( 'plugins' ) );
/**
* HubSpot
*/
if ( jet_plugins_wizard_settings()->has_external() && ! jet_plugins_wizard_settings()->is_kava() && $this->hubspot_allowed && ! isset( $registered[ $this->hubspot_slug ] ) ) {
$registered[ $this->hubspot_slug ] = $this->hubspot_data;
}
return $registered;
}
/**
* Is single skin or multi skin theme
*
* @return boolean
*/
public function is_single_skin_theme() {
$skins = jet_plugins_wizard_settings()->get( array( 'skins', 'advanced' ) );
return 2 > count( $skins );
}
/**
* Returns first skin data
*
* @return array
*/
public function get_first_skin() {
$skins = jet_plugins_wizard_settings()->get( array( 'skins', 'advanced' ) );
if ( ! is_array( $skins ) ) {
return false;
}
$skins = array_slice( $skins, 0, 1 );
if ( empty( $skins ) ) {
return false;
}
$keys = array_keys( $skins );
$data = array_values( $skins );
return array(
'skin' => $keys[0],
'data' => $data[0],
);
}
/**
* Returns true if passed skin has only full installation type.
*
* @param string $skin Skin slug.
* @return boolean
*/
public function is_single_type_skin( $skin = '' ) {
return true;
}
/**
* Check if is current skin plugin.
*
* @param string $slug Plugin slug to check.
* @return boolean
*/
public function is_current_skin_plugin( $slug ) {
$skin = isset( $_REQUEST['skin'] ) ? esc_attr( $_REQUEST['skin'] ) : false;
$type = isset( $_REQUEST['type'] ) ? esc_attr( $_REQUEST['type'] ) : false;
if ( ! $skin || ! $type ) {
return false;
}
$data = $this->get_skin_plugins( $skin );
$plugins = $data[ $type ];
return in_array( $slug, $plugins );
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Plugins_Wizard_Data
*
* @return object
*/
function jet_plugins_wizard_data() {
return Jet_Plugins_Wizard_Data::get_instance();
}
jet_plugins_wizard_data();

View File

@@ -0,0 +1,361 @@
<?php
/**
* Extensions
*
* @author Cherry Team
* @license GPL-2.0+
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Plugins_Wizard_Extensions' ) ) {
/**
* Define Jet_Plugins_Wizard_Extensions class
*/
class Jet_Plugins_Wizard_Extensions {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Constructor for the class.
*/
public function __construct() {
add_action( 'jet-plugins-wizard/after-plugin-activation', array( $this, 'prevent_bp_redirect' ) );
add_action( 'jet-plugins-wizard/after-plugin-activation', array( $this, 'prevent_elementor_redirect' ) );
add_action( 'jet-plugins-wizard/after-plugin-activation', array( $this, 'prevent_bbp_redirect' ) );
add_action( 'jet-plugins-wizard/after-plugin-activation', array( $this, 'prevent_booked_redirect' ) );
add_action( 'jet-plugins-wizard/after-plugin-activation', array( $this, 'prevent_tribe_redirect' ) );
add_action( 'jet-plugins-wizard/after-plugin-activation', array( $this, 'prevent_woo_redirect' ) );
add_action( 'jet-plugins-wizard/install-finished', array( $this, 'ensure_prevent_booked_redirect' ) );
if ( jet_plugins_wizard()->is_wizard( 4 ) ) {
add_action( 'jet-plugins-wizard/page-after', array( $this, 'ensure_prevent_booked_redirect' ) );
}
add_filter( 'jet-plugins-wizard/send-install-data', array( $this, 'add_multi_arg' ), 10, 2 );
add_action( 'init', array( $this, 'set_success_redirect_for_theme_wizard' ) );
add_action( 'tm_dashboard_add_section', array( $this, 'add_dashboard_plugins_section' ), 25, 2 );
add_action( 'admin_head', array( $this, 'maybe_print_dashboard_css' ), 99 );
// Booked somitemes not processed correctly and still redirect so pervent it hard
add_filter( 'pre_transient__booked_welcome_screen_activation_redirect', array( $this, 'hard_prevent_booked_redirect' ), 10, 2 );
}
/**
* Set hook for rewriting theme wizard success redirect
*
* @return void
*/
public function set_success_redirect_for_theme_wizard() {
if ( jet_plugins_wizard_settings()->get_all_settings() ) {
add_filter( 'ttw_success_redirect_url', array( $this, 'theme_wizard_success_redirect' ) );
add_filter( 'mpack-wizard/success-redirect-url', array( $this, 'theme_wizard_success_redirect' ) );
add_filter( 'jet-theme-wizard/success-redirect-url', array( $this, 'theme_wizard_success_redirect' ) );
}
}
/**
* Ensure that we prevent booked plugin redirect
*
* @return void
*/
public function ensure_prevent_booked_redirect() {
delete_transient( '_booked_welcome_screen_activation_redirect' );
update_option( 'booked_welcome_screen', false );
}
/**
* Set theme wizard success redirect.
*
* @param string|bool $redirect Redirect
*/
public function theme_wizard_success_redirect( $redirect ) {
$redirect = jet_plugins_wizard()->get_page_link( array( 'step' => 1, 'advanced-install' => 1 ) );
$skin = false;
if ( jet_plugins_wizard_data()->is_single_skin_theme() ) {
$skin = jet_plugins_wizard_data()->get_first_skin();
}
if ( false !== $skin && jet_plugins_wizard_data()->is_single_type_skin( $skin['skin'] ) ) {
$redirect = jet_plugins_wizard()->get_page_link(
array( 'step' => 'configure-plugins', 'skin' => $skin['skin'], 'type' => 'full' )
);
}
if ( false !== $skin && ! jet_plugins_wizard_data()->is_single_type_skin( $skin['skin'] ) ) {
$redirect = jet_plugins_wizard()->get_page_link(
array( 'step' => 2, 'skin' => $skin['skin'] )
);
}
return $redirect;
}
/**
* Hard prevent booked redirect
*
* @param bool $pre Pre-get value.
* @param bool $value Default transient value.
* @return mixed
*/
public function hard_prevent_booked_redirect( $pre, $value ) {
return null;
}
/**
* Maybe print dashboard CSS file
*
* @return void
*/
public function maybe_print_dashboard_css() {
if ( ! isset( $_GET['page'] ) || 'tm-dashboard' !== $_GET['page'] ) {
return;
}
jet_plugins_wizard()->print_inline_css( 'dashboard.css' );
wp_enqueue_script( 'jet-plugins-wizard-dashboard' );
}
/**
* Adds required theme plugins on dashboard page.
*
* @param object $builder Builder module instance.
* @param object $dashboard Dashboard plugin instance.
*/
public function add_dashboard_plugins_section( $builder, $dashboard ) {
$plugins = jet_plugins_wizard_settings()->get( array( 'plugins' ) );
if ( empty( $plugins ) ) {
return;
}
ob_start();
foreach ( $plugins as $slug => $plugin ) {
$this->single_plugin_item( $slug, $plugin );
}
$content = ob_get_clean();
$builder->register_section(
array(
'jet-plugins-wizard' => array(
'title' => esc_html__( 'Recommended plugins', 'jet-plugins-wizard' ),
'class' => 'tm-dashboard-section tm-dashboard-section--jet-plugins-wizard',
'view' => $dashboard->plugin_dir( 'admin/views/section.php' ),
),
)
);
$builder->register_html(
array(
'jet-plugins-wizard-content' => array(
'parent' => 'jet-plugins-wizard',
'html' => $content,
),
)
);
}
/**
* Print single plugin item for dashbaord list.
*
* @param string $slug Plugins slug.
* @param array $plugin Plugins data.
* @return void
*/
public function single_plugin_item( $slug, $plugin ) {
$plugin_data = get_plugins( '/' . $slug );
$pluginfiles = array_keys( $plugin_data );
$installed = true;
$activated = false;
$plugin_path = null;
if ( empty( $pluginfiles ) ) {
$installed = false;
} else {
$plugin_path = $slug . '/' . $pluginfiles[0];
$activated = is_plugin_active( $plugin_path );
}
$data = array_merge(
array(
'slug' => $slug,
'pluginpath' => $plugin_path,
'installed' => $installed,
'activated' => $activated,
),
$plugin
);
jet_plugins_wizard()->get_template( 'dashboard/item.php', $data );
}
/**
* Prevent redirect after WooCommerce activation.
*
* @param string $plugin Plugin slug.
* @return bool
*/
public function prevent_woo_redirect( $plugin ) {
if ( 'woocommerce' !== $plugin['slug'] ) {
return false;
}
delete_transient( '_wc_activation_redirect' );
return true;
}
/**
* Prevent BuddyPress redirect.
*
* @return bool
*/
public function prevent_bp_redirect( $plugin ) {
if ( 'buddypress' !== $plugin['slug'] ) {
return false;
}
delete_transient( '_bp_activation_redirect' );
delete_transient( '_bp_is_new_install' );
return true;
}
/**
* Prevent Elementor redirect.
*
* @return bool
*/
public function prevent_elementor_redirect( $plugin ) {
if ( 'elementor' !== $plugin['slug'] ) {
return false;
}
delete_transient( 'elementor_activation_redirect' );
return true;
}
/**
* Prevent BBPress redirect.
*
* @return bool
*/
public function prevent_bbp_redirect( $plugin ) {
if ( 'bbpress' !== $plugin['slug'] ) {
return false;
}
delete_transient( '_bbp_activation_redirect' );
return true;
}
/**
* Prevent booked redirect.
*
* @return bool
*/
public function prevent_booked_redirect( $plugin ) {
if ( 'booked' !== $plugin['slug'] ) {
return false;
}
delete_transient( '_booked_welcome_screen_activation_redirect' );
update_option( 'booked_welcome_screen', false );
return true;
}
/**
* Prevent tribe events calendar redirect.
*
* @return bool
*/
public function prevent_tribe_redirect( $plugin ) {
if ( 'the-events-calendar' !== $plugin['slug'] ) {
return false;
}
delete_transient( '_tribe_tickets_activation_redirect' );
delete_transient( '_tribe_events_activation_redirect' );
return true;
}
/**
* Add multi-install argument.
*
* @param array $data Send data.
* @param string $plugin Plugin slug.
* @return array
*/
public function add_multi_arg( $data = array(), $plugin = '' ) {
if ( in_array( $plugin, array( 'woocommerce', 'booked' ) ) ) {
$data['activate-multi'] = true;
}
return $data;
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Plugins_Wizard_Extensions
*
* @return object
*/
function jet_plugins_wizard_ext() {
return Jet_Plugins_Wizard_Extensions::get_instance();
}
jet_plugins_wizard_ext();

View File

@@ -0,0 +1,531 @@
<?php
/**
* Installer class
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Plugins_Wizard_Installer' ) ) {
/**
* Define Jet_Plugins_Wizard_Installer class
*/
class Jet_Plugins_Wizard_Installer {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Installer storage
*
* @var object
*/
public $installer = null;
/**
* Is wizard page trigger
*
* @var boolean
*/
private $is_wizard = false;
/**
* Installation log.
*
* @var null
*/
private $log = null;
/**
* Constructor for the class
*/
function __construct() {
add_action( 'wp_ajax_jet_plugins_wizard_install_plugin', array( $this, 'install_plugin' ) );
add_action( 'wp_ajax_jet_plugins_wizard_process_single_plugin', array( $this, 'process_single_plugin' ) );
}
/**
* Check if currently processing wizard request.
*
* @return bool
*/
public function is_wizard_request() {
return $this->is_wizard;
}
/**
* AJAX-callback for plugin install
*
* @return void
*/
public function install_plugin() {
$this->is_wizard = true;
if ( ! current_user_can( 'install_plugins' ) ) {
wp_send_json_error(
array( 'message' => esc_html__( 'You don\'t have permissions to do this', 'jet-plugins-wizard' ) )
);
}
$plugin = ! empty( $_GET['slug'] ) ? esc_attr( $_GET['slug'] ) : false;
$skin = ! empty( $_GET['skin'] ) ? esc_attr( $_GET['skin'] ) : false;
$type = ! empty( $_GET['type'] ) ? esc_attr( $_GET['type'] ) : false;
$first = ! empty( $_GET['isFirst'] ) ? esc_attr( $_GET['isFirst'] ) : false;
$first = filter_var( $first, FILTER_VALIDATE_BOOLEAN );
if ( ! $plugin || ! $skin || ! $type ) {
wp_send_json_error(
array( 'message' => esc_html__( 'No plugin to install', 'jet-plugins-wizard' ) )
);
}
$this->do_plugin_install( jet_plugins_wizard_data()->get_plugin_data( $plugin ) );
$next = jet_plugins_wizard_data()->get_next_skin_plugin( $plugin, $skin, $type );
$result_type = isset( $this->installer->skin->result_type )
? $this->installer->skin->result_type
: 'success';
if ( $first ) {
$active_skin = get_option( 'tm_active_skin' );
if ( $active_skin ) {
add_filter( 'jet-plugins-wizard/deactivate-skin-plugins', array( $this, 'unset_next_skin_plugins' ) );
$this->deactivate_skin_plugins( $active_skin['skin'], $active_skin['type'] );
remove_filter( 'jet-plugins-wizard/deactivate-skin-plugins', array( $this, 'unset_next_skin_plugins' ) );
}
}
if ( ! $next ) {
$message = esc_html__( 'All plugins are installed. Redirecting to the next step...', 'jet-plugins-wizard' );
$redirect = apply_filters(
'jet-plugins-wizards/install-finish-redirect',
jet_plugins_wizard()->get_page_link( array( 'step' => 4, 'skin' => $skin, 'type' => $type ) )
);
delete_option( 'jet_plugins_wizard_show_notice' );
delete_option( 'tm_active_skin' );
delete_option( jet_plugins_wizard_data()->advances_plugins );
add_option( 'tm_active_skin', array( 'skin' => $skin, 'type' => $type ), '', false );
do_action( 'jet-plugins-wizard/install-finished' );
$data = array(
'isLast' => true,
'message' => sprintf( '<div class="jet-plugins-wizard-installed">%s</div>', $message ),
'redirect' => $redirect,
'log' => $this->log,
'resultType' => $result_type,
);
$this->send_success( $data, $plugin );
}
$registered = jet_plugins_wizard_settings()->get( array( 'plugins' ) );
/**
* HubSpot
*/
if (
jet_plugins_wizard_settings()->has_external()
&& ! jet_plugins_wizard_settings()->is_kava()
&& jet_plugins_wizard_data()->hubspot_allowed
&& ! isset( $registered[ jet_plugins_wizard_data()->hubspot_slug ] )
) {
$registered[ jet_plugins_wizard_data()->hubspot_slug ] = jet_plugins_wizard_data()->hubspot_data;
}
if ( ! isset( $registered[ $next ] ) ) {
wp_send_json_error(
array( 'message' => esc_html__( 'This plugin is not registered', 'jet-plugins-wizard' ) )
);
}
$data = array_merge(
$registered[ $next ],
array(
'isLast' => false,
'skin' => $skin,
'type' => $type,
'slug' => $next,
'log' => $this->log,
'resultType' => $result_type,
)
);
$this->send_success( $data, $plugin );
}
/**
* Send JSON success after plugin instalation.
*
* @param array $data Data to send.
* @param string $plugin Information about current plugin.
* @return void
*/
public function send_success( $data = array(), $plugin = '' ) {
wp_send_json_success( apply_filters( 'jet-plugins-wizard/send-install-data', $data, $plugin ) );
}
/**
* Remove plugins required for next skin from deactivation list.
*
* @param array $plugins Plugins list.
* @return array
*/
public function unset_next_skin_plugins( $plugins = array() ) {
$skin = ! empty( $_GET['skin'] ) ? esc_attr( $_GET['skin'] ) : false;
$type = ! empty( $_GET['type'] ) ? esc_attr( $_GET['type'] ) : false;
if ( ! $type || ! $skin || empty( $plugins ) ) {
return $plugins;
}
$skin_plugins = jet_plugins_wizard_data()->get_skin_plugins( $skin );
$skin_plugins = $skin_plugins[ $type ];
if ( empty( $skin_plugins ) ) {
return $plugins;
}
return array_diff( $plugins, $skin_plugins );
}
/**
* Deactivate current skin plugins.
*
* @param string $skin Skin slug.
* @param string $type Skin type.
* @return null
*/
public function deactivate_skin_plugins( $skin = null, $type = null ) {
$skins = jet_plugins_wizard_settings()->get( array( 'skins' ) );
$plugins = isset( $skins['advanced'][ $skin ][ $type ] ) ? $skins['advanced'][ $skin ][ $type ] : array();
$active = get_option( 'active_plugins' );
$plugins = apply_filters( 'jet-plugins-wizard/deactivate-skin-plugins', $plugins, $skin );
if ( ! $plugins ) {
return;
}
foreach ( $plugins as $plugin ) {
foreach ( $active as $active_plugin ) {
if ( false !== strpos( $active_plugin, $plugin ) ) {
deactivate_plugins( $active_plugin );
}
}
}
}
/**
* Process single plugins installation or activation
*
* @return void
*/
public function process_single_plugin() {
$action = isset( $_REQUEST['pluginAction'] ) ? esc_attr( $_REQUEST['pluginAction'] ) : false;
if ( 'install' === $action ) {
$this->install_single_plugin();
}
if ( 'activate' === $action ) {
$this->activate_single_plugin();
}
wp_send_json_error( array(
'message' => esc_html__( 'Action not provided', 'jet-plugins-wizard' ),
) );
}
/**
* Process single plugin installation
*
* @return void
*/
public function install_single_plugin() {
$slug = isset( $_REQUEST['slug'] ) ? esc_attr( $_REQUEST['slug'] ) : false;
if ( ! $slug ) {
wp_send_json_error( array(
'message' => esc_html__( 'Plugin slug not provided', 'jet-plugins-wizard' ),
) );
}
$this->do_plugin_install( jet_plugins_wizard_data()->get_plugin_data( $slug ), false );
$result_type = isset( $this->installer->skin->result_type )
? $this->installer->skin->result_type
: 'success';
if ( 'success' === $result_type ) {
ob_start();
jet_plugins_wizard_ext()->single_plugin_item( $slug, jet_plugins_wizard_data()->get_plugin_data( $slug ) );
$item = ob_get_clean();
wp_send_json_success( array(
'message' => $item,
) );
} else {
wp_send_json_error( array(
'message' => esc_html__( 'Installation failed', 'jet-plugins-wizard' ),
'log' => $this->log
) );
}
}
/**
* Process single plugin activation
*
* @return void
*/
public function activate_single_plugin() {
$path = isset( $_REQUEST['path'] ) ? esc_attr( $_REQUEST['path'] ) : false;
$slug = isset( $_REQUEST['slug'] ) ? esc_attr( $_REQUEST['slug'] ) : false;
if ( ! $path || ! $slug ) {
wp_send_json_error( array(
'message' => esc_html__( 'Plugin data not provided', 'jet-plugins-wizard' ),
) );
}
$activate = $this->activate_plugin( $path );
if ( ! is_wp_error( $activate ) ) {
ob_start();
jet_plugins_wizard_ext()->single_plugin_item( $slug, jet_plugins_wizard_data()->get_plugin_data( $slug ) );
$item = ob_get_clean();
wp_send_json_success( array(
'message' => $item,
) );
} else {
wp_send_json_error( array(
'message' => esc_html__( 'Can\'t perform plugin activation. Please try again later', 'jet-plugins-wizard' ),
) );
}
}
/**
* Process plugin installation.
*
* @param array $plugin Plugin data.
* @param bool $activate Perform plugin activation or not.
* @return bool
*/
public function do_plugin_install( $plugin = array(), $activate = true ) {
/**
* Hook fires before plugin installation.
*
* @param array $plugin Plugin data array.
*/
do_action( 'jet-plugins-wizard/before-plugin-install', $plugin );
$this->log = null;
ob_start();
$this->dependencies();
$source = $this->locate_source( $plugin );
$this->installer = new Jet_Plugins_Wizard_Plugin_Upgrader(
new Jet_Plugins_Wizard_Plugin_Upgrader_Skin(
array(
'url' => false,
'plugin' => $plugin['slug'],
'source' => $plugin['source'],
'title' => $plugin['name'],
)
)
);
$installed = $this->installer->install( $source );
$this->log = ob_get_clean();
$plugin_activate = $this->installer->plugin_info();
/**
* Hook fires after plugin installation but before activation.
*
* @param array $plugin Plugin data array.
*/
do_action( 'jet-plugins-wizard/after-plugin-install', $plugin );
if ( false !== $activate ) {
$this->activate_plugin( $plugin_activate, $plugin['slug'] );
}
/**
* Hook fires after plugin activation.
*
* @param array $plugin Plugin data array.
*/
do_action( 'jet-plugins-wizard/after-plugin-activation', $plugin );
return $installed;
}
/**
* Activate plugin.
*
* @param string $activation_data Activation data.
* @param string $slug Plugin slug.
* @return WP_Error|null
*/
public function activate_plugin( $activation_data, $slug ) {
if ( ! empty( $activation_data ) ) {
$activate = activate_plugin( $activation_data );
return $activate;
}
$all_plugins = get_plugins();
if ( empty( $all_plugins ) ) {
return null;
}
$all_plugins = array_keys( $all_plugins );
foreach ( $all_plugins as $plugin ) {
if ( false === strpos( $plugin, $slug ) ) {
continue;
}
if ( ! is_plugin_active( $plugin ) ) {
$activate = activate_plugin( $plugin );
return $activate;
}
}
return null;
}
/**
* Returns plugin installation source URL.
*
* @param array $plugin Plugin data.
* @return string
*/
public function locate_source( $plugin = array() ) {
$source = isset( $plugin['source'] ) ? $plugin['source'] : 'wordpress';
$result = false;
switch ( $source ) {
case 'wordpress':
require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; // Need for plugins_api
$api = plugins_api(
'plugin_information',
array( 'slug' => $plugin['slug'], 'fields' => array( 'sections' => false ) )
);
if ( is_wp_error( $api ) ) {
wp_die( $this->installer->strings['oops'] . var_dump( $api ) );
}
if ( isset( $api->download_link ) ) {
$result = $api->download_link;
}
break;
case 'local':
$result = ! empty( $plugin['path'] ) ? $plugin['path'] : false;
break;
case 'remote':
$result = ! empty( $plugin['path'] ) ? esc_url( $plugin['path'] ) : false;
break;
case 'crocoblock':
if ( jet_plugins_wizard_license()->is_enabled() ) {
$api_url = jet_plugins_wizard_settings()->get( array( 'license', 'server' ) );
$result = add_query_arg(
array(
'ct_api_action' => 'get_plugin',
'license' => jet_plugins_wizard_license()->get_license(),
'url' => urlencode( home_url( '/' ) ),
'slug' => $plugin['slug'],
),
$api_url
);
}
break;
}
return $result;
}
/**
* Include dependencies.
*
* @return void
*/
public function dependencies() {
if ( ! class_exists( 'Plugin_Upgrader', false ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
}
require_once jet_plugins_wizard()->path( 'includes/class-jet-plugins-wizard-plugin-upgrader-skin.php' );
require_once jet_plugins_wizard()->path( 'includes/class-jet-plugins-wizard-plugin-upgrader.php' );
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Plugins_Wizard_Installer
*
* @return object
*/
function jet_plugins_wizard_installer() {
return Jet_Plugins_Wizard_Installer::get_instance();
}
jet_plugins_wizard_installer();

View File

@@ -0,0 +1,469 @@
<?php
/**
* Plugins installation manager
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Plugins_Wizard_Interface' ) ) {
/**
* Define Jet_Plugins_Wizard_Interface class
*/
class Jet_Plugins_Wizard_Interface {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Holder for skins list.
*
* @var array
*/
private $skins = null;
/**
* Holder for current skin data.
*
* @var array
*/
private $skin = null;
/**
* Constructor for the class
*/
function __construct() {
add_action( 'admin_menu', array( $this, 'menu_page' ) );
add_action( 'admin_footer', array( $this, 'item_template' ) );
add_filter( 'jet-data-importer/tabs-menu-visibility', array( $this, 'import_tabs_visibility' ) );
}
/**
* Disable tabs on import page if we came from wizard.
*
* @param bool $is_visible Default visibility.
* @return bool
*/
public function import_tabs_visibility( $is_visible = true ) {
if ( ! empty( $_GET['referrer'] ) && 'jet-plugins-wizard' === $_GET['referrer'] ) {
return false;
}
return $is_visible;
}
/**
* Register wizard page
*
* @return void
*/
public function menu_page() {
add_menu_page(
esc_html__( 'Plugins Installation Wizard', 'jet-plugins-wizard' ),
esc_html__( 'Plugins Wizard', 'jet-plugins-wizard' ),
'manage_options',
jet_plugins_wizard()->slug(),
array( $this, 'render_plugin_page' ),
'dashicons-flag',
75
);
}
/**
* Render plugin page
*
* @return void
*/
public function render_plugin_page() {
jet_plugins_wizard()->get_template( 'page-header.php' );
$this->dispatch();
jet_plugins_wizard()->get_template( 'page-footer.php' );
}
/**
* Print JS item template
*
* @return void
*/
public function item_template() {
if ( empty( $_GET['page'] ) || jet_plugins_wizard()->slug() !== $_GET['page'] ) {
return;
}
printf(
'<script type="text/html" id="tmpl-wizard-item">%1$s</script>',
$this->get_item( '{{{data.slug}}}', '{{{data.name}}}' )
);
}
/**
* Get plugin installation notice
*
* @param string $slug Plugin slug.
* @param string $name Plugin name.
* @return string
*/
public function get_item( $slug, $name ) {
ob_start();
$wizard_item = jet_plugins_wizard()->get_template( 'plugin-item.php' );
$item = ob_get_clean();
return sprintf( $item, $slug, $name, $this->get_loader() );
}
/**
* Get loader HTML
*
* @return string
*/
public function get_loader() {
ob_start();
jet_plugins_wizard()->get_template( 'loader.php' );
return ob_get_clean();
}
/**
* Process wizard steps
*
* @return void
*/
public function dispatch() {
$step = ! empty( $_GET['step'] ) ? $_GET['step'] : 0;
$dispatch = apply_filters( 'jet-plugins-wizard/steps', array(
'configure-plugins' => 'step-configure-plugins.php',
'0' => 'step-service-notice.php',
'1' => 'step-before-install.php',
'2' => 'step-select-type.php',
'3' => 'step-install.php',
'4' => 'step-after-install.php',
), $step );
do_action( 'jet-plugins-wizards/page-before' );
if ( isset( $dispatch[ $step ] ) ) {
jet_plugins_wizard()->get_template( $dispatch[ $step ] );
}
do_action( 'jet-plugins-wizards/page-after' );
}
/**
* Show before import page title
*
* @return void
*/
public function before_import_title() {
$skins = $this->get_skins();
if ( empty( $skins ) ) {
esc_html_e( 'No data found for installation', 'jet-plugins-wizard' );
} elseif ( 1 === count( $skins ) ) {
esc_html_e( 'Start install', 'jet-plugins-wizard' );
} else {
esc_html_e( 'Select skin and start install', 'jet-plugins-wizard' );
}
}
/**
* Return available skins list
*
* @return array
*/
public function get_skins() {
if ( ! empty( $this->skins ) ) {
return $this->skins;
}
$this->skins = jet_plugins_wizard_settings()->get( array( 'skins', 'advanced' ) );
return $this->skins;
}
/**
* Setup processed skin data
*
* @param string $slug Skin slug.
* @param array $data Skin data.
* @return void
*/
public function the_skin( $slug = null, $data = array() ) {
$data['slug'] = $slug;
$this->skin = $data;
}
/**
* Retrun processed skin data
*
* @return array
*/
public function get_skin() {
return $this->skin;
}
/**
* Get info by current screen.
*
* @param string $key Key name.
* @return mixed
*/
public function get_skin_data( $key = null ) {
if ( empty( $this->skin ) ) {
$skin = isset( $_GET['skin'] ) ? esc_attr( $_GET['skin'] ) : false;
if ( ! $skin ) {
return false;
}
$data = jet_plugins_wizard_settings()->get( array( 'skins', 'advanced', $skin ) );
$this->the_skin( $skin, $data );
}
if ( empty( $this->skin[ $key ] ) ) {
return false;
}
return $this->skin[ $key ];
}
/**
* Returns skin plugins list
*
* @param string $slug Skin name.
* @return string
*/
public function get_skin_plugins( $slug = null ) {
$skins = $this->get_skins();
$skin = isset( $skins[ $slug ] ) ? $skins[ $slug ] : false;
if ( ! $skin ) {
return '';
}
$plugins = $skin[ 'full' ];
if ( empty( $plugins ) ) {
return '';
}
$registered = jet_plugins_wizard_settings()->get( array( 'plugins' ) );
$plugins_str = '';
$format = '<div class="jet-plugins-wizard-skin-plugins__item">%s</div>';
foreach ( $plugins as $plugin ) {
$plugin_data = isset( $registered[ $plugin ] ) ? $registered[ $plugin ] : false;
if ( ! $plugin_data ) {
continue;
}
$plugins_str .= sprintf( $format, $plugin_data['name'] );
}
return $plugins_str;
}
/**
* Return value from ini_get and ensure thats it integer.
*
* @param string $key Key to retrieve from ini_get.
* @return int
*/
public function ini_get_int( $key = null ) {
$val = ini_get( $key );
return intval( $val );
}
/**
* Validae server requirements.
*
* @return string
*/
public function server_notice( $when = 'always' ) {
$data = array(
array(
'arg' => null,
'_cb' => 'phpversion',
'rec' => '5.4',
'units' => null,
'name' => esc_html__( 'PHP version', 'jet-plugins-wizard' ),
'compare' => 'version_compare',
),
array(
'arg' => 'memory_limit',
'_cb' => array( $this, 'ini_get_int' ),
'rec' => 128,
'units' => 'Mb',
'name' => esc_html__( 'Memory limit', 'jet-plugins-wizard' ),
'compare' => array( $this, 'val_compare' ),
),
array(
'arg' => 'max_execution_time',
'_cb' => 'ini_get',
'rec' => 60,
'units' => 's',
'name' => esc_html__( 'Max execution time', 'jet-plugins-wizard' ),
'compare' => array( $this, 'val_compare' ),
),
);
$format = '<li class="jet-plugins-wizard-server__item%5$s">%1$s: %2$s%3$s &mdash; <b>%4$s</b></li>';
$result = '';
$has_errors = false;
foreach ( $data as $prop ) {
if ( null !== $prop['arg'] ) {
$val = call_user_func( $prop['_cb'], $prop['arg'] );
} else {
$val = call_user_func( $prop['_cb'] );
}
$compare = call_user_func( $prop['compare'], $val, $prop['rec'] );
if ( -1 === $compare ) {
$msg = sprintf( esc_html__( '%1$s%2$s Recommended', 'jet-plugins-wizard' ), $prop['rec'], $prop['units'] );
$scs = '';
$has_errors = true;
$this->set_wizard_errors( $prop['arg'] );
} else {
$msg = esc_html__( 'Ok', 'jet-plugins-wizard' );
$scs = ' check-success';
}
$result .= sprintf( $format, $prop['name'], $val, $prop['units'], $msg, $scs );
}
if ( 'always' === $when ) {
return sprintf( '<ul class="jet-plugins-wizard-server">%s</ul>', $result );
}
if ( 'errors' === $when && $has_errors ) {
$message = sprintf(
'<div class="jet-plugins-wizard-server-error">%1$s</div>',
__( 'Not all of your server parameters met requirements. You can continue the installation process, but it will take more time and can probably drive to bugs:', 'jet-plugins-wizard' )
);
return sprintf( '%2$s<ul class="jet-plugins-wizard-server">%1$s</ul>', $result, $message );
}
}
/**
* Save wizard error.
*
* @param string $arg Norie to ada
*/
public function set_wizard_errors( $arg = null ) {
$errors = wp_cache_get( 'errors', 'jet-plugins-wizard' );
if ( ! $errors ) {
$errors[ $arg ] = $arg;
}
wp_cache_set( 'errors', $errors, 'jet-plugins-wizard' );
}
/**
* Compare 2 values.
*
* @return int
*/
public function val_compare( $a, $b ) {
$a = intval( $a );
$b = intval( $b );
if ( $a > $b ) {
return 1;
}
if ( $a === $b ) {
return 0;
}
if ( $a < $b ) {
return -1;
}
}
/**
* Returns start skin installation button HTML.
*
* @param string $skin Skin slug.
* @return string
*/
public function get_install_skin_button( $skin = '' ) {
$url = jet_plugins_wizard()->get_page_link( array( 'step' => 2, 'skin' => $skin ) );
$label = esc_html__( 'Select Skin', 'jet-plugins-wizard' );
$format = '<a href="%1$s" data-loader="true" class="btn btn-primary"><span class="text">%2$s</span><span class="jet-plugins-wizard-loader"><span class="jet-plugins-wizard-loader__spinner"></span></span></a>';
if ( jet_plugins_wizard_data()->is_single_skin_theme() || jet_plugins_wizard_data()->is_single_type_skin( $skin ) ) {
$label = esc_html__( 'Start Install', 'jet-plugins-wizard' );
}
if ( jet_plugins_wizard_data()->is_single_type_skin( $skin ) ) {
$next_step = isset( $_GET['advanced-install'] ) && '1' === $_GET['advanced-install'] ? 'configure-plugins' : 3;
$url = jet_plugins_wizard()->get_page_link( array( 'step' => $next_step, 'skin' => $skin, 'type' => 'full' ) );
}
return sprintf( $format, $url, $label );
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Plugins_Wizard_Interface
*
* @return object
*/
function jet_plugins_wizard_interface() {
return Jet_Plugins_Wizard_Interface::get_instance();
}
jet_plugins_wizard_interface();

View File

@@ -0,0 +1,304 @@
<?php
/**
* Class description
*
* @package package_name
* @author Cherry Team
* @license GPL-2.0+
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Plugins_Wizard_License' ) ) {
/**
* Define Jet_Plugins_Wizard_License class
*/
class Jet_Plugins_Wizard_License {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* OPtion name to store license key in.
*
* @var string
*/
public $license_option = 'jet_theme_core_license';
/**
* License checking status
*
* @var boolean
*/
private $is_enabled = null;
/**
* Constructor for the class
*/
public function __construct() {
if ( ! $this->is_enabled() ) {
return;
}
add_filter( 'jet-plugins-wizard/steps', array( $this, 'replace_zero_step' ), 10, 2 );
add_filter( 'jet-plugins-wizard/js-settings', array( $this, 'add_license_strings' ) );
add_action( 'wp_ajax_jet_plugins_wizard_activate_license', array( $this, 'activate_license' ) );
}
/**
* Retuirn license
*
* @return [type] [description]
*/
public function get_license() {
return get_option( $this->license_option );
}
/**
* Check if license is already active
*
* @return boolean
*/
public function is_active() {
$license = get_option( $this->license_option );
if ( ! $license ) {
return false;
}
$response = $this->license_request( 'check_license', $license );
$result = wp_remote_retrieve_body( $response );
$result = json_decode( $result, true );
if ( ! isset( $result['success'] ) ) {
return false;
}
if ( true === $result['success'] && 'valid' === $result['license'] ) {
return true;
} else {
return false;
}
}
/**
* Perform a remote request with passed action for passed license key
*
* @param string $action EDD action to perform (activate_license, check_license etc)
* @param string $license License key
* @return WP_Error|array
*/
public function license_request( $action, $license ) {
$api_url = jet_plugins_wizard_settings()->get( array( 'license', 'server' ) );
if ( ! $api_url ) {
wp_send_json_error( array(
'errorMessage' => __( 'Sorry, license API is disabled', 'jet-plugins-wizard' ),
) );
}
$item_id = jet_plugins_wizard_settings()->get( array( 'license', 'item_id' ) );
$url = add_query_arg(
array(
'edd_action' => $action,
'item_id' => $item_id,
'license' => $license,
'url' => urlencode( home_url( '/' ) ),
),
$api_url
);
$args = array(
'timeout' => 60,
'sslverify' => false
);
return wp_remote_get( $url, $args );
}
/**
* Activate license.
*
* @return void
*/
public function activate_license() {
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( array(
'errorMessage' => __( 'Sorry, you not allowed to activate license', 'jet-plugins-wizard' ),
) );
}
$license = isset( $_REQUEST['license'] ) ? esc_attr( $_REQUEST['license'] ) : false;
if ( ! $license ) {
wp_send_json_error( array(
'errorMessage' => __( 'Please provide valid license key', 'jet-plugins-wizard' ),
) );
}
$response = $this->license_request( 'activate_license', $license );
$result = wp_remote_retrieve_body( $response );
$result = json_decode( $result, true );
if ( ! isset( $result['success'] ) ) {
wp_send_json_error( array(
'errorMessage' => __( 'Internal error, please try again later.', 'jet-plugins-wizard' ),
) );
}
if ( true === $result['success'] ) {
if ( 'valid' === $result['license'] ) {
update_option( $this->license_option, $license, 'no' );
ob_start();
printf(
'<div class="jet-plugins-wizard-msg">%1$s</div>',
__( 'Thanks for license activation. Press Next to continue installation.', 'jet-plugins-wizard' )
);
jet_plugins_wizard()->get_template( 'start-install-button.php' );
wp_send_json_success( array( 'replaceWith' => ob_get_clean() ) );
} else {
wp_send_json_error( array(
'errorMessage' => $this->get_error_by_code( 'default' ),
) );
}
} else {
if ( ! empty( $result['error'] ) ) {
wp_send_json_error( array(
'errorMessage' => $this->get_error_by_code( $result['error'] ),
) );
} else {
wp_send_json_error( array(
'errorMessage' => $this->get_error_by_code( 'default' ),
) );
}
}
}
/**
* Retrirve error message by error code
*
* @return string
*/
public function get_error_by_code( $code ) {
$messages = array(
'missing' => __( 'Your license is missing. Please check your key again.', 'jet-plugins-wizard' ),
'no_activations_left' => __( '<strong>You have no more activations left.</strong> Please upgrade to a more advanced license (you\'ll only need to cover the difference).', 'jet-plugins-wizard' ),
'expired' => __( '<strong>Your License Has Expired.</strong> Renew your license today to keep getting feature updates, premium support and unlimited access to the template library.', 'jet-plugins-wizard' ),
'revoked' => __( '<strong>Your license key has been cancelled</strong> (most likely due to a refund request). Please consider acquiring a new license.', 'jet-plugins-wizard' ),
'disabled' => __( '<strong>Your license key has been cancelled</strong> (most likely due to a refund request). Please consider acquiring a new license.', 'jet-plugins-wizard' ),
'invalid' => __( '<strong>Your license key doesn\'t match your current domain</strong>. This is most likely due to a change in the domain URL of your site (including HTTPS/SSL migration). Please deactivate the license and then reactivate it again.', 'jet-plugins-wizard' ),
'site_inactive' => __( '<strong>Your license key doesn\'t match your current domain</strong>. This is most likely due to a change in the domain URL. Please deactivate the license and then reactivate it again.', 'jet-plugins-wizard' ),
'inactive' => __( '<strong>Your license key doesn\'t match your current domain</strong>. This is most likely due to a change in the domain URL of your site (including HTTPS/SSL migration). Please deactivate the license and then reactivate it again.', 'jet-plugins-wizard' ),
);
$default = __( 'An error occurred. Please check your internet connection and try again. If the problem persists, contact our support.', 'jet-plugins-wizard' );
return isset( $messages[ $code ] ) ? $messages[ $code ] : $default;
}
/**
* Add licesne texts into localize object
*
* @param array $data [description]
* @return array
*/
public function add_license_strings( $data = array() ) {
$data['license'] = array(
'empty' => __( 'Please enter your license', 'jet-plugins-wizard' ),
);
return $data;
}
/**
* Replace welcome step with activate license step.
*
* @param array $steps Default stepa data
* @return array
*/
public function replace_zero_step( $steps, $step ) {
if ( 'configure-plugins' === $step || 0 !== absint( $step ) ) {
return $steps;
}
if ( $this->is_active() ) {
return $steps;
}
$steps[0] = 'step-activate-licesne.php';
return $steps;
}
/**
* Is license checking enabled or not
*
* @return boolean [description]
*/
public function is_enabled() {
if ( null !== $this->is_enabled ) {
return $this->is_enabled;
}
$this->is_enabled = jet_plugins_wizard_settings()->get( array( 'license', 'enabled' ) );
return $this->is_enabled;
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Plugins_Wizard_License
*
* @return object
*/
function jet_plugins_wizard_license() {
return Jet_Plugins_Wizard_License::get_instance();
}

View File

@@ -0,0 +1,144 @@
<?php
/**
* Plugin installer skin class.
*/
if ( ! defined( 'WPINC' ) ) {
die;
}
class Jet_Plugins_Wizard_Plugin_Upgrader_Skin extends Plugin_Installer_Skin {
/**
* Holder for installation source type.
*
* @var string
*/
public $source = 'wordpress';
/**
* Result type
*
* @var string
*/
public $result_type = 'success';
/**
* Construtor for the class.
*
* @param array $args Options array.
*/
public function __construct( $args = array() ) {
$this->source = isset( $args['source'] ) ? $args['source'] : $this->source;
parent::__construct( $args );
}
/**
* Output markup after plugin installation processed.
*/
public function after() {}
/**
* Output header markup.
*/
public function header() {
if ( $this->done_header ) {
return;
}
$this->done_header = true;
echo '<div class="jet-plugins-wizard-install-results">';
echo '<div class="jet-plugins-wizard-install-results__trigger">';
esc_html_e( 'Details', 'jet-plugins-wizard' );
echo '</div>';
echo '<ul>';
}
/**
* Output footer markup.
*/
public function footer() {
if ( $this->done_footer ) {
return;
}
$this->done_footer = true;
echo '</ul>';
echo '</div>';
}
/**
*
* @param string|WP_Error $errors
*/
public function error( $errors ) {
if ( ! $this->done_header ) {
$this->header();
}
if ( is_string( $errors ) ) {
$this->feedback( $errors );
} elseif ( is_wp_error( $errors ) && $errors->get_error_code() ) {
$this->set_result_type( $errors->errors );
foreach ( $errors->get_error_messages() as $message ) {
if ( $errors->get_error_data() && is_string( $errors->get_error_data() ) ) {
$this->feedback( $message . ' ' . esc_html( strip_tags( $errors->get_error_data() ) ) );
} else {
$this->feedback( $message );
}
}
}
}
/**
* Set warning or error result type.
*
* @param array $errors Errors array
*/
public function set_result_type( $errors ) {
if ( array_key_exists( 'folder_exists', $errors ) ) {
$this->result_type = 'warning';
} else {
$this->result_type = 'error';
}
}
/**
*
* @param string $string
*/
public function feedback( $string ) {
if ( isset( $this->upgrader->strings[ $string ] ) )
$string = $this->upgrader->strings[ $string ];
if ( false !== strpos( $string, '%' ) ) {
$args = func_get_args();
$args = array_splice( $args, 1 );
if ( $args ) {
$args = array_map( 'strip_tags', $args );
$args = array_map( 'esc_html', $args );
$string = vsprintf( $string, $args );
}
}
if ( empty( $string ) ) {
return;
}
if ( is_wp_error( $string ) ) {
if ( $string->get_error_data() && is_string( $string->get_error_data() ) ) {
$string = $string->get_error_message() . ': ' . $string->get_error_data();
} else {
$string = $string->get_error_message();
}
}
printf( '<li>%s</li>', $string );
}
}

View File

@@ -0,0 +1,194 @@
<?php
/**
* Plugin installer class.
*/
if ( ! defined( 'WPINC' ) ) {
die;
}
class Jet_Plugins_Wizard_Plugin_Upgrader extends Plugin_Upgrader {
private $source = null;
public function __construct( $skin = null ) {
$this->source = $skin->source;
parent::__construct( $skin );
}
/**
* Install a plugin package.
*
* @param string $package The full local path or URI of the package.
* @param array $args Optional arguments array.
* @return bool|WP_Error True if the install was successful, false or a WP_Error otherwise.
*/
public function install( $package, $args = array() ) {
$defaults = array(
'clear_update_cache' => true,
);
$parsed_args = wp_parse_args( $args, $defaults );
$this->init();
$this->install_strings();
add_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1, 3 );
add_filter( 'upgrader_source_selection', array( $this, 'check_package' ) );
if ( $parsed_args['clear_update_cache'] ) {
// Clear cache so wp_update_plugins() knows about the new plugin.
add_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9, 0 );
}
$this->run( array(
'package' => $package,
'destination' => WP_PLUGIN_DIR,
'clear_destination' => false, // Do not overwrite files.
'clear_working' => true,
'hook_extra' => array(
'type' => 'plugin',
'action' => 'install',
)
) );
remove_action( 'upgrader_process_complete', 'wp_clean_plugins_cache', 9 );
remove_filter( 'upgrader_source_selection', array( $this, 'check_package') );
remove_filter( 'upgrader_source_selection', array( $this, 'maybe_adjust_source_dir' ), 1 );
if ( ! $this->result || is_wp_error( $this->result ) ) {
return $this->result;
}
// Force refresh of plugin update information
wp_clean_plugins_cache( $parsed_args['clear_update_cache'] );
return true;
}
/**
* Adjust the plugin directory name if necessary.
*
* The final destination directory of a plugin is based on the subdirectory name found in the
* (un)zipped source. In some cases - most notably GitHub repository plugin downloads -, this
* subdirectory name is not the same as the expected slug and the plugin will not be recognized
* as installed. This is fixed by adjusting the temporary unzipped source subdirectory name to
* the expected plugin slug.
*
* @since 1.0.0
* @param string $source Path to upgrade/zip-file-name.tmp/subdirectory/.
* @param string $remote_source Path to upgrade/zip-file-name.tmp.
* @param \WP_Upgrader $upgrader Instance of the upgrader which installs the plugin.
* @return string $source
*/
public function maybe_adjust_source_dir( $source, $remote_source, $upgrader ) {
global $wp_filesystem;
if ( ! jet_plugins_wizard_installer()->is_wizard_request() || ! is_object( $wp_filesystem ) ) {
return $source;
}
// Check for single file plugins.
$source_files = array_keys( $wp_filesystem->dirlist( $remote_source ) );
if ( 1 === count( $source_files ) && false === $wp_filesystem->is_dir( $source ) ) {
return $source;
}
$desired_slug = isset( $upgrader->skin->options['plugin'] ) ? $upgrader->skin->options['plugin'] : false;
if ( ! $desired_slug ) {
return $source;
}
$subdir_name = untrailingslashit( str_replace( trailingslashit( $remote_source ), '', $source ) );
if ( ! empty( $subdir_name ) && $subdir_name !== $desired_slug ) {
$from_path = untrailingslashit( $source );
$to_path = trailingslashit( $remote_source ) . $desired_slug;
if ( true === $wp_filesystem->move( $from_path, $to_path ) ) {
return trailingslashit( $to_path );
} else {
return new WP_Error(
'rename_failed',
esc_html__( 'The remote plugin package does not contain a folder with the desired slug and renaming did not work.', 'jet-plugins-wizard' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'jet-plugins-wizard' ),
array( 'found' => $subdir_name, 'expected' => $desired_slug )
);
}
} elseif ( empty( $subdir_name ) ) {
return new WP_Error(
'packaged_wrong',
esc_html__( 'The remote plugin package consists of more than one file, but the files are not packaged in a folder.', 'jet-plugins-wizard' ) . ' ' . esc_html__( 'Please contact the plugin provider and ask them to package their plugin according to the WordPress guidelines.', 'jet-plugins-wizard' ),
array( 'found' => $subdir_name, 'expected' => $desired_slug )
);
}
return $source;
}
/**
* Grabs the plugin file from an installed plugin.
*
* @since 1.0.0
*/
public function plugin_info() {
/** Return false if installation result isn't an array or the destination name isn't set */
if ( ! is_array( $this->result ) ) {
return $this->maybe_get_data_from_error();
}
if ( empty( $this->result['destination_name'] ) ) {
return false;
}
/** Get the installed plugin file or return false if it isn't set */
$plugin = get_plugins( '/' . $this->result['destination_name'] );
if ( empty( $plugin ) ) {
return false;
}
/** Assume the requested plugin is the first in the list */
$pluginfiles = array_keys( $plugin );
return $this->result['destination_name'] . '/' . $pluginfiles[0];
}
/**
* Try to get plugin data from error
*
* @return string|bool
*/
public function maybe_get_data_from_error() {
if ( ! isset( $this->skin->result ) || ! is_wp_error( $this->skin->result ) ) {
return false;
}
if ( ! isset( $this->skin->result->error_data['folder_exists'] ) ) {
return false;
}
$path = $this->skin->result->error_data['folder_exists'];
if ( ! $path ) {
return false;
}
$plugin = basename( $path );
$plugin_data = get_plugins( '/' . $plugin );
if ( empty( $plugin_data ) ) {
return false;
}
/** Assume the requested plugin is the first in the list */
$pluginfiles = array_keys( $plugin_data );
return $plugin . '/' . $pluginfiles[0];
}
}

View File

@@ -0,0 +1,284 @@
<?php
/**
* Settings manager
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
if ( ! class_exists( 'Jet_Plugins_Wizard_Settings' ) ) {
/**
* Define Jet_Plugins_Wizard_Settings class
*/
class Jet_Plugins_Wizard_Settings {
/**
* A reference to an instance of this class.
*
* @since 1.0.0
* @var object
*/
private static $instance = null;
/**
* Manifest file content
*
* @var array
*/
private $all_settings = null;
/**
* External settings
*
* @var array
*/
private $external_settings = array();
/**
* Manifest defaults
*
* @var array
*/
private $defaults = null;
/**
* Has registered external config
*
* @var boolean
*/
private $has_external = false;
/**
* Get settings from array.
*
* @param array $settings Settings trail to get.
* @return mixed
*/
public function get( $settings = array() ) {
$all_settings = $this->get_all_settings();
if ( ! $all_settings ) {
return false;
}
if ( ! is_array( $settings ) ) {
$settings = array( $settings );
}
$count = count( $settings );
$result = $all_settings;
for ( $i = 0; $i < $count; $i++ ) {
if ( empty( $result[ $settings[ $i ] ] ) ) {
return false;
}
$result = $result[ $settings[ $i ] ];
if ( $count - 1 === $i ) {
return $result;
}
}
}
/**
* Check if is kava theme
*
* @return boolean [description]
*/
public function is_kava() {
if ( ! $this->has_external() ) {
return false;
}
if ( empty( $this->external_settings['plugins']['get_from'] ) ) {
return false;
}
$plugins_url = $this->external_settings['plugins']['get_from'];
if ( false === strpos( $plugins_url, 'account.crocoblock.com' ) ) {
return false;
} else {
return true;
}
}
/**
* Add new 3rd party configuration
* @param array $config [description]
* @return [type] [description]
*/
public function register_external_config( $config = array() ) {
$this->has_external = true;
$this->external_settings = array_merge( $this->external_settings, $config );
}
/**
* Return external config status
* @return boolean [description]
*/
public function has_external() {
return $this->has_external;
}
/**
* Get mainfest
*
* @return mixed
*/
public function get_all_settings() {
if ( null !== $this->all_settings ) {
return $this->all_settings;
}
$settings = $this->external_settings;
$all_settings = array(
'license' => isset( $settings['license'] ) ? $settings['license'] : $this->get_defaults( 'license' ),
'plugins' => isset( $settings['plugins'] ) ? $settings['plugins'] : $this->get_defaults( 'plugins' ),
'skins' => isset( $settings['skins'] ) ? $settings['skins'] : $this->get_defaults( 'skins' ),
'texts' => isset( $settings['texts'] ) ? $settings['texts'] : $this->get_defaults( 'texts' ),
);
$this->all_settings = $this->maybe_update_remote_data( $all_settings );
return $this->all_settings;
}
/**
* Maybe update remote settings data
*
* @param array $settings Plugins settings
* @return array
*/
public function maybe_update_remote_data( $settings ) {
if ( ! empty( $settings['plugins']['get_from'] ) ) {
$settings['plugins'] = $this->get_remote_data( $settings['plugins']['get_from'], 'jet_wizard_plugins' );
}
if ( ! empty( $settings['skins']['get_from'] ) ) {
$settings['skins'] = $this->get_remote_data( $settings['skins']['get_from'], 'jet_wizard_skins' );
}
return $settings;
}
/**
* Get remote data for wizard
*
* @param [type] $url [description]
* @param [type] $transient_key [description]
* @return [type] [description]
*/
public function get_remote_data( $url, $transient_key ) {
$data = get_site_transient( $transient_key );
if ( $this->has_external() ) {
$data = false;
}
if ( ! $data ) {
$response = wp_remote_get( $url, array(
'timeout' => 60,
'sslverify' => false,
) );
$data = wp_remote_retrieve_body( $response );
$data = json_decode( $data, true );
if ( empty( $data ) ) {
$data = array();
}
if ( ! $this->has_external() ) {
set_site_transient( $transient_key, $data, 2 * DAY_IN_SECONDS );
}
}
return $data;
}
/**
* Clear transien data cahces
*
* @return [type] [description]
*/
public function clear_transient_data() {
set_site_transient( 'jet_wizard_plugins', null );
set_site_transient( 'jet_wizard_skins', null );
}
/**
* Get wizard defaults
*
* @param string $part What part of manifest to get (optional - if empty return all)
* @return array
*/
public function get_defaults( $part = null ) {
if ( null === $this->defaults ) {
include jet_plugins_wizard()->path( 'includes/config/default-config.php' );
$this->defaults = array(
'license' => $license,
'plugins' => $plugins,
'skins' => $skins,
'texts' => $texts,
);
}
if ( ! $part ) {
return $this->defaults;
}
if ( isset( $this->defaults[ $part ] ) ) {
return $this->defaults[ $part ];
}
return array();
}
/**
* Returns the instance.
*
* @since 1.0.0
* @return object
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
}
}
/**
* Returns instance of Jet_Plugins_Wizard_Settings
*
* @return object
*/
function jet_plugins_wizard_settings() {
return Jet_Plugins_Wizard_Settings::get_instance();
}

View File

@@ -0,0 +1,67 @@
<?php
$license = array(
'enabled' => true,
'server' => 'https://account.crocoblock.com/',
'item_id' => 9,
);
/**
* Plugins configuration example.
*
* array(
'cherry-services-list' => array(
'name' => esc_html__( 'Cherry Services List', 'jet-plugins-wizard' ),
'sourse' => 'wordpress', // 'git', 'local', 'remote', 'wordpress' (default).
'path' => false, // git repository, remote URL or local path.
'access' => 'skins',
),
'cherry-data-importer' => array(
'name' => esc_html__( 'Cherry Data Importer', 'jet-plugins-wizard' ),
'sourse' => 'git', // 'git', 'local', 'remote', 'wordpress' (default).
'path' => false, // git repository, remote URL or local path.
'access' => 'base',
),
)
* or 'get_from_api' => URL
*
* @var array
*/
$plugins = array(
'get_from' => 'https://account.crocoblock.com/wp-content/uploads/static/wizard-plugins.json',
);
/**
* Skins configuration example
* Format:
* array(
'base' => array(
'cherry-data-importer',
),
'skins' => array(
'default' => array(
'full' => array(
'cherry-services-list',
),
'lite' => false,
'demo' => false,
'thumb' => false,
'name' => esc_html__( 'Default', 'jet-plugins-wizard' ),
),
),
)
* or 'get_from_api' => URL
* @var array
*/
$skins = array(
'get_from' => 'https://account.crocoblock.com/wp-content/uploads/static/wizard-skins.json',
);
/**
* Default plugin texts
*
* @var array
*/
$texts = array(
'theme-name' => 'Kava'
);