default_data();
$this->data = wp_parse_args( $data, $defaults );
$this->data['tabs'] = wp_parse_args( $this->data['tabs'], $defaults['tabs'] );
if ( ! function_exists( 'blockchain_lite_get_theme_variations' ) ) {
$this->data['tabs']['theme_variations'] = '';
if ( 'theme_variations' === $this->data['default_tab'] ) {
$this->data['default_tab'] = 'required_plugins';
}
}
foreach ( $this->data['required_plugins_page']['plugins'] as $slug => $plugin ) {
$plugin = $this->plugin_entry_defaults( $plugin );
$this->data['required_plugins_page']['plugins'][ $slug ] = $plugin;
}
foreach ( $this->data['recommended_plugins_page']['plugins'] as $slug => $plugin ) {
$plugin = $this->plugin_entry_defaults( $plugin );
$this->data['recommended_plugins_page']['plugins'][ $slug ] = $plugin;
}
$this->themedata_setup();
$this->page_setup();
}
}
/**
* Setup theme and custom data
*
* @return void
*/
public function themedata_setup() {
$theme = wp_get_theme();
$defaults = $this->default_data();
if ( is_child_theme() ) {
$this->theme_name = $theme->parent()->get( 'Name' );
$this->theme = $theme->parent();
} else {
$this->theme_name = $theme->get( 'Name' );
$this->theme = $theme;
}
$this->theme_version = $theme->get( 'Version' );
$this->theme_slug = $theme->get_template();
$this->menu_title = ! empty( $this->data['menu_title'] ) ? $this->data['menu_title'] : $defaults['menu_title'];
$this->page_title = ! empty( $this->data['page_title'] ) ? $this->data['page_title'] : $defaults['page_title'];
if ( ! empty( $this->data['theme_variations_page']['variations'] ) ) {
$variations = $this->data['theme_variations_page']['variations'];
$theme_screenshot = $theme->get_screenshot();
foreach ( $this->data['theme_variations_page']['variations'] as $slug => $variation ) {
if ( empty( $variation['screenshot'] ) ) {
$variation['screenshot'] = $theme_screenshot;
if ( '' !== $slug ) {
$path = "/theme-variations/{$slug}/screenshot.png";
$screenshot_path = get_theme_file_path( $path );
if ( file_exists( $screenshot_path ) ) {
$variation['screenshot'] = get_theme_file_uri( $path );
}
}
}
$variations[ $slug ] = $variation;
}
$this->data['theme_variations_page']['variations'] = $variations;
}
}
/**
* Actions used on the onboarding page
*
* @return void
*/
public function page_setup() {
if ( $this->data['redirect_on_activation'] ) {
add_action( 'after_switch_theme', array( $this, 'redirect_to_onboarding' ) );
}
add_action( 'admin_notices', array( $this, 'onboarding_notice' ) );
add_action( 'wp_ajax_blockchain_lite_dismiss_onboarding', array( $this, 'dismiss_onboarding' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
add_action( 'admin_menu', array( $this, 'register' ) );
add_action( 'wp_ajax_install_blockchain_lite_plugin', array( $this, 'install_plugin' ) );
add_action( 'wp_ajax_blockchain_lite_activate_variation', array( $this, 'activate_variation' ) );
add_action( 'wp_ajax_blockchain_lite_reset_theme_mods', array( $this, 'reset_theme_mods' ) );
}
/**
* Redirect to the onboarding page after activation
*
* @return void
*/
public function redirect_to_onboarding() {
global $pagenow;
if ( is_admin() && 'themes.php' === $pagenow && isset( $_GET['activated'] ) && current_user_can( 'manage_options' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
wp_safe_redirect( admin_url( 'themes.php?page=' . $this->theme_slug . '-onboard' ) );
exit;
}
}
/**
* Add admin notice for the onboarding page
*
* @return void
*/
public function onboarding_notice() {
$dismissed = get_theme_mod( 'dismissed_onboarding', false );
if ( ! current_user_can( 'manage_options' ) || $dismissed ) {
return;
}
$onboarding_page_url = get_admin_url( '', 'themes.php?page=' . $this->theme_slug . '-onboard' );
?>
onboarding page to get things started.', 'blockchain-lite' ),
$this->theme_name,
esc_url( $onboarding_page_url )
), array( 'a' => array( 'href' => array() ) ) );
?>
theme_version, true );
$settings = array(
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'dismiss_nonce' => wp_create_nonce( 'blockchain-lite-dismiss-onboarding' ),
);
wp_localize_script( 'blockchain-lite-onboarding-notice', 'blockchain_lite_Onboarding', $settings );
}
/**
* Handle dismissal of the admin notice
*
* @return void
*/
public function dismiss_onboarding() {
check_ajax_referer( 'blockchain-lite-dismiss-onboarding', 'nonce' );
if ( current_user_can( 'manage_options' ) && ! empty( $_POST['dismissed'] ) && 'true' === $_POST['dismissed'] ) {
set_theme_mod( 'dismissed_onboarding', true );
wp_send_json_success( 'OK' );
}
wp_send_json_error( 'BAD' );
}
/**
* Enqueue onboarding page styles and scripts
*
* @return void
*/
public function enqueue_admin_styles() {
if ( get_current_screen()->id !== 'appearance_page_' . $this->theme_slug . '-onboard' ) {
return;
}
wp_enqueue_style( 'plugin-install' );
wp_enqueue_style( 'blockchain-lite-onboarding', get_theme_file_uri( '/inc/onboarding/css/onboarding-styles.css' ), array(), $this->theme_version );
wp_enqueue_script( 'blockchain-lite-onboarding', get_theme_file_uri( '/inc/onboarding/js/onboarding.js' ), array(
'plugin-install',
'updates',
), $this->theme_version, true );
wp_localize_script(
'blockchain-lite-onboarding', 'blockchain_lite_onboarding', array(
'onboarding_nonce' => wp_create_nonce( 'onboarding_nonce' ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'template_directory' => get_template_directory_uri(),
'activating_text' => esc_html__( 'Activating', 'blockchain-lite' ),
'activate_text' => esc_html__( 'Activate', 'blockchain-lite' ),
'installing_text' => esc_html__( 'Installing...', 'blockchain-lite' ),
'activate_variation_text' => esc_html__( 'Activate variation', 'blockchain-lite' ),
'deleting_text' => esc_html__( 'Deleting...', 'blockchain-lite' ),
'reset_mods_confirm_text' => esc_html__( 'Are you sure you want to delete your theme customizations?', 'blockchain-lite' ),
)
);
}
/**
* Register the page
*
* @return void
*/
public function register() {
add_theme_page( $this->page_title, $this->menu_title, 'edit_theme_options', $this->theme_slug . '-onboard', array( $this, 'render_page' ) );
}
/**
* Render the onboarding page
*
* @return void
*/
public function render_page() {
$title = $this->data['title'];
$title = str_replace(
array( ':theme_name:', ':theme_version:' ),
array( $this->theme_name, $this->theme_version ),
$title );
if ( defined( 'BLOCKCHAIN_LITE_WHITELABEL' ) && BLOCKCHAIN_LITE_WHITELABEL ) {
$logo_src = ! empty( $this->data['logo_src'] ) ? $this->data['logo_src'] : '';
$logo_url = ! empty( $this->data['logo_url'] ) ? $this->data['logo_url'] : '';
} else {
$logo_src = ! empty( $this->data['logo_src'] ) ? $this->data['logo_src'] : get_theme_file_uri( '/inc/onboarding/assets/cssigniter_logo.svg' );
$logo_url = ! empty( $this->data['logo_url'] ) ? $this->data['logo_url'] : 'https://www.cssigniter.com/themes/' . BLOCKCHAIN_LITE_NAME . '/';
}
?>
data['description'] ) ) : ?>
data['description'], blockchain_lite_get_allowed_tags( 'guide' ) ); ?>
data['logo_show'] && $logo_src ) : ?>
data ) && ! empty( $this->data['tabs'] ) ) {
$this->generate_tabs();
}
?>
data['default_tab']; // phpcs:ignore WordPress.Security.NonceVerification
?>
data['tabs'] as $tab => $title ) : ?>
$active_tab();
}
?>
data['theme_variations_page']['variations'];
$this->get_variation_boxes( $variations );
?>
data['theme_variations_page']['reset_mods_button'] ) && true === (bool) $this->data['theme_variations_page']['reset_mods_button'];
if ( $reset_button ) {
?>
$variation ) {
$enabled_class = '';
if ( $current_variation === $slug ) {
$enabled_class = 'enabled';
}
?>
data['required_plugins_page']['plugins'];
$actions = $this->get_plugin_action( $plugins );
$this->get_plugin_boxes( $plugins, $actions );
?>
theme_name ) );
?>
data['recommended_plugins_page']['plugins'];
$actions = $this->get_plugin_action( $plugins );
$this->get_plugin_boxes( $plugins, $actions );
?>
data['required_plugins_page']['plugins'], $this->data['recommended_plugins_page']['plugins'] );
$plugins = wp_list_filter( $plugins, array( 'required_by_sample' => true ) );
if ( ! empty( $plugins['one-click-demo-import'] ) ) {
$plugins['one-click-demo-import']['required_by_sample'] = true;
}
$actions = $this->get_plugin_action( $plugins );
foreach ( $actions as $slug => $action ) {
if ( 'none' === $action ) {
unset( $plugins[ $slug ] );
}
}
if ( ! empty( $plugins ) ) {
?>
get_plugin_action( $plugins );
$this->get_plugin_boxes( $plugins, $actions );
?>
get_plugin_action( array( 'one-click-demo-import' => __( 'One Click Demo Import', 'blockchain-lite' ) ) );
if ( in_array( $check['one-click-demo-import'], array( 'install-plugin', 'activate' ), true ) ) {
?>
One Click Demo Import before proceeding.', 'blockchain-lite' ), blockchain_lite_get_allowed_tags( 'guide' ) ); ?>
data['support_page']['sections'] ) ) {
return;
}
?>
data['support_page']['sections'];
foreach ( $sections as $section_id => $section ) {
?>
$action ) {
$data = $plugins[ $slug ];
$plugin_file = ! empty( $data['plugin_file'] ) ? $slug . '/' . $data['plugin_file'] : $slug . '/' . $slug . '.php';
if ( 'upload-plugin' === $action ) {
$link = add_query_arg(
array(
'action' => 'activate',
'plugin' => rawurlencode( $plugin_file ),
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin_file ),
), admin_url( 'plugins.php' )
);
?>
$action,
'plugin' => $slug,
'_wpnonce' => wp_create_nonce( $action . '_' . $slug ),
), admin_url( 'update.php' )
);
?>
'activate',
'plugin' => rawurlencode( $plugin_file ),
'_wpnonce' => wp_create_nonce( 'activate-plugin_' . $plugin_file ),
), admin_url( 'plugins.php' )
);
?>
$data ) {
$plugin_file = ! empty( $data['plugin_file'] ) ? $slug . '/' . $data['plugin_file'] : $slug . '/' . $slug . '.php';
$plugin_file_path = WP_PLUGIN_DIR . '/' . $plugin_file;
$is_callable = ! empty( $data['is_callable'] ) ? is_callable( $data['is_callable'] ) : false;
$is_active = is_plugin_active( $plugin_file );
$is_installed = file_exists( $plugin_file_path );
$is_bundled = isset( $data['bundled'] ) && true === $data['bundled'] ? true : false;
if ( $is_callable || $is_active ) {
$plugin_action[ $slug ] = 'none';
continue;
}
if ( $is_installed ) {
$plugin_action[ $slug ] = 'activate';
} else {
if ( $is_bundled ) {
$plugin_action[ $slug ] = 'upload-plugin';
} else {
$plugin_action[ $slug ] = 'install-plugin';
}
}
}
return $plugin_action;
}
/**
* Installs theme specific plugins
*
* @return void
*/
public function install_plugin() {
if ( ! current_user_can( 'upload_plugins' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to install plugins on this site.', 'blockchain-lite' ) );
}
// Verify nonce.
if ( ! isset( $_POST['onboarding_nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['onboarding_nonce'] ) ), 'onboarding_nonce' ) ) {
die( 'Permission denied' );
}
$plugin_slug = isset( $_POST['plugin_slug'] ) ? sanitize_key( wp_unslash( $_POST['plugin_slug'] ) ) : '';
$plugin_source_url = get_template_directory_uri() . '/plugins/' . $plugin_slug . '.zip';
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
/* translators: %s is a URL. */
$title = sprintf( __( 'Installing Plugin from URL: %s', 'blockchain-lite' ), esc_html( $plugin_source_url ) );
$url = 'update.php?action=install-plugin';
$upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( array(
'title' => $title,
'url' => $url,
) ) );
$upgrader->install( $plugin_source_url );
}
/**
* Activates a theme variation.
*
* @return void
*/
public function activate_variation() {
if ( ! current_user_can( 'edit_theme_options' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to change theme options on this site.', 'blockchain-lite' ) );
}
// Verify nonce.
if ( ! isset( $_POST['onboarding_nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['onboarding_nonce'] ) ), 'onboarding_nonce' ) ) {
die( 'Permission denied' );
}
$variation = isset( $_POST['variation'] ) ? sanitize_key( wp_unslash( $_POST['variation'] ) ) : '';
if ( array_key_exists( $variation, blockchain_lite_get_theme_variations() ) ) {
set_theme_mod( 'theme_variation', $variation );
}
die;
}
/**
* Resets theme modifications.
*
* @return void
*/
public function reset_theme_mods() {
// Check that we can actually perform this action.
if ( ! isset( $this->data['theme_variations_page']['reset_mods_button'] ) || false === (bool) $this->data['theme_variations_page']['reset_mods_button'] ) {
die( 'Permission denied' );
}
if ( ! current_user_can( 'edit_theme_options' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to change theme options on this site.', 'blockchain-lite' ) );
}
// Verify nonce.
if ( ! isset( $_POST['onboarding_nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['onboarding_nonce'] ) ), 'onboarding_nonce' ) ) {
die( 'Permission denied' );
}
$defaults = blockchain_lite_customizer_defaults();
$theme_mods = get_theme_mods();
// Only remove theme-specific theme mods.
foreach ( $defaults as $key => $value ) {
if ( array_key_exists( $key, $theme_mods ) ) {
remove_theme_mod( $key );
}
}
die;
}
public function default_data() {
$theme = wp_get_theme();
return array(
// Required. Turns the onboarding page on/off.
'show_page' => true,
// Optional. Turns the redirection to the onboarding page on/off.
'redirect_on_activation' => true,
// Optional. The text to be used for the admin menu. If empty, defaults to "About theme_name"
/* translators: %s is the theme name. */
'menu_title' => sprintf( __( 'About %s', 'blockchain-lite' ), $theme->get( 'Name' ) ),
// Optional. The text to be displayed in the page's title tag. If empty, defaults to "About theme_name"
/* translators: %s is the theme name. */
'page_title' => sprintf( __( 'About %s', 'blockchain-lite' ), $theme->get( 'Name' ) ),
// Optional. The onboarding page's title, placeholders available :theme_name:, :theme_version:. If empty, defaults to "Welcome to :theme_name:! - Version :theme_version:"
'title' => __( 'Welcome to :theme_name:! - Version :theme_version:', 'blockchain-lite' ),
// Optional. The theme's description. Some HTML is allowed (no p).
'description' => '',
// Optional. Boolean. Whether to show the logo. Default: true in normal mode. false if whitelabel.
'logo_show' => defined( 'BLOCKCHAIN_LITE_WHITELABEL' ) && BLOCKCHAIN_LITE_WHITELABEL ? false : true,
// Optional. The logo's image source URL. Defaults to the bundled logo.
'logo_src' => get_theme_file_uri( '/inc/onboarding/assets/cssigniter_logo.svg' ),
// Required. The logo's link URL. Defaults to 'https://www.cssigniter.com/themes/' . BLOCKCHAIN_LITE_NAME . '/'
'logo_url' => 'https://www.cssigniter.com/themes/' . BLOCKCHAIN_LITE_NAME . '/',
// Optional. The default active tab. Default 'required_plugins'. Must be one of the keys in the tabs[] array.
'default_tab' => 'required_plugins',
// Optional. slug => label pairs for each tab. Empty label to disable. Defaults are as follows:
'tabs' => array(
'theme_variations' => __( 'Theme Variations', 'blockchain-lite' ),
'required_plugins' => __( 'Required Plugins', 'blockchain-lite' ),
'recommended_plugins' => __( 'Recommended Plugins', 'blockchain-lite' ),
'sample_content' => __( 'Sample Content', 'blockchain-lite' ),
'support' => __( 'Support', 'blockchain-lite' ),
),
'theme_variations_page' => array(
'reset_mods_button' => true,
'variations' => array(
// // Each variation is registered as 'slug' => array()
// 'variation-slug' => array(
// // Required. The variation's title.
// 'title' => __( 'Variation Title', 'blockchain-lite' ),
// // Optional. The variation's description.
// 'description' => '',
// // Required. The variation's screenshot. Defaults to /theme-variations/variation-slug/screenshot.png and falls back to the theme's screenshot.
// 'screenshot' => '',
// ),
),
),
'required_plugins_page' => array(
'plugins' => array(
// // Each plugin is registered as 'slug' => array()
// 'plugin-slug' => array(
// // Required. The plugin's title.
// 'title' => __( 'Plugin Title', 'blockchain-lite' ),
// // Optional. The plugin's description, or why the plugin is required.
// 'description' => '',
// // Optional. If both 'version' and 'bundle' are set, the theme will prompt for a plugin update if applicable.
// 'version' => '1.0',
// // Optional. If true, the plugin zip will be searched in the theme's plugins/ directory, named "plugin-slug.zip". Default false.
// 'bundled' => false,
// // Optional. If passed string or array is callable, then the plugin will appear as activated.
// 'is_callable' => '',
// // Optional. If not passed, it's assumed to be "plugin-slug.php". Only pass a filename. It gets combined with the plugin slug as needed.
// 'plugin_file' => '',
// // Optional. Declares that the plugin must be active for sample content import to succeed. Default false.
// 'required_by_sample' => false,
// ),
),
),
'recommended_plugins_page' => array(
'plugins' => array(
// // Each plugin is registered as 'slug' => array()
// 'plugin-slug' => array(
// // Required. The plugin's title.
// 'title' => __( 'Plugin Title', 'blockchain-lite' ),
// // Optional. The plugin's description, or why the plugin is required.
// 'description' => '',
// // Optional. If both 'version' and 'bundle' are set, the theme will prompt for a plugin update if applicable.
// 'version' => '1.0',
// // Optional. If true, the plugin zip will be searched in the theme's plugins/ directory, named "plugin-slug.zip". Default false.
// 'bundled' => false,
// // Optional. If passed string or array is callable, then the plugin will appear as activated.
// 'is_callable' => '',
// // Optional. If not passed, it's assumed to be "plugin-slug.php". Only pass a filename. It gets combined with the plugin slug as needed.
// 'plugin_file' => '',
// // Optional. Declares that the plugin must be active for sample content import to succeed. Default false.
// 'required_by_sample' => false,
// ),
),
),
'support_page' => array(
'sections' => array(
'documentation' => array(
'title' => __( 'Theme Documentation', 'blockchain-lite' ),
'description' => __( "If you don't want to import our demo sample content, just visit this page and learn how to set things up individually.", 'blockchain-lite' ),
'link_url' => 'https://www.cssigniter.com/docs/' . BLOCKCHAIN_LITE_NAME . '/',
),
'kb' => array(
'title' => __( 'Knowledge Base', 'blockchain-lite' ),
'description' => __( 'Browse our library of step by step how-to articles, tutorials, and guides to get quick answers.', 'blockchain-lite' ),
'link_url' => 'https://www.cssigniter.com/docs/knowledgebase/',
),
'support' => array(
'title' => __( 'Request Support', 'blockchain-lite' ),
'description' => __( 'Got stuck? No worries, just visit our support page, submit your ticket and we will be there for you within 24 hours.', 'blockchain-lite' ),
'link_url' => 'https://www.cssigniter.com/support/',
),
),
),
);
}
public function plugin_entry_defaults( $plugin ) {
return wp_parse_args( $plugin, array(
// Required. The plugin's title.
'title' => __( 'Plugin Title', 'blockchain-lite' ),
// Optional. The plugin's description, or why the plugin is required.
'description' => '',
// Optional. E.g. '1.0'. If both 'version' and 'bundle' are set, the theme will prompt for a plugin update if applicable.
'version' => '',
// Optional. If true, the plugin zip will be searched in the theme's plugins/ directory, named "plugin-slug.zip". Default false.
'bundled' => false,
// Optional. If passed string or array is callable, then the plugin will appear as activated.
'is_callable' => '',
// Optional. Declares that the plugin must be active for sample content import to succeed. Default false.
'required_by_sample' => false,
) );
}
}