| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077 |
- <?php
- /**
- * Envato Theme Setup Wizard Class
- *
- * Takes new users through some basic steps to setup their theme.
- *
- */
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- if ( ! class_exists( 'Envato_Theme_Setup_Wizard' ) ) {
- class Envato_Theme_Setup_Wizard {
- protected $version = '1.3.0';
- protected $theme_name = '';
- protected $envato_username = '';
- protected $oauth_script = '';
- protected $step = '';
- protected $steps = array();
- protected $plugin_path = '';
- protected $plugin_url = '';
- protected $page_slug;
- protected $tgmpa_instance;
- protected $tgmpa_menu_slug = 'tgmpa-install-plugins';
- protected $tgmpa_url = 'themes.php?page=tgmpa-install-plugins';
- protected $page_parent;
- protected $page_url;
- public $site_styles = array();
- private static $instance = null;
- public static function get_instance() {
- if ( ! self::$instance ) {
- self::$instance = new self;
- }
- return self::$instance;
- }
- public function __construct() {
- $this->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 '<div class="envato-setup-content">';
- 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 '</div>';
- $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() {
- ?>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
- <head>
- <meta name="viewport" content="width=device-width"/>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- <?php
- // avoid theme check issues.
- echo '<t';
- echo 'itle>' . esc_html__( 'Taskereasy › Setup Wizard', 'taskereasy' ) . '</ti' . 'tle>'; ?>
- <?php wp_print_scripts( 'envato-setup' ); ?>
- <?php do_action( 'admin_print_styles' ); ?>
- <?php do_action( 'admin_print_scripts' ); ?>
- <?php do_action( 'admin_head' ); ?>
- </head>
- <body class="envato-setup wp-core-ui">
- <h1 id="wc-logo">
- <a href="https://themeforest.net/item/taskereasy-multipurpose-business-corporate-wordpress-theme/23832008" target="_blank">
- <img src="<?php echo get_template_directory_uri(); ?>/assets/images/logo.png" alt="Taskereasy" />
- </a>
- </h1>
- <?php
- }
- /**
- * Setup Wizard Footer
- */
- public function setup_wizard_footer() {
- ?>
- <?php if ( 'next_steps' === $this->step ) : ?>
- <a class="wc-return-to-dashboard"
- href="<?php echo esc_url( admin_url() ); ?>"><?php esc_html_e( 'Return to the WordPress Dashboard', 'taskereasy' ); ?></a>
- <?php endif; ?>
- </body>
- <?php
- do_action( 'admin_footer' );
- do_action( 'admin_print_footer_scripts' );
- ?>
- </html>
- <?php
- }
- /**
- * Output the steps
- */
- public function setup_wizard_steps() {
- $ouput_steps = $this->steps;
- array_shift( $ouput_steps );
- ?>
- <ol class="envato-setup-steps">
- <?php foreach ( $ouput_steps as $step_key => $step ) : ?>
- <li class="<?php
- $show_link = false;
- if ( $step_key === $this->step ) {
- echo 'active';
- } elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) {
- echo 'done';
- $show_link = true;
- }
- ?>"><?php
- if ( $show_link ) {
- ?>
- <a href="<?php echo esc_url( $this->get_step_link( $step_key ) ); ?>"><?php echo esc_html( $step['name'] ); ?></a>
- <?php
- } else {
- echo esc_html( $step['name'] );
- }
- ?></li>
- <?php endforeach; ?>
- </ol>
- <?php
- }
- /**
- * Output the content for the current step
- */
- public function setup_wizard_content() {
- isset( $this->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' ){
- ?>
- <p><?php echo esc_html__('You must first activate Taskereasy and update your server status before you can run demo import.', 'taskereasy'); ?></p>
- <?php
- $message = 0;
- $icon = 'dashicons-yes';
- $status = 'ta-success';
- $php_version = phpversion();
- $memory = wp_convert_hr_to_bytes( ini_get('memory_limit') );
- if( version_compare($php_version, '5.2.4', '<') ){
- $icon = 'dashicons-warning';
- $status = 'ta-warning';
- $message = 1;
- }
- ?>
- <table class="ta-status-table">
- <tbody>
- <tr>
- <th class="ta-status-heading ta-status"><span class="dashicons <?php echo esc_attr( $icon ) ?> <?php echo esc_attr( $status ) ?>"></span><?php echo esc_html('PHP Version', 'taskereasy') ?></th>
- <td class="ta-status-message <?php echo esc_attr( $status ) ?>"><?php if( $message ){ echo __('You are using an outdated PHP version.', 'taskereasy'); } ?></td>
- <td class="ta-status-value <?php echo esc_attr( $status ) ?>"><?php echo esc_html( $php_version ) ?></td>
- </tr>
- <?php
- $message = 0;
- $icon = 'dashicons-yes';
- $status = 'ta-success';
- if( $memory < 64000000 ){
- $icon = 'dashicons-warning';
- $status = 'ta-warning';
- $message = 1;
- }
- ?>
- <tr>
- <th class="ta-status-heading ta-status"><span class="dashicons <?php echo esc_attr( $icon ) ?> <?php echo esc_attr( $status ) ?>"></span><?php echo esc_html('WordPress Memory Limit', 'taskereasy') ?></th>
- <td class="ta-status-message <?php echo esc_attr( $status ) ?>"><?php if( $message ){ echo __('A Minimum memory limit of <strong>64MB is required</strong>. <a href="http://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP" target="_blank">Learn More</a>', 'taskereasy'); } ?></td>
- <td class="ta-status-value <?php echo esc_attr( $status ) ?>"><?php echo esc_html( size_format($memory) ) ?></td>
- </tr>
- <?php
- $message = 0;
- $icon = 'dashicons-yes';
- $status = 'ta-success';
- $exec_time = @ini_get('max_execution_time');
- if ( $exec_time < 180 && $exec_time != 0 ) {
- $icon = 'dashicons-warning';
- $status = 'ta-warning';
- $message = 1;
- }
- ?>
- <tr>
- <th class="ta-status-heading ta-status"><span class="dashicons <?php echo esc_attr( $icon ) ?> <?php echo esc_attr( $status ) ?>"></span><?php echo esc_html('PHP Execution Time Limit', 'taskereasy') ?></th>
- <td class="ta-status-message <?php echo esc_attr( $status ) ?>"><?php if( $message ){ echo __('We recommend setting max execution time to at least 180 for data import. <a href="http://codex.wordpress.org/Common_WordPress_Errors#Maximum_execution_time_exceeded" target="_blank">Learn More</a>', 'taskereasy'); } ?></td>
- <td class="ta-status-value <?php echo esc_attr( $status ) ?>"><?php echo esc_html($exec_time); ?></td>
- </tr>
- <?php
- $message = 0;
- $icon = 'dashicons-yes';
- $status = 'ta-success';
- if( empty($ss_status) || $ss_status != 'activated' ) {
- $icon = 'dashicons-warning';
- $status = 'ta-warning';
- $message = 1;
- }
- $active_status = ( empty($ss_status) || $ss_status != 'activated' ) ? 'Inactive' : 'Activated';
- ?>
- <tr>
- <th class="ta-status-heading ta-status"><span class="dashicons <?php echo esc_attr( $icon ) ?> <?php echo esc_attr( $status ) ?>"></span> <?php echo esc_html('Taskereasy Status', 'taskereasy') ?></th>
- <td class="ta-status-message <?php echo esc_attr( $status ) ?>"><?php if( $message ){ echo __('Verify Your Taskereasy License to benefit from all the features <a href="http://codex.wordpress.org/Common_WordPress_Errors#Maximum_execution_time_exceeded" target="_blank">Learn More</a>', 'taskereasy'); } ?></td>
- <td class="ta-status-value <?php echo esc_attr( $status ) ?>"><?php echo esc_html($active_status, 'taskereasy'); ?></td>
- </tr>
- </tbody>
- </table>
- <a href="<?php echo esc_url( wp_get_referer() && ! strpos( wp_get_referer(), 'update.php' ) ? wp_get_referer() : admin_url( '' ) ); ?>"
- class="secondary-button bold"><?php esc_html_e( 'Cancel', 'taskereasy' ); ?></a>
- <p></p>
- <?php
- }elseif ( $this->is_possible_upgrade() ) {
- ?>
- <h1><?php printf( esc_html__( 'Welcome to the Easy Setup Assistant for %s.', 'taskereasy' ), wp_get_theme() ); ?></h1>
- <p><?php esc_html_e( 'It looks like you may have recently upgraded to this theme. Great! This setup wizard will help ensure all the default settings are correct. It will also show some information about your new website and support options.', 'taskereasy' ); ?></p>
- <p class="envato-setup-actions step">
- <a href="<?php echo esc_url( wp_get_referer() && ! strpos( wp_get_referer(), 'update.php' ) ? wp_get_referer() : admin_url( '' ) ); ?>"
- class="secondary-button bold"><?php esc_html_e( 'Cancel', 'taskereasy' ); ?>
- </a>
- <?php if( $theme_status == 'activated' ){ ?>
- <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
- class="main-button button-next bold pull-right"><?php esc_html_e( 'Run Setup Wizard', 'taskereasy' ); ?>
- </a>
- <?php } ?>
- </p>
- <?php
- } else if ( get_option( 'envato_setup_complete', false ) ) {
- ?>
- <h1><?php printf( esc_html__( 'Welcome to the Easy Setup Assistant for %s.', 'taskereasy' ), wp_get_theme() ); ?></h1>
- <p><?php esc_html_e( 'It looks like you have already run the setup wizard. ', 'taskereasy' ); ?></p>
- <p class="envato-setup-actions step">
- <a href="<?php echo esc_url( wp_get_referer() && ! strpos( wp_get_referer(), 'update.php' ) ? wp_get_referer() : admin_url( '' ) ); ?>"
- class="secondary-button bold"><?php esc_html_e( 'Cancel', 'taskereasy' ); ?></a>
- <?php if( $theme_status == 'activated' ){ ?>
- <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
- class="main-button button-next bold pull-right"><?php esc_html_e( 'Run Setup Wizard Again', 'taskereasy' ); ?>
- </a>
- <?php }?>
- </p>
- <?php
- } else {
- ?>
- <h1><?php printf( esc_html__( 'Welcome to the Easy Setup Assistant!', 'taskereasy' ), wp_get_theme() ); ?></h1>
- <p><?php printf( esc_html__( 'Thank you for choosing %s. This quick setup wizard will help you configure your new website. This wizard will install the required WordPress plugins, and demo content. It should only take 5 minutes.', 'taskereasy' ), wp_get_theme() ); ?><br/></p>
- <p><?php esc_html_e( 'No time right now? Skip and return to the WordPress dashboard. Come back anytime if you change your mind!', 'taskereasy' ); ?></p>
- <p class="envato-setup-actions step">
- <a href="<?php echo esc_url( wp_get_referer() && ! strpos( wp_get_referer(), 'update.php' ) ? wp_get_referer() : admin_url( '' ) ); ?>"
- class="secondary-button bold"><?php esc_html_e( 'Cancel', 'taskereasy' ); ?></a>
- <?php if( $theme_status == 'activated' ){ ?>
- <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
- class="main-button button-next bold pull-right"><?php esc_html_e( 'Run Setup Wizard', 'taskereasy' ); ?>
- </a>
- <?php } ?>
- </p>
- <?php
- }
- }
- public function filter_options( $options ) {
- return $options;
- }
- private function _get_plugins() {
- $instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
- $plugins = array(
- 'all' => 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 */
- ?>
- <h1><?php esc_html_e( "Let's Install Required Plugins", 'taskereasy' ); ?></h1>
- <form method="post">
- <?php
- $plugins = $this->_get_plugins();
- if ( count( $plugins['all'] ) ) {
- ?>
- <p><?php esc_html_e( 'Your website needs a few essential plugins. The following plugins will be installed or updated:', 'taskereasy' ); ?></p>
- <ul class="envato-wizard-plugins">
- <?php foreach ( $plugins['all'] as $slug => $plugin ) { ?>
- <li data-slug="<?php echo esc_attr( $slug ); ?>"><?php echo esc_html( $plugin['name'] ); ?>
- <span>
- <?php
- $keys = array();
- if ( isset( $plugins['install'][ $slug ] ) ) {
- $keys[] = 'Installation';
- }
- if ( isset( $plugins['update'][ $slug ] ) ) {
- $keys[] = 'Update';
- }
- if ( isset( $plugins['activate'][ $slug ] ) ) {
- $keys[] = 'Activation';
- }
- echo implode( ' and ', $keys ) . ' required';
- ?>
- </span>
- <div class="spinner"></div>
- </li>
- <?php } ?>
- </ul>
- <?php
- } else {
- echo '<p><strong>' . esc_html_e( 'Good news! All plugins are already installed and up to date. Please continue.', 'taskereasy' ) . '</strong></p>';
- } ?>
- <p><?php esc_html_e( 'You can add and remove plugins later on from within WordPress. Click Continue to install', 'taskereasy' ); ?></p>
- <p class="envato-setup-actions step">
- <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
- class="secondary-button bold button-next"><?php esc_html_e( 'Skip this step', 'taskereasy' ); ?></a>
- <?php wp_nonce_field( 'envato-setup' ); ?>
- <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
- class="main-button bold pull-right button-next"
- data-callback="install_plugins"><?php esc_html_e( 'Continue','taskereasy' ); ?></a>
- </p>
- </form>
- <?php
- }
- public function ajax_plugins() {
- if ( ! check_ajax_referer( 'envato_setup_nonce', 'wpnonce' ) || empty( $_POST['slug'] ) ) {
- wp_send_json_error( array( 'error' => 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() {
- ?>
- <h1><?php esc_html_e( 'Let us Import Dummy Content', 'taskereasy' ); ?></h1>
- <form method="post">
- <?php if ( $this->is_possible_upgrade() ) { ?>
- <p><?php esc_html_e( 'It looks like you already have content installed on this website. If you would like to install the default demo content as well you can select it below. Otherwise just choose the upgrade option to ensure everything is up to date.', 'taskereasy' ); ?></p>
- <?php } else { ?>
- <p><?php printf( esc_html__( "It's time to import some dummy content for your new site. Click Import Content and once imported, this content can be managed from the WordPress admin dashboard. If you dont like to import, click Skip this step. ", 'taskereasy' ), '<a href="' . esc_url( admin_url( 'edit.php?post_type=page' ) ) . '" target="_blank">', '</a>' ); ?></p>
- <?php } ?>
- <div class="content-importer-response">
- <div id="importer-response" class="clear pos-relative">
- <span class="res-text"></span>
- <img class="loadinerSearch" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/ajax-load.gif' ?>">
- <img class="checkImg" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/check-img.png' ?>">
- </div>
- <div id="importer-response-menu" class="clear pos-relative">
- <span class="res-text"></span>
- <img class="loadinerSearch" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/ajax-load.gif' ?>">
- <img class="checkImg" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/check-img.png' ?>">
- </div>
- <div id="importer-response-homepage" class="clear pos-relative">
- <span class="res-text"></span>
- <img class="loadinerSearch" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/ajax-load.gif' ?>">
- <img class="checkImg" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/check-img.png' ?>">
- </div>
- <div id="importer-response-themeoptions" class="clear pos-relative">
- <span class="res-text"></span>
- <img class="loadinerSearch" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/ajax-load.gif' ?>">
- <img class="checkImg" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/check-img.png' ?>">
- </div>
- <div class="clear"></div>
- </div>
- <p class="envato-setup-actions step">
- <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
- class="secondary-button bold button-next button-next-skip"><?php esc_html_e( 'Skip this step', 'taskereasy' ); ?></a>
- <a href="#" class="ta-import-content main-button bold pull-right"><?php esc_html_e( 'Import Content', 'taskereasy' ); ?></a>
- <?php wp_nonce_field( 'envato-setup' ); ?>
- </p>
- </form>
- <?php
- }
- public function setup_content() {
- $themeSelectedStyle = get_theme_mod('dtbwp_site_style',$this->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() {
- ?>
- <div class="envato-setup-first-step-container envato-setup-first-step-containerwelcome plugins-container-heading">
- <h1><?php printf( esc_html__( "Select one of our pre-built demos.", 'taskereasy' ), wp_get_theme() ); ?></h1>
- </div>
- <form method="post" class="ta-demo-content-import-container">
- <div class="plugins-container-inner">
- <div class="theme-presets ta-select-demo-outer">
- <ul>
- <?php
- $current_style = get_theme_mod( 'dtbwp_site_style', $this->get_default_theme_style() );
- $stylecls = '';
- $i = 0;
- foreach ( $this->site_styles as $style_name => $style_data ) {
- ?>
- <li class="ta-imp-demo <?php if($i == 0){ echo 'current'; } ?>">
- <div class="ta-select-demo">
- <div class="ta-select-demo-image">
- <a href="#" data-style="<?php echo esc_attr( $style_name ); ?>"></a>
- <img style="width:100%;" src="<?php echo get_template_directory_uri().'/setup/content/demos/'.$style_name.'/style.jpg' ?>"/>
- <?php if('style1' == $style_name){
- $stylecls = 'opacity:1;visibility:visible';
- }else{
- $stylecls = '';
- } ?>
- <div class="ta-select-demo-image-overlay" style="<?php echo esc_attr( $stylecls ); ?>"></div>
- <div class="ta-select-demo-image-overlay-link" style="<?php echo esc_attr( $stylecls ); ?>">
- <a href="" class="ta-current-demo"></a>
- </div>
- </div>
- <div class="ta-ad-pri1ce-content text-center">
- <?php if('style1' == $style_name){ ?>
- <h5><?php echo esc_html__('Home 1', 'taskereasy') ?></h5>
- <a class="main-button bold" href="https://slidesigma.com/themes/wp/taskereasy/" target="_blank"><?php printf( esc_html__( 'Preview', 'taskereasy' ) ); ?></a>
- <?php } ?>
- <?php if('style2' == $style_name){ ?>
- <h5><?php echo esc_html__('Home 2', 'taskereasy') ?></h5>
- <a class="main-button bold" href="https://slidesigma.com/themes/wp/taskereasy/home-2/" target="_blank"><?php printf( esc_html__( 'Preview', 'taskereasy' ) ); ?></a>
- <?php } ?>
- <?php if('style3' == $style_name){ ?>
- <h5><?php echo esc_html__('Home 3', 'taskereasy') ?></h5>
- <a class="main-button bold" href="https://slidesigma.com/themes/wp/taskereasy/home-3/" target="_blank"><?php printf( esc_html__( 'Preview', 'taskereasy' ) ); ?></a>
- <?php } ?>
- <?php if('style4' == $style_name){ ?>
- <h5><?php echo esc_html__('Home 4', 'taskereasy') ?></h5>
- <a class="main-button bold" href="https://slidesigma.com/themes/wp/taskereasy/home-4/" target="_blank"><?php printf( esc_html__( 'Preview', 'taskereasy' ) ); ?></a>
- <?php } ?>
- </div>
- </div>
- </li>
- <?php
- $i++;
- }
- ?>
- </ul>
- </div>
- <div class="clearfix"></div>
- <input type="hidden" name="new_style" id="new_style" value="style1">
- <p class="envato-setup-actions step">
- <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
- class="secondary-button bold button-next"><?php esc_html_e( 'No, Maybe Later', 'taskereasy' ); ?></a>
- <?php wp_nonce_field( 'envato-setup' ); ?>
- <input type="submit" class="main-button bold pointer pull-right button-next"
- value="<?php esc_attr_e( 'Yes, i am ready. ', 'taskereasy' ); ?>" name="save_step"/>
- </p>
- </div>
- </form>
- <?php
- }
- public function envato_setup_color_style_save() {
- check_admin_referer( 'envato-setup' );
- $new_style = isset( $_POST['new_style'] ) ? $_POST['new_style'] : false;
- if ( $new_style ) {
- set_theme_mod( 'dtbwp_site_style', $new_style );
- }
- wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
- exit;
- }
- public function envato_setup_ready() {
- update_option( 'envato_setup_complete', time() );
- update_option( 'dtbwp_update_notice', strtotime('-4 days') );
- ?>
- <h1><?php esc_html_e( 'Your Website is Ready!', 'taskereasy' ); ?></h1>
- <img src="<?php echo get_template_directory_uri(); ?>/assets/images/misc/congrats.png"/>
- <p class="ta-redirect-page-pragrahi"><?php esc_html_e( 'Your are being redirected to the welcome page.', 'taskereasy' ); ?></p>
- <?php
- $welcomePargeURL = admin_url().'themes.php?page=taskereasy';
- header("refresh:3;url=$welcomePargeURL");
- }
- private static $_current_manage_token = false;
- public function ajax_notice_handler() {
- check_ajax_referer( 'dtnwp-ajax-nonce', 'security' );
- // Store it in the options table
- update_option( 'dtbwp_update_notice', time() );
- }
- private function _array_merge_recursive_distinct( $array1, $array2 ) {
- $merged = $array1;
- foreach ( $array2 as $key => &$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;
|