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 '
'; if ( ! empty( $_REQUEST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) { $show_content = call_user_func( $this->steps[ $this->step ]['handler'] ); } if ( $show_content ) { $this->setup_wizard_content(); } echo '
'; $this->setup_wizard_footer(); exit; } public function get_step_link( $step ) { return add_query_arg( 'step', $step, admin_url( 'admin.php?page=' . $this->page_slug ) ); } public function get_next_step_link() { $keys = array_keys( $this->steps ); return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ], remove_query_arg( 'translation_updated' ) ); } /** * Setup Wizard Header */ public function setup_wizard_header() { ?> > ' . esc_html__( 'Taskereasy › Setup Wizard', 'taskereasy' ) . ''; ?>

Taskereasy

step ) : ?> steps; array_shift( $ouput_steps ); ?>
    $step ) : ?>
steps[ $this->step ] ) ? call_user_func( $this->steps[ $this->step ]['view'] ) : false; } /** * Introduction step */ public function envato_setup_introduction() { $theme_status = get_option( 'theme_activation' ); if( $theme_status != 'activated' ){ ?>

64MB is required. Learn More', 'taskereasy'); } ?>
Learn More', 'taskereasy'); } ?>
Learn More', 'taskereasy'); } ?>

is_possible_upgrade() ) { ?>


array(), // Meaning: all plugins which still have open actions. 'install' => array(), 'update' => array(), 'activate' => array(), ); foreach ( $instance->plugins as $slug => $plugin ) { if ( !$instance->can_plugin_activate( $slug ) && false === $instance->does_plugin_have_update( $slug ) ) { // No need to display plugins if they are installed, up-to-date and active. continue; } else { $plugins['all'][ $slug ] = $plugin; if ( ! $instance->is_plugin_installed( $slug ) ) { $plugins['install'][ $slug ] = $plugin; } else { if ( false !== $instance->does_plugin_have_update( $slug ) ) { $plugins['update'][ $slug ] = $plugin; } if ( $instance->can_plugin_activate( $slug ) ) { $plugins['activate'][ $slug ] = $plugin; } } } } return $plugins; } /** * Page setup */ public function envato_setup_default_plugins() { tgmpa_load_bulk_installer(); // install plugins with TGM. if ( ! class_exists( 'TGM_Plugin_Activation' ) || ! isset( $GLOBALS['tgmpa'] ) ) { die( 'Failed to find TGM' ); } $url = wp_nonce_url( add_query_arg( array( 'plugins' => 'go' ) ), 'envato-setup' ); $plugins = $this->_get_plugins(); // copied from TGM $method = ''; // Leave blank so WP_Filesystem can populate it as necessary. $fields = array_keys( $_POST ); // Extra fields to pass to WP_Filesystem. if ( false === ( $creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, $fields ) ) ) { return true; // Stop the normal page form from displaying, credential request form will be shown. } // Now we have some credentials, setup WP_Filesystem. if ( ! WP_Filesystem( $creds ) ) { // Our credentials were no good, ask the user for them again. request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, $fields ); return true; } /* If we arrive here, we have the filesystem */ ?>

_get_plugins(); if ( count( $plugins['all'] ) ) { ?>

' . esc_html_e( 'Good news! All plugins are already installed and up to date. Please continue.', 'taskereasy' ) . '

'; } ?>

1, 'message' => esc_html__( 'No Slug Found', 'taskereasy' ) ) ); } $json = array(); // send back some json we use to hit up TGM $plugins = $this->_get_plugins(); // what are we doing with this plugin? foreach ( $plugins['activate'] as $slug => $plugin ) { if ( $_POST['slug'] == $slug ) { $json = array( 'url' => admin_url( $this->tgmpa_url ), 'plugin' => array( $slug ), 'tgmpa-page' => $this->tgmpa_menu_slug, 'plugin_status' => 'all', '_wpnonce' => wp_create_nonce( 'bulk-plugins' ), 'action' => 'tgmpa-bulk-activate', 'action2' => - 1, 'message' => esc_html__( 'Activating Plugin', 'taskereasy' ), ); break; } } foreach ( $plugins['update'] as $slug => $plugin ) { if ( $_POST['slug'] == $slug ) { $json = array( 'url' => admin_url( $this->tgmpa_url ), 'plugin' => array( $slug ), 'tgmpa-page' => $this->tgmpa_menu_slug, 'plugin_status' => 'all', '_wpnonce' => wp_create_nonce( 'bulk-plugins' ), 'action' => 'tgmpa-bulk-update', 'action2' => - 1, 'message' => esc_html__( 'Updating Plugin', 'taskereasy' ), ); break; } } foreach ( $plugins['install'] as $slug => $plugin ) { if ( $_POST['slug'] == $slug ) { $json = array( 'url' => admin_url( $this->tgmpa_url ), 'plugin' => array( $slug ), 'tgmpa-page' => $this->tgmpa_menu_slug, 'plugin_status' => 'all', '_wpnonce' => wp_create_nonce( 'bulk-plugins' ), 'action' => 'tgmpa-bulk-install', 'action2' => - 1, 'message' => esc_html__( 'Installing Plugin' , 'taskereasy'), ); break; } } if ( $json ) { $json['hash'] = md5( serialize( $json ) ); // used for checking if duplicates happen, move to next plugin wp_send_json( $json ); } else { wp_send_json( array( 'done' => 1, 'message' => esc_html__( 'Success', 'taskereasy' ) ) ); } exit; } public function envato_setup_default_content() { ?>

