theme_name = $theme->Name;
$this->theme_version = $theme->Version;
/** Define Tabs Sections */
$this->tab_sections = array(
'getting_started' => esc_html__('Getting Started', 'sparklestore'),
'recommended_plugins' => esc_html__('Recommended Plugins', 'sparklestore'),
'support' => esc_html__('Support', 'sparklestore'),
'free_vs_pro' => esc_html__('Free Vs Pro', 'sparklestore')
);
/** List of Recommended Free Plugins */
/** List of Recommended Free Plugins **/
$this->free_plugins = array(
'woocommerce' => array(
'name' => 'WooCommerce',
'slug' => 'woocommerce',
'filename' => 'woocommerce',
'thumb_path' => 'https://ps.w.org/woocommerce/assets/icon-256x256.png'
),
'elementor' => array(
'name' => 'Elementor Website 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'
),
'yith-woocommerce-quick-view' => array(
'name' => 'YITH WooCommerce Quick View',
'slug' => 'yith-woocommerce-quick-view',
'filename' => 'yith-woocommerce-quick-view',
'thumb_path' => 'https://ps.w.org/yith-woocommerce-quick-view/assets/icon-128x128.jpg?rev=1460911'
),
'yith-woocommerce-compare' => array(
'name' => 'YITH WooCommerce Compare',
'slug' => 'yith-woocommerce-compare',
'filename' => 'yith-woocommerce-compare',
'thumb_path' => 'https://ps.w.org/yith-woocommerce-compare/assets/icon-128x128.jpg?rev=1460911'
),
'yith-woocommerce-wishlist' => array(
'name' => 'YITH WooCommerce Wishlist',
'slug' => 'yith-woocommerce-wishlist',
'filename' => 'yith-woocommerce-wishlist',
'thumb_path' => 'https://ps.w.org/yith-woocommerce-wishlist/assets/icon-128x128.jpg?rev=1460911'
),
'wc-multivendor-marketplace' => array(
'name' => 'WCFM Marketplace',
'slug' => 'wc-multivendor-marketplace',
'filename' => 'wc-multivendor-marketplace',
'thumb_path' => 'https://ps.w.org/wc-multivendor-marketplace/assets/icon-256x256.png?rev=1925332'
),
'menu-icons' => array(
'name' => 'Menu Icons',
'slug' => 'menu-icons',
'filename' => 'menu-icons',
'thumb_path' => 'https://ps.w.org/menu-icons/assets/icon-128x128.png?rev=1797515'
)
);
/* 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_sparklestore_activate_plugin', array($this, 'activate_plugin'));
}
/** Trigger Welcome Message Notification */
public function admin_notice($hook) {
$hide_notice = get_option('sparklestore_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_sparklestore-welcome' === $screen->id || (isset($screen->parent_file) && 'plugins.php' === $screen->parent_file && 'update' === $screen->id) || 'theme-install' === $screen->id) {
return;
}
$slug = $filename = 'one-click-demo-import';
?>
theme_name); ?>
id) {
?>
generate_demo_installer_button(); ?>
theme_name))), 'manage_options', 'sparklestore-welcome', array($this, 'welcome_screen'), '', 2);
}
/** Welcome Page */
public function welcome_screen() {
$tabs = $this->tab_sections;
?>
esc_html__('Installing Demo Importer Plugin', 'sparklestore'),
'activating_text' => esc_html__('Activating Demo Importer Plugin', 'sparklestore'),
'importer_page' => esc_html__('Go to Demo Importer Page', 'sparklestore'),
'importer_url' => admin_url('themes.php?page=sparkle-theme-demo-importer'),
'error' => esc_html__('Error! Reload the page and try again.', 'sparklestore'),
);
wp_enqueue_style('sparklestore-welcome', get_template_directory_uri() . '/welcome/css/welcome.css', array());
wp_enqueue_script('sparklestore-welcome', get_template_directory_uri() . '/welcome/js/welcome.js', array('plugin-install', 'updates'), '', true);
wp_localize_script('sparklestore-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)) {
$result = activate_plugin($slug . '/' . $file . '.php');
update_option('sparklestore_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 ('appearance_page_sparklestore-welcome' == $screen->id) {
$text = sprintf(esc_html__('Please leave us a %s rating if you like our theme . A huge thank you from SparkleThemes in advance!', 'sparklestore'), '★★★★★');
}
return $text;
}
/** Generate One Click Demo Importer Plugin Install Button Link */
public function generate_demo_installer_button() {
$slug = $filename = 'sparkle-demo-importer';
$import_url = '#';
if ($this->check_plugin_installed_state($slug, $filename) && !$this->check_plugin_active_state($slug, $filename)) {
$import_class = 'button button-primary sparklestore-activate-plugin';
$import_button_text = esc_html__('Activate Demo Importer Plugin', 'sparklestore');
} elseif ($this->check_plugin_installed_state($slug, $filename)) {
$import_class = 'button button-primary';
$import_button_text = esc_html__('Go to Demo Importer Page', 'sparklestore');
$import_url = admin_url( '/themes.php?page=sparkle-theme-demo-importer' );
} else {
$import_class = 'button button-primary sparklestore-install-plugin';
$import_button_text = esc_html__('Install Demo Importer Plugin', 'sparklestore');
}
return '' . esc_html($import_button_text) . '';
}
public function erase_hide_notice() {
delete_option('sparklestore_hide_notice');
}
}
new SparkleStore_Welcome();
endif;