init_globals(); $this->init_actions(); } public function init_globals() { $current_theme = wp_get_theme(); $this->page_slug = apply_filters( $this->theme_name . '_theme_setup_wizard_page_slug', $this->theme_name . '-setup' ); $this->parent_slug = apply_filters( $this->theme_name . '_theme_setup_wizard_parent_slug', '' ); // create an images/styleX/ folder for each style here. $this->site_styles = array( 'style1' => 'Style 1', 'style2' => 'Style 2', 'style3' => 'Style 3', 'style4' => 'Style 4', ); //If we have parent slug - set correct url if ( $this->parent_slug !== '' ) { $this->page_url = 'admin.php?page=' . $this->page_slug; } else { $this->page_url = 'themes.php?page=' . $this->page_slug; } $this->page_url = apply_filters( $this->theme_name . '_theme_setup_wizard_page_url', $this->page_url ); //set relative plugin path url $this->plugin_path = trailingslashit( $this->cleanFilePath( dirname( __FILE__ ) ) ); $relative_url = str_replace( $this->cleanFilePath( get_template_directory() ), '', $this->plugin_path ); $this->plugin_url = trailingslashit( get_template_directory_uri() . $relative_url ); } public function init_actions() { if ( apply_filters( $this->theme_name . '_enable_setup_wizard', true ) && current_user_can( 'manage_options' ) ) { add_action( 'after_switch_theme', array( $this, 'switch_theme' ) ); if ( class_exists( 'TGM_Plugin_Activation' ) && isset( $GLOBALS['tgmpa'] ) ) { add_action( 'init', array( $this, 'get_tgmpa_instanse' ), 30 ); add_action( 'init', array( $this, 'set_tgmpa_url' ), 40 ); } add_action( 'admin_menu', array( $this, 'admin_menus' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'admin_init', array( $this, 'admin_redirects' ), 30 ); add_action( 'admin_init', array( $this, 'init_wizard_steps' ), 30 ); add_action( 'admin_init', array( $this, 'setup_wizard' ), 30 ); add_filter( 'tgmpa_load', array( $this, 'tgmpa_load' ), 10, 1 ); add_action( 'wp_ajax_envato_setup_plugins', array( $this, 'ajax_plugins' ) ); add_action( 'wp_ajax_envato_setup_content', array( $this, 'ajax_content' ) ); add_action( 'wp_ajax_taskereasy_menu', array( $this, 'taskereasy_menu' ) ); add_action( 'wp_ajax_setup_content', array( $this, 'setup_content' ) ); add_action( 'wp_ajax_taskereasy_homepage', array( $this, 'taskereasy_homepage' ) ); add_action( 'wp_ajax_taskereasy_theme_options', array( $this, 'taskereasy_theme_options' ) ); } add_action( 'upgrader_post_install', array( $this, 'upgrader_post_install' ), 10, 2 ); } /** * After a theme update we clear the setup_complete option. This prompts the user to visit the update page again. */ public function upgrader_post_install( $return, $theme ) { if ( is_wp_error( $return ) ) { return $return; } if ( $theme != get_stylesheet() ) { return $return; } update_option( 'envato_setup_complete', false ); return $return; } /** * We determine if the user already has theme content installed. This can happen if swapping from a previous theme or updated the current theme. We change the UI a bit when updating / swapping to a new theme. * */ public function is_possible_upgrade() { return false; } public function enqueue_scripts() { } public function tgmpa_load( $status ) { return is_admin() || current_user_can( 'install_themes' ); } public function switch_theme() { set_transient( '_' . $this->theme_name . '_activation_redirect', 1 ); } public function admin_redirects() { if ( ! get_transient( '_' . $this->theme_name . '_activation_redirect' ) || get_option( 'envato_setup_complete', false ) ) { return; } delete_transient( '_' . $this->theme_name . '_activation_redirect' ); wp_redirect( admin_url( $this->page_url ) ); exit(); } public function get_default_theme_style() { return 'style1'; } /** * Get configured TGMPA instance * * @access public * @since 1.1.2 */ public function get_tgmpa_instanse() { $this->tgmpa_instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) ); } /** * Update $tgmpa_menu_slug and $tgmpa_parent_slug from TGMPA instance * * @access public * @since 1.1.2 */ public function set_tgmpa_url() { $this->tgmpa_menu_slug = ( property_exists( $this->tgmpa_instance, 'menu' ) ) ? $this->tgmpa_instance->menu : $this->tgmpa_menu_slug; $this->tgmpa_menu_slug = apply_filters( $this->theme_name . '_theme_setup_wizard_tgmpa_menu_slug', $this->tgmpa_menu_slug ); $tgmpa_parent_slug = ( property_exists( $this->tgmpa_instance, 'parent_slug' ) && $this->tgmpa_instance->parent_slug !== 'themes.php' ) ? 'admin.php' : 'themes.php'; $this->tgmpa_url = apply_filters( $this->theme_name . '_theme_setup_wizard_tgmpa_url', $tgmpa_parent_slug . '?page=' . $this->tgmpa_menu_slug ); } /** * Add admin menus/screens. */ public function admin_menus() { if ( $this->is_submenu_page() ) { //prevent Theme Check warning about "themes should use add_theme_page for adding admin pages" $add_subpage_function = 'add_submenu' . '_page'; $add_subpage_function( $this->parent_slug, esc_html__( 'Setup Wizard', 'taskereasy' ), esc_html__( 'Setup Wizard', 'taskereasy' ), 'manage_options', $this->page_slug, array( $this, 'setup_wizard', ) ); } else { add_theme_page( esc_html__( 'Setup Wizard', 'taskereasy' ), esc_html__( 'Setup Wizard', 'taskereasy' ), 'manage_options', $this->page_slug, array( $this, 'setup_wizard', ) ); } } /** * Setup steps. * * @since 1.1.1 * @access public * @return array */ public function init_wizard_steps() { $this->steps = array( 'introduction' => array( 'name' => esc_html__( 'Introduction', 'taskereasy' ), 'view' => array( $this, 'envato_setup_introduction' ), 'handler' => array( $this, '' ), ), ); if ( class_exists( 'TGM_Plugin_Activation' ) && isset( $GLOBALS['tgmpa'] ) ) { $this->steps['default_plugins'] = array( 'name' => esc_html__( 'Plugins', 'taskereasy' ), 'view' => array( $this, 'envato_setup_default_plugins' ), 'handler' => '', ); } if( count($this->site_styles) > 1 ) { $this->steps['style'] = array( 'name' => esc_html__( 'Demos', 'taskereasy' ), 'view' => array( $this, 'envato_setup_color_style' ), 'handler' => array( $this, 'envato_setup_color_style_save' ), ); } $this->steps['default_content'] = array( 'name' => esc_html__( 'Content' , 'taskereasy'), 'view' => array( $this, 'envato_setup_default_content' ), 'handler' => '', ); $this->steps['next_steps'] = array( 'name' => esc_html__( 'Ready!', 'taskereasy' ), 'view' => array( $this, 'envato_setup_ready' ), 'handler' => '', ); $this->steps = apply_filters( $this->theme_name . '_theme_setup_wizard_steps', $this->steps ); } /** * Show the setup wizard */ public function setup_wizard() { if ( empty( $_GET['page'] ) || $this->page_slug !== $_GET['page'] ) { return; } $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) ); wp_register_script( 'jquery-blockui', $this->plugin_url . 'js/jquery.blockUI.js', array( 'jquery' ), '2.70', true ); wp_register_script( 'envato-setup', $this->plugin_url . 'js/envato-setup.js', array( 'jquery', 'jquery-blockui', ), $this->version ); wp_localize_script( 'envato-setup', 'envato_setup_params', array( 'tgm_plugin_nonce' => array( 'update' => wp_create_nonce( 'tgmpa-update' ), 'install' => wp_create_nonce( 'tgmpa-install' ), ), 'tgm_bulk_url' => admin_url( $this->tgmpa_url ), 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'wpnonce' => wp_create_nonce( 'envato_setup_nonce' ), 'verify_text' => esc_html__( '...verifying' , 'taskereasy'), ) ); //wp_enqueue_style( 'envato_wizard_admin_styles', $this->plugin_url . '/css/admin.css', array(), $this->version ); wp_enqueue_style( 'envato-setup', $this->plugin_url . 'css/envato-setup.css', array( 'wp-admin', 'dashicons', 'install', ), $this->version ); //enqueue style for admin notices wp_enqueue_style( 'wp-admin' ); wp_enqueue_media(); wp_enqueue_script( 'media' ); ob_start(); $this->setup_wizard_header(); $this->setup_wizard_steps(); $show_content = true; echo '
&$value ) {
if ( is_array( $value ) && isset( $merged [ $key ] ) && is_array( $merged [ $key ] ) ) {
$merged [ $key ] = $this->_array_merge_recursive_distinct( $merged [ $key ], $value );
} else {
$merged [ $key ] = $value;
}
}
return $merged;
}
public static function cleanFilePath( $path ) {
$path = str_replace( '', '', str_replace( array( '\\', '\\\\', '//' ), '/', $path ) );
if ( $path[ strlen( $path ) - 1 ] === '/' ) {
$path = rtrim( $path, '/' );
}
return $path;
}
public function is_submenu_page() {
return ( $this->parent_slug == '' ) ? false : true;
}
}
}// if !class_exists
/**
* Loads the main instance of Envato_Theme_Setup_Wizard to have
* ability extend class functionality
*
* @since 1.1.1
* @return object Envato_Theme_Setup_Wizard
*/
add_action( 'after_setup_theme', 'envato_theme_setup_wizard', 10 );
if ( ! function_exists( 'envato_theme_setup_wizard' ) ) :
function envato_theme_setup_wizard() {
Envato_Theme_Setup_Wizard::get_instance();
}
endif;