is_possible_upgrade() ) { ?>

', '' ); ?>

get_default_theme_style()); $file = get_template_directory().'/setup/content/'.$themeSelectedStyle.'/content.xml'; if ( !defined('WP_LOAD_IMPORTERS') ) define('WP_LOAD_IMPORTERS', true); require_once ABSPATH . 'wp-admin/includes/import.php'; $importer_error = false; if ( !class_exists( 'WP_Importer' ) ) { $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php'; if ( file_exists( $class_wp_importer ) ){ require_once($class_wp_importer); } else { $importer_error = true; } } if ( !class_exists( 'WP_Import' ) ) { $class_wp_import = get_template_directory().'/setup/importer/importer/wordpress-importer.php'; if ( file_exists( $class_wp_import ) ) require_once($class_wp_import); else $importer_error = true; } if($importer_error){ ob_start(); $msg = "Error on import"; $msg = ob_get_contents(); ob_end_clean(); die($msg); } else { if(!is_file( $file )){ ob_start(); $msg = "Something went wrong"; $msg = ob_get_contents(); ob_end_clean(); die($msg); } else { $wp_import = new WP_Import(); $wp_import->fetch_attachments = true; ob_start(); $res=$wp_import->import( $file ); $res = ob_get_contents(); ob_end_clean(); $msg = 'Content imported success'; die($msg); } } } //Assigns menu location public function taskereasy_menu(){ $main_menu = get_term_by('name', 'main menu', 'nav_menu'); set_theme_mod( 'nav_menu_locations', array( 'primary' => $main_menu->term_id, ) ); die('Menu setup successful'); } public function taskereasy_homepage(){ $blog = get_page_by_path( 'Blog' ); $home = get_page_by_path( 'Home' ); update_option( 'show_on_front', 'page' ); update_option( 'page_on_front', $home->ID ); update_option( 'page_for_posts',$blog->ID ); die('Home page setup successful'); } public function taskereasy_theme_options() { WP_Filesystem(); global $wp_filesystem; $themeSelectedStyle = get_theme_mod('dtbwp_site_style',$this->get_default_theme_style()); $file = get_template_directory().'/setup/content/'.$themeSelectedStyle.'/themeOptions.json'; $data = $wp_filesystem->get_contents( $file ); $data = json_decode( $data, true ); $theme_option_name = 'taskereasy_options'; if ( is_array( $data ) && !empty( $data ) ) { $data = apply_filters( 'solitaire_theme_import_theme_options', $data ); update_option($theme_option_name, $data); die('Theme Options imported'); } else { die('An error occured while importing theme options'); } } public $logs = array(); public function log( $message ) { $this->logs[] = $message; } public $errors = array(); public function error( $message ) { $this->logs[] = 'ERROR!!!! ' . $message; } /* Function for the different styles */ public function envato_setup_color_style() { ?>

    get_default_theme_style() ); $stylecls = ''; $i = 0; foreach ( $this->site_styles as $style_name => $style_data ) { ?>

get_next_step_link() ) ); exit; } public function envato_setup_ready() { update_option( 'envato_setup_complete', time() ); update_option( 'dtbwp_update_notice', strtotime('-4 days') ); ?>

&$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;