'ikreate-demo-importer',
'name' => 'Ikreate Demo Importer',
'source' => 'https://ikreatethemes.com/ikreate-demo-importer.zip'
);
/**
* @var Ikreate_Demo_Importer
*
* @since 1.0.0
*/
private $plugin = null;
/**
* Redirect.
*
* @param $url
*
* @since 1.0.0
*
*/
private static function business_roy_redirect( $url ) {
if ( headers_sent() ) {
echo "";
} else {
wp_redirect( $url );
}
exit();
}
/**
* Constructor for the Welcome Screen
*/
public function __construct() {
/** Useful Variables */
$theme = wp_get_theme();
$this->theme_name = $theme->Name;
$this->theme_version = $theme->Version;
/** Define Tabs Sections */
$this->tab_sections = array(
'getting_started' => esc_html__('Getting Started', 'business-roy'),
'recommended_plugins' => esc_html__('Recommended Plugins', 'business-roy'),
'support' => esc_html__('Support', 'business-roy'),
'free_vs_pro' => esc_html__('Free Vs Pro', 'business-roy')
);
/** List of Recommended Free Plugins **/
$this->free_plugins = array(
'elementor' => array(
'name' => 'Elementor Page Builder',
'slug' => 'elementor',
'filename' => 'elementor',
'thumb_path' => 'https://ps.w.org/elementor/assets/icon-256x256.png'
),
'contact-form-7' => array(
'name' => 'Contact Form 7',
'slug' => 'contact-form-7',
'filename' => 'contact-form-7',
'thumb_path' => 'https://ps.w.org/contact-form-7/assets/icon.svg?rev=2339255'
),
'simple-floating-menu' => array(
'name' => 'Simple Floating Menu',
'slug' => 'simple-floating-menu',
'filename' => 'simple-floating-menu',
'thumb_path' => 'https://ps.w.org/simple-floating-menu/assets/icon-256x256.png'
)
);
/* Create a Welcome Page */
add_action('admin_menu', array($this, 'welcome_register_menu'));
/* Enqueue Styles & Scripts for Welcome Page */
add_action('admin_enqueue_scripts', array($this, 'welcome_styles_and_scripts'));
/* Adds Footer Rating Text */
add_filter('admin_footer_text', array($this, 'admin_footer_text'));
/* Hide Notice */
add_filter('wp_loaded', array($this, 'hide_admin_notice'), 10);
/* Create a Welcome Page */
add_action('wp_loaded', array($this, 'admin_notice'), 20);
add_action('after_switch_theme', array($this, 'erase_hide_notice'));
add_action('wp_ajax_business_roy_activate_plugin', array($this, 'activate_plugin'));
add_action( 'wp_ajax_thim_core_installer', array( $this, 'business_roy_ajax_install' ) );
//add_action( 'admin_notices', array( $this, 'notice_install' ) );
add_action( 'business_roy_installer_step_start', array( $this, 'business_roy_prepare_installation' ) );
add_action( 'business_roy_installer_step_install', array( $this, 'business_roy_step_install' ) );
add_action( 'business_roy_installer_step_activate', array( $this, 'business_roy_step_activate' ) );
}
/** Trigger Welcome Message Notification */
public function admin_notice($hook) {
$hide_notice = get_option('business_roy_hide_notice');
if (!$hide_notice) {
add_action('admin_notices', array($this, 'admin_notice_content'));
}
}
/** Welcome Message Notification */
public function admin_notice_content() {
$screen = get_current_screen();
if ('appearance_page_business_roy-welcome' === $screen->id || (isset($screen->parent_file) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id) || 'theme-install' === $screen->id) {
return;
}
$slug = $filename = 'elementor';
?>
theme_name); ?>
business_roy_setup_content(); ?>
tab_sections;
?>
esc_html__('Installing Demo Importer Plugin', 'business-roy'),
'activating_text' => esc_html__('Activating Demo Importer Plugin', 'business-roy'),
'importer_page' => esc_html__('Go to Demo Importer Page', 'business-roy'),
'importer_url' => admin_url('themes.php?page=elementor'),
'error' => esc_html__('Error! Reload the page and try again.', 'business-roy'),
);
wp_enqueue_style('business-roy-welcome', get_template_directory_uri() . '/inc/welcome/css/welcome.css', array());
wp_enqueue_script('business-roy-welcome', get_template_directory_uri() . '/inc/welcome/js/welcome.js', array('plugin-install', 'updates'), '', true);
wp_localize_script('business-roy-welcome', 'importer_params', $importer_params);
}
}
/* Check if plugin is installed */
public function check_plugin_installed_state($slug, $filename) {
return file_exists(ABSPATH . 'wp-content/plugins/' . $slug . '/' . $filename . '.php') ? true : false;
}
/* Check if plugin is activated */
public function check_plugin_active_state($slug, $filename) {
return is_plugin_active($slug . '/' . $filename . '.php') ? true : false;
}
/** Generate Url for the Plugin Button */
public function plugin_generate_url($status, $slug, $file_name) {
switch ($status) {
case 'install':
return wp_nonce_url(add_query_arg(array(
'action' => 'install-plugin',
'plugin' => esc_attr($slug)
), network_admin_url('update.php')), 'install-plugin_' . esc_attr($slug));
break;
case 'inactive':
return add_query_arg(array(
'action' => 'deactivate',
'plugin' => rawurlencode(esc_attr($slug) . '/' . esc_attr($file_name) . '.php'),
'plugin_status' => 'all',
'paged' => '1',
'_wpnonce' => wp_create_nonce('deactivate-plugin_' . esc_attr($slug) . '/' . esc_attr($file_name) . '.php'),
), network_admin_url('plugins.php'));
break;
case 'active':
return add_query_arg(array(
'action' => 'activate',
'plugin' => rawurlencode(esc_attr($slug) . '/' . esc_attr($file_name) . '.php'),
'plugin_status' => 'all',
'paged' => '1',
'_wpnonce' => wp_create_nonce('activate-plugin_' . esc_attr($slug) . '/' . esc_attr($file_name) . '.php'),
), network_admin_url('plugins.php'));
break;
}
}
/** Ajax Plugin Activation */
public function activate_plugin() {
$slug = isset($_POST['slug']) ? $_POST['slug'] : '';
$file = isset($_POST['file']) ? $_POST['file'] : '';
$success = false;
if (!empty($slug) && !empty($file)) {
//patterns-plugin-activate
//activate_plugin('patterns-kit/plugins.php');
$result = activate_plugin($slug . '/' . $file . '.php');
update_option('business_roy_hide_notice', true);
if (!is_wp_error($result)) {
$success = true;
}
}
echo wp_json_encode(array('success' => $success));
die();
}
/** Adds Footer Notes */
public function admin_footer_text($text) {
$screen = get_current_screen();
if ('toplevel_page_business-roy-welcome' == $screen->id) {
$text = sprintf(esc_html__('Please leave us a %s rating if you like our theme . A huge thank you from ikreate themes in advance!', 'business-roy'), '★★★★★');
}
return $text;
}
public function erase_hide_notice() {
delete_option('business_roy_hide_notice');
}
//........................
/**
* Get object plugin Thim Core.
*
* @return Business_Roy_Plugin
* @since 1.0.0
*
*/
private function business_roy_get_thim_core() {
if ( $this->plugin === null ) {
$plugin = new Business_Roy_Plugin();
$plugin->set_args( $this->package );
$this->plugin = $plugin;
}
return $this->plugin;
}
/**
* Get link step.
*
* @param string $step
*
* @return string
* @since 1.0.0
*
*/
private function business_roy_get_link_step( $step = '' ) {
return add_query_arg( array( 'step' => $step ) );
}
/**
* Handle ajax.
*
* @since 1.0.0
*/
public function business_roy_ajax_install() {
$plugin = $this->business_roy_get_thim_core();
$result = $plugin->install();
if ( ! $result ) {
wp_send_json_error( $plugin->get_messages() );
}
wp_send_json_success( $plugin->get_messages() );
}
/**
* Setup content.
*
* @since 1.0.0
*/
private function business_roy_setup_content() {
$thim_core = $this->business_roy_get_thim_core();
$status = $thim_core->get_status();
$step = isset( $_REQUEST['step'] ) ? $_REQUEST['step'] : 'start';
?>
business_roy_get_thim_core();
$status = $thim_core->get_status();
$step = ( $status == 'inactive' ) ? 'activate' : 'install';
$link = $this->business_roy_get_link_step( $step );
if ( $status == 'inactive' ) {
$import_class = 'button button-primary';
$import_button_text = esc_html__('Activate Demo Importer Plugin', 'business-roy');
} elseif ( $status == 'active' ) {
$import_class = 'button button-primary';
$import_button_text = esc_html__('Go to Demo Importer Page', 'business-roy');
$link = admin_url( '/themes.php?page=ikreatethemes-demo-importer' );
} else {
$import_class = 'thim-button-link button button-primary';
$import_button_text = esc_html__('Install Demo Importer Plugin', 'business-roy');
}
?>
>
business_roy_get_link_step( 'activate' );
$plugin = $this->business_roy_get_thim_core();
$status = $plugin->get_status();
if ( $status != 'not_installed' ) {
self::business_roy_redirect( $link );
}
$result = $plugin->install();
$messages = $plugin->get_messages();
$notice = $result ? 'success' : 'error';
?>
>
business_roy_get_thim_core();
if ( $plugin->activate( true ) || $plugin->is_active() ) {
$this->business_roy_redirect_dashboard();
return;
}
}
/**
* Reload to redirect to theme dashboard.
*
* @since 1.0.0
*/
private function business_roy_redirect_dashboard() {
$url = admin_url( 'themes.php?page=ikreatethemes-demo-importer' );
self::business_roy_redirect( $url );
}
}
new BusinessRoy_Welcome();
endif;