envato_setup.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. <?php
  2. /**
  3. * Envato Theme Setup Wizard Class
  4. *
  5. * Takes new users through some basic steps to setup their theme.
  6. *
  7. */
  8. if ( ! defined( 'ABSPATH' ) ) {
  9. exit;
  10. }
  11. if ( ! class_exists( 'Envato_Theme_Setup_Wizard' ) ) {
  12. class Envato_Theme_Setup_Wizard {
  13. protected $version = '1.3.0';
  14. protected $theme_name = '';
  15. protected $envato_username = '';
  16. protected $oauth_script = '';
  17. protected $step = '';
  18. protected $steps = array();
  19. protected $plugin_path = '';
  20. protected $plugin_url = '';
  21. protected $page_slug;
  22. protected $tgmpa_instance;
  23. protected $tgmpa_menu_slug = 'tgmpa-install-plugins';
  24. protected $tgmpa_url = 'themes.php?page=tgmpa-install-plugins';
  25. protected $page_parent;
  26. protected $page_url;
  27. public $site_styles = array();
  28. private static $instance = null;
  29. public static function get_instance() {
  30. if ( ! self::$instance ) {
  31. self::$instance = new self;
  32. }
  33. return self::$instance;
  34. }
  35. public function __construct() {
  36. $this->init_globals();
  37. $this->init_actions();
  38. }
  39. public function init_globals() {
  40. $current_theme = wp_get_theme();
  41. $this->page_slug = apply_filters( $this->theme_name . '_theme_setup_wizard_page_slug', $this->theme_name . '-setup' );
  42. $this->parent_slug = apply_filters( $this->theme_name . '_theme_setup_wizard_parent_slug', '' );
  43. // create an images/styleX/ folder for each style here.
  44. $this->site_styles = array(
  45. 'style1' => 'Style 1',
  46. 'style2' => 'Style 2',
  47. 'style3' => 'Style 3',
  48. 'style4' => 'Style 4',
  49. );
  50. //If we have parent slug - set correct url
  51. if ( $this->parent_slug !== '' ) {
  52. $this->page_url = 'admin.php?page=' . $this->page_slug;
  53. } else {
  54. $this->page_url = 'themes.php?page=' . $this->page_slug;
  55. }
  56. $this->page_url = apply_filters( $this->theme_name . '_theme_setup_wizard_page_url', $this->page_url );
  57. //set relative plugin path url
  58. $this->plugin_path = trailingslashit( $this->cleanFilePath( dirname( __FILE__ ) ) );
  59. $relative_url = str_replace( $this->cleanFilePath( get_template_directory() ), '', $this->plugin_path );
  60. $this->plugin_url = trailingslashit( get_template_directory_uri() . $relative_url );
  61. }
  62. public function init_actions() {
  63. if ( apply_filters( $this->theme_name . '_enable_setup_wizard', true ) && current_user_can( 'manage_options' ) ) {
  64. add_action( 'after_switch_theme', array( $this, 'switch_theme' ) );
  65. if ( class_exists( 'TGM_Plugin_Activation' ) && isset( $GLOBALS['tgmpa'] ) ) {
  66. add_action( 'init', array( $this, 'get_tgmpa_instanse' ), 30 );
  67. add_action( 'init', array( $this, 'set_tgmpa_url' ), 40 );
  68. }
  69. add_action( 'admin_menu', array( $this, 'admin_menus' ) );
  70. add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
  71. add_action( 'admin_init', array( $this, 'admin_redirects' ), 30 );
  72. add_action( 'admin_init', array( $this, 'init_wizard_steps' ), 30 );
  73. add_action( 'admin_init', array( $this, 'setup_wizard' ), 30 );
  74. add_filter( 'tgmpa_load', array( $this, 'tgmpa_load' ), 10, 1 );
  75. add_action( 'wp_ajax_envato_setup_plugins', array( $this, 'ajax_plugins' ) );
  76. add_action( 'wp_ajax_envato_setup_content', array( $this, 'ajax_content' ) );
  77. add_action( 'wp_ajax_taskereasy_menu', array( $this, 'taskereasy_menu' ) );
  78. add_action( 'wp_ajax_setup_content', array( $this, 'setup_content' ) );
  79. add_action( 'wp_ajax_taskereasy_homepage', array( $this, 'taskereasy_homepage' ) );
  80. add_action( 'wp_ajax_taskereasy_theme_options', array( $this, 'taskereasy_theme_options' ) );
  81. }
  82. add_action( 'upgrader_post_install', array( $this, 'upgrader_post_install' ), 10, 2 );
  83. }
  84. /**
  85. * After a theme update we clear the setup_complete option. This prompts the user to visit the update page again.
  86. */
  87. public function upgrader_post_install( $return, $theme ) {
  88. if ( is_wp_error( $return ) ) {
  89. return $return;
  90. }
  91. if ( $theme != get_stylesheet() ) {
  92. return $return;
  93. }
  94. update_option( 'envato_setup_complete', false );
  95. return $return;
  96. }
  97. /**
  98. * 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.
  99. *
  100. */
  101. public function is_possible_upgrade() {
  102. return false;
  103. }
  104. public function enqueue_scripts() {
  105. }
  106. public function tgmpa_load( $status ) {
  107. return is_admin() || current_user_can( 'install_themes' );
  108. }
  109. public function switch_theme() {
  110. set_transient( '_' . $this->theme_name . '_activation_redirect', 1 );
  111. }
  112. public function admin_redirects() {
  113. if ( ! get_transient( '_' . $this->theme_name . '_activation_redirect' ) || get_option( 'envato_setup_complete', false ) ) {
  114. return;
  115. }
  116. delete_transient( '_' . $this->theme_name . '_activation_redirect' );
  117. wp_redirect( admin_url( $this->page_url ) );
  118. exit();
  119. }
  120. public function get_default_theme_style() {
  121. return 'style1';
  122. }
  123. /**
  124. * Get configured TGMPA instance
  125. *
  126. * @access public
  127. * @since 1.1.2
  128. */
  129. public function get_tgmpa_instanse() {
  130. $this->tgmpa_instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
  131. }
  132. /**
  133. * Update $tgmpa_menu_slug and $tgmpa_parent_slug from TGMPA instance
  134. *
  135. * @access public
  136. * @since 1.1.2
  137. */
  138. public function set_tgmpa_url() {
  139. $this->tgmpa_menu_slug = ( property_exists( $this->tgmpa_instance, 'menu' ) ) ? $this->tgmpa_instance->menu : $this->tgmpa_menu_slug;
  140. $this->tgmpa_menu_slug = apply_filters( $this->theme_name . '_theme_setup_wizard_tgmpa_menu_slug', $this->tgmpa_menu_slug );
  141. $tgmpa_parent_slug = ( property_exists( $this->tgmpa_instance, 'parent_slug' ) && $this->tgmpa_instance->parent_slug !== 'themes.php' ) ? 'admin.php' : 'themes.php';
  142. $this->tgmpa_url = apply_filters( $this->theme_name . '_theme_setup_wizard_tgmpa_url', $tgmpa_parent_slug . '?page=' . $this->tgmpa_menu_slug );
  143. }
  144. /**
  145. * Add admin menus/screens.
  146. */
  147. public function admin_menus() {
  148. if ( $this->is_submenu_page() ) {
  149. //prevent Theme Check warning about "themes should use add_theme_page for adding admin pages"
  150. $add_subpage_function = 'add_submenu' . '_page';
  151. $add_subpage_function( $this->parent_slug, esc_html__( 'Setup Wizard', 'taskereasy' ), esc_html__( 'Setup Wizard', 'taskereasy' ), 'manage_options', $this->page_slug, array(
  152. $this,
  153. 'setup_wizard',
  154. ) );
  155. } else {
  156. add_theme_page( esc_html__( 'Setup Wizard', 'taskereasy' ), esc_html__( 'Setup Wizard', 'taskereasy' ), 'manage_options', $this->page_slug, array(
  157. $this,
  158. 'setup_wizard',
  159. ) );
  160. }
  161. }
  162. /**
  163. * Setup steps.
  164. *
  165. * @since 1.1.1
  166. * @access public
  167. * @return array
  168. */
  169. public function init_wizard_steps() {
  170. $this->steps = array(
  171. 'introduction' => array(
  172. 'name' => esc_html__( 'Introduction', 'taskereasy' ),
  173. 'view' => array( $this, 'envato_setup_introduction' ),
  174. 'handler' => array( $this, '' ),
  175. ),
  176. );
  177. if ( class_exists( 'TGM_Plugin_Activation' ) && isset( $GLOBALS['tgmpa'] ) ) {
  178. $this->steps['default_plugins'] = array(
  179. 'name' => esc_html__( 'Plugins', 'taskereasy' ),
  180. 'view' => array( $this, 'envato_setup_default_plugins' ),
  181. 'handler' => '',
  182. );
  183. }
  184. if( count($this->site_styles) > 1 ) {
  185. $this->steps['style'] = array(
  186. 'name' => esc_html__( 'Demos', 'taskereasy' ),
  187. 'view' => array( $this, 'envato_setup_color_style' ),
  188. 'handler' => array( $this, 'envato_setup_color_style_save' ),
  189. );
  190. }
  191. $this->steps['default_content'] = array(
  192. 'name' => esc_html__( 'Content' , 'taskereasy'),
  193. 'view' => array( $this, 'envato_setup_default_content' ),
  194. 'handler' => '',
  195. );
  196. $this->steps['next_steps'] = array(
  197. 'name' => esc_html__( 'Ready!', 'taskereasy' ),
  198. 'view' => array( $this, 'envato_setup_ready' ),
  199. 'handler' => '',
  200. );
  201. $this->steps = apply_filters( $this->theme_name . '_theme_setup_wizard_steps', $this->steps );
  202. }
  203. /**
  204. * Show the setup wizard
  205. */
  206. public function setup_wizard() {
  207. if ( empty( $_GET['page'] ) || $this->page_slug !== $_GET['page'] ) {
  208. return;
  209. }
  210. $this->step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : current( array_keys( $this->steps ) );
  211. wp_register_script( 'jquery-blockui', $this->plugin_url . 'js/jquery.blockUI.js', array( 'jquery' ), '2.70', true );
  212. wp_register_script( 'envato-setup', $this->plugin_url . 'js/envato-setup.js', array(
  213. 'jquery',
  214. 'jquery-blockui',
  215. ), $this->version );
  216. wp_localize_script( 'envato-setup', 'envato_setup_params', array(
  217. 'tgm_plugin_nonce' => array(
  218. 'update' => wp_create_nonce( 'tgmpa-update' ),
  219. 'install' => wp_create_nonce( 'tgmpa-install' ),
  220. ),
  221. 'tgm_bulk_url' => admin_url( $this->tgmpa_url ),
  222. 'ajaxurl' => admin_url( 'admin-ajax.php' ),
  223. 'wpnonce' => wp_create_nonce( 'envato_setup_nonce' ),
  224. 'verify_text' => esc_html__( '...verifying' , 'taskereasy'),
  225. ) );
  226. //wp_enqueue_style( 'envato_wizard_admin_styles', $this->plugin_url . '/css/admin.css', array(), $this->version );
  227. wp_enqueue_style( 'envato-setup', $this->plugin_url . 'css/envato-setup.css', array(
  228. 'wp-admin',
  229. 'dashicons',
  230. 'install',
  231. ), $this->version );
  232. //enqueue style for admin notices
  233. wp_enqueue_style( 'wp-admin' );
  234. wp_enqueue_media();
  235. wp_enqueue_script( 'media' );
  236. ob_start();
  237. $this->setup_wizard_header();
  238. $this->setup_wizard_steps();
  239. $show_content = true;
  240. echo '<div class="envato-setup-content">';
  241. if ( ! empty( $_REQUEST['save_step'] ) && isset( $this->steps[ $this->step ]['handler'] ) ) {
  242. $show_content = call_user_func( $this->steps[ $this->step ]['handler'] );
  243. }
  244. if ( $show_content ) {
  245. $this->setup_wizard_content();
  246. }
  247. echo '</div>';
  248. $this->setup_wizard_footer();
  249. exit;
  250. }
  251. public function get_step_link( $step ) {
  252. return add_query_arg( 'step', $step, admin_url( 'admin.php?page=' . $this->page_slug ) );
  253. }
  254. public function get_next_step_link() {
  255. $keys = array_keys( $this->steps );
  256. return add_query_arg( 'step', $keys[ array_search( $this->step, array_keys( $this->steps ) ) + 1 ], remove_query_arg( 'translation_updated' ) );
  257. }
  258. /**
  259. * Setup Wizard Header
  260. */
  261. public function setup_wizard_header() {
  262. ?>
  263. <!DOCTYPE html>
  264. <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
  265. <head>
  266. <meta name="viewport" content="width=device-width"/>
  267. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  268. <?php
  269. // avoid theme check issues.
  270. echo '<t';
  271. echo 'itle>' . esc_html__( 'Taskereasy &rsaquo; Setup Wizard', 'taskereasy' ) . '</ti' . 'tle>'; ?>
  272. <?php wp_print_scripts( 'envato-setup' ); ?>
  273. <?php do_action( 'admin_print_styles' ); ?>
  274. <?php do_action( 'admin_print_scripts' ); ?>
  275. <?php do_action( 'admin_head' ); ?>
  276. </head>
  277. <body class="envato-setup wp-core-ui">
  278. <h1 id="wc-logo">
  279. <a href="https://themeforest.net/item/taskereasy-multipurpose-business-corporate-wordpress-theme/23832008" target="_blank">
  280. <img src="<?php echo get_template_directory_uri(); ?>/assets/images/logo.png" alt="Taskereasy" />
  281. </a>
  282. </h1>
  283. <?php
  284. }
  285. /**
  286. * Setup Wizard Footer
  287. */
  288. public function setup_wizard_footer() {
  289. ?>
  290. <?php if ( 'next_steps' === $this->step ) : ?>
  291. <a class="wc-return-to-dashboard"
  292. href="<?php echo esc_url( admin_url() ); ?>"><?php esc_html_e( 'Return to the WordPress Dashboard', 'taskereasy' ); ?></a>
  293. <?php endif; ?>
  294. </body>
  295. <?php
  296. do_action( 'admin_footer' );
  297. do_action( 'admin_print_footer_scripts' );
  298. ?>
  299. </html>
  300. <?php
  301. }
  302. /**
  303. * Output the steps
  304. */
  305. public function setup_wizard_steps() {
  306. $ouput_steps = $this->steps;
  307. array_shift( $ouput_steps );
  308. ?>
  309. <ol class="envato-setup-steps">
  310. <?php foreach ( $ouput_steps as $step_key => $step ) : ?>
  311. <li class="<?php
  312. $show_link = false;
  313. if ( $step_key === $this->step ) {
  314. echo 'active';
  315. } elseif ( array_search( $this->step, array_keys( $this->steps ) ) > array_search( $step_key, array_keys( $this->steps ) ) ) {
  316. echo 'done';
  317. $show_link = true;
  318. }
  319. ?>"><?php
  320. if ( $show_link ) {
  321. ?>
  322. <a href="<?php echo esc_url( $this->get_step_link( $step_key ) ); ?>"><?php echo esc_html( $step['name'] ); ?></a>
  323. <?php
  324. } else {
  325. echo esc_html( $step['name'] );
  326. }
  327. ?></li>
  328. <?php endforeach; ?>
  329. </ol>
  330. <?php
  331. }
  332. /**
  333. * Output the content for the current step
  334. */
  335. public function setup_wizard_content() {
  336. isset( $this->steps[ $this->step ] ) ? call_user_func( $this->steps[ $this->step ]['view'] ) : false;
  337. }
  338. /**
  339. * Introduction step
  340. */
  341. public function envato_setup_introduction() {
  342. $theme_status = get_option( 'theme_activation' );
  343. if( $theme_status != 'activated' ){
  344. ?>
  345. <p><?php echo esc_html__('You must first activate Taskereasy and update your server status before you can run demo import.', 'taskereasy'); ?></p>
  346. <?php
  347. $message = 0;
  348. $icon = 'dashicons-yes';
  349. $status = 'ta-success';
  350. $php_version = phpversion();
  351. $memory = wp_convert_hr_to_bytes( ini_get('memory_limit') );
  352. if( version_compare($php_version, '5.2.4', '<') ){
  353. $icon = 'dashicons-warning';
  354. $status = 'ta-warning';
  355. $message = 1;
  356. }
  357. ?>
  358. <table class="ta-status-table">
  359. <tbody>
  360. <tr>
  361. <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>
  362. <td class="ta-status-message <?php echo esc_attr( $status ) ?>"><?php if( $message ){ echo __('You are using an outdated PHP version.', 'taskereasy'); } ?></td>
  363. <td class="ta-status-value <?php echo esc_attr( $status ) ?>"><?php echo esc_html( $php_version ) ?></td>
  364. </tr>
  365. <?php
  366. $message = 0;
  367. $icon = 'dashicons-yes';
  368. $status = 'ta-success';
  369. if( $memory < 64000000 ){
  370. $icon = 'dashicons-warning';
  371. $status = 'ta-warning';
  372. $message = 1;
  373. }
  374. ?>
  375. <tr>
  376. <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>
  377. <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>
  378. <td class="ta-status-value <?php echo esc_attr( $status ) ?>"><?php echo esc_html( size_format($memory) ) ?></td>
  379. </tr>
  380. <?php
  381. $message = 0;
  382. $icon = 'dashicons-yes';
  383. $status = 'ta-success';
  384. $exec_time = @ini_get('max_execution_time');
  385. if ( $exec_time < 180 && $exec_time != 0 ) {
  386. $icon = 'dashicons-warning';
  387. $status = 'ta-warning';
  388. $message = 1;
  389. }
  390. ?>
  391. <tr>
  392. <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>
  393. <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>
  394. <td class="ta-status-value <?php echo esc_attr( $status ) ?>"><?php echo esc_html($exec_time); ?></td>
  395. </tr>
  396. <?php
  397. $message = 0;
  398. $icon = 'dashicons-yes';
  399. $status = 'ta-success';
  400. if( empty($ss_status) || $ss_status != 'activated' ) {
  401. $icon = 'dashicons-warning';
  402. $status = 'ta-warning';
  403. $message = 1;
  404. }
  405. $active_status = ( empty($ss_status) || $ss_status != 'activated' ) ? 'Inactive' : 'Activated';
  406. ?>
  407. <tr>
  408. <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>
  409. <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>
  410. <td class="ta-status-value <?php echo esc_attr( $status ) ?>"><?php echo esc_html($active_status, 'taskereasy'); ?></td>
  411. </tr>
  412. </tbody>
  413. </table>
  414. <a href="<?php echo esc_url( wp_get_referer() && ! strpos( wp_get_referer(), 'update.php' ) ? wp_get_referer() : admin_url( '' ) ); ?>"
  415. class="secondary-button bold"><?php esc_html_e( 'Cancel', 'taskereasy' ); ?></a>
  416. <p></p>
  417. <?php
  418. }elseif ( $this->is_possible_upgrade() ) {
  419. ?>
  420. <h1><?php printf( esc_html__( 'Welcome to the Easy Setup Assistant for %s.', 'taskereasy' ), wp_get_theme() ); ?></h1>
  421. <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>
  422. <p class="envato-setup-actions step">
  423. <a href="<?php echo esc_url( wp_get_referer() && ! strpos( wp_get_referer(), 'update.php' ) ? wp_get_referer() : admin_url( '' ) ); ?>"
  424. class="secondary-button bold"><?php esc_html_e( 'Cancel', 'taskereasy' ); ?>
  425. </a>
  426. <?php if( $theme_status == 'activated' ){ ?>
  427. <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
  428. class="main-button button-next bold pull-right"><?php esc_html_e( 'Run Setup Wizard', 'taskereasy' ); ?>
  429. </a>
  430. <?php } ?>
  431. </p>
  432. <?php
  433. } else if ( get_option( 'envato_setup_complete', false ) ) {
  434. ?>
  435. <h1><?php printf( esc_html__( 'Welcome to the Easy Setup Assistant for %s.', 'taskereasy' ), wp_get_theme() ); ?></h1>
  436. <p><?php esc_html_e( 'It looks like you have already run the setup wizard. ', 'taskereasy' ); ?></p>
  437. <p class="envato-setup-actions step">
  438. <a href="<?php echo esc_url( wp_get_referer() && ! strpos( wp_get_referer(), 'update.php' ) ? wp_get_referer() : admin_url( '' ) ); ?>"
  439. class="secondary-button bold"><?php esc_html_e( 'Cancel', 'taskereasy' ); ?></a>
  440. <?php if( $theme_status == 'activated' ){ ?>
  441. <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
  442. class="main-button button-next bold pull-right"><?php esc_html_e( 'Run Setup Wizard Again', 'taskereasy' ); ?>
  443. </a>
  444. <?php }?>
  445. </p>
  446. <?php
  447. } else {
  448. ?>
  449. <h1><?php printf( esc_html__( 'Welcome to the Easy Setup Assistant!', 'taskereasy' ), wp_get_theme() ); ?></h1>
  450. <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>
  451. <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>
  452. <p class="envato-setup-actions step">
  453. <a href="<?php echo esc_url( wp_get_referer() && ! strpos( wp_get_referer(), 'update.php' ) ? wp_get_referer() : admin_url( '' ) ); ?>"
  454. class="secondary-button bold"><?php esc_html_e( 'Cancel', 'taskereasy' ); ?></a>
  455. <?php if( $theme_status == 'activated' ){ ?>
  456. <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
  457. class="main-button button-next bold pull-right"><?php esc_html_e( 'Run Setup Wizard', 'taskereasy' ); ?>
  458. </a>
  459. <?php } ?>
  460. </p>
  461. <?php
  462. }
  463. }
  464. public function filter_options( $options ) {
  465. return $options;
  466. }
  467. private function _get_plugins() {
  468. $instance = call_user_func( array( get_class( $GLOBALS['tgmpa'] ), 'get_instance' ) );
  469. $plugins = array(
  470. 'all' => array(), // Meaning: all plugins which still have open actions.
  471. 'install' => array(),
  472. 'update' => array(),
  473. 'activate' => array(),
  474. );
  475. foreach ( $instance->plugins as $slug => $plugin ) {
  476. if ( !$instance->can_plugin_activate( $slug ) && false === $instance->does_plugin_have_update( $slug ) ) {
  477. // No need to display plugins if they are installed, up-to-date and active.
  478. continue;
  479. } else {
  480. $plugins['all'][ $slug ] = $plugin;
  481. if ( ! $instance->is_plugin_installed( $slug ) ) {
  482. $plugins['install'][ $slug ] = $plugin;
  483. } else {
  484. if ( false !== $instance->does_plugin_have_update( $slug ) ) {
  485. $plugins['update'][ $slug ] = $plugin;
  486. }
  487. if ( $instance->can_plugin_activate( $slug ) ) {
  488. $plugins['activate'][ $slug ] = $plugin;
  489. }
  490. }
  491. }
  492. }
  493. return $plugins;
  494. }
  495. /**
  496. * Page setup
  497. */
  498. public function envato_setup_default_plugins() {
  499. tgmpa_load_bulk_installer();
  500. // install plugins with TGM.
  501. if ( ! class_exists( 'TGM_Plugin_Activation' ) || ! isset( $GLOBALS['tgmpa'] ) ) {
  502. die( 'Failed to find TGM' );
  503. }
  504. $url = wp_nonce_url( add_query_arg( array( 'plugins' => 'go' ) ), 'envato-setup' );
  505. $plugins = $this->_get_plugins();
  506. // copied from TGM
  507. $method = ''; // Leave blank so WP_Filesystem can populate it as necessary.
  508. $fields = array_keys( $_POST ); // Extra fields to pass to WP_Filesystem.
  509. if ( false === ( $creds = request_filesystem_credentials( esc_url_raw( $url ), $method, false, false, $fields ) ) ) {
  510. return true; // Stop the normal page form from displaying, credential request form will be shown.
  511. }
  512. // Now we have some credentials, setup WP_Filesystem.
  513. if ( ! WP_Filesystem( $creds ) ) {
  514. // Our credentials were no good, ask the user for them again.
  515. request_filesystem_credentials( esc_url_raw( $url ), $method, true, false, $fields );
  516. return true;
  517. }
  518. /* If we arrive here, we have the filesystem */
  519. ?>
  520. <h1><?php esc_html_e( "Let's Install Required Plugins", 'taskereasy' ); ?></h1>
  521. <form method="post">
  522. <?php
  523. $plugins = $this->_get_plugins();
  524. if ( count( $plugins['all'] ) ) {
  525. ?>
  526. <p><?php esc_html_e( 'Your website needs a few essential plugins. The following plugins will be installed or updated:', 'taskereasy' ); ?></p>
  527. <ul class="envato-wizard-plugins">
  528. <?php foreach ( $plugins['all'] as $slug => $plugin ) { ?>
  529. <li data-slug="<?php echo esc_attr( $slug ); ?>"><?php echo esc_html( $plugin['name'] ); ?>
  530. <span>
  531. <?php
  532. $keys = array();
  533. if ( isset( $plugins['install'][ $slug ] ) ) {
  534. $keys[] = 'Installation';
  535. }
  536. if ( isset( $plugins['update'][ $slug ] ) ) {
  537. $keys[] = 'Update';
  538. }
  539. if ( isset( $plugins['activate'][ $slug ] ) ) {
  540. $keys[] = 'Activation';
  541. }
  542. echo implode( ' and ', $keys ) . ' required';
  543. ?>
  544. </span>
  545. <div class="spinner"></div>
  546. </li>
  547. <?php } ?>
  548. </ul>
  549. <?php
  550. } else {
  551. echo '<p><strong>' . esc_html_e( 'Good news! All plugins are already installed and up to date. Please continue.', 'taskereasy' ) . '</strong></p>';
  552. } ?>
  553. <p><?php esc_html_e( 'You can add and remove plugins later on from within WordPress. Click Continue to install', 'taskereasy' ); ?></p>
  554. <p class="envato-setup-actions step">
  555. <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
  556. class="secondary-button bold button-next"><?php esc_html_e( 'Skip this step', 'taskereasy' ); ?></a>
  557. <?php wp_nonce_field( 'envato-setup' ); ?>
  558. <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
  559. class="main-button bold pull-right button-next"
  560. data-callback="install_plugins"><?php esc_html_e( 'Continue','taskereasy' ); ?></a>
  561. </p>
  562. </form>
  563. <?php
  564. }
  565. public function ajax_plugins() {
  566. if ( ! check_ajax_referer( 'envato_setup_nonce', 'wpnonce' ) || empty( $_POST['slug'] ) ) {
  567. wp_send_json_error( array( 'error' => 1, 'message' => esc_html__( 'No Slug Found', 'taskereasy' ) ) );
  568. }
  569. $json = array();
  570. // send back some json we use to hit up TGM
  571. $plugins = $this->_get_plugins();
  572. // what are we doing with this plugin?
  573. foreach ( $plugins['activate'] as $slug => $plugin ) {
  574. if ( $_POST['slug'] == $slug ) {
  575. $json = array(
  576. 'url' => admin_url( $this->tgmpa_url ),
  577. 'plugin' => array( $slug ),
  578. 'tgmpa-page' => $this->tgmpa_menu_slug,
  579. 'plugin_status' => 'all',
  580. '_wpnonce' => wp_create_nonce( 'bulk-plugins' ),
  581. 'action' => 'tgmpa-bulk-activate',
  582. 'action2' => - 1,
  583. 'message' => esc_html__( 'Activating Plugin', 'taskereasy' ),
  584. );
  585. break;
  586. }
  587. }
  588. foreach ( $plugins['update'] as $slug => $plugin ) {
  589. if ( $_POST['slug'] == $slug ) {
  590. $json = array(
  591. 'url' => admin_url( $this->tgmpa_url ),
  592. 'plugin' => array( $slug ),
  593. 'tgmpa-page' => $this->tgmpa_menu_slug,
  594. 'plugin_status' => 'all',
  595. '_wpnonce' => wp_create_nonce( 'bulk-plugins' ),
  596. 'action' => 'tgmpa-bulk-update',
  597. 'action2' => - 1,
  598. 'message' => esc_html__( 'Updating Plugin', 'taskereasy' ),
  599. );
  600. break;
  601. }
  602. }
  603. foreach ( $plugins['install'] as $slug => $plugin ) {
  604. if ( $_POST['slug'] == $slug ) {
  605. $json = array(
  606. 'url' => admin_url( $this->tgmpa_url ),
  607. 'plugin' => array( $slug ),
  608. 'tgmpa-page' => $this->tgmpa_menu_slug,
  609. 'plugin_status' => 'all',
  610. '_wpnonce' => wp_create_nonce( 'bulk-plugins' ),
  611. 'action' => 'tgmpa-bulk-install',
  612. 'action2' => - 1,
  613. 'message' => esc_html__( 'Installing Plugin' , 'taskereasy'),
  614. );
  615. break;
  616. }
  617. }
  618. if ( $json ) {
  619. $json['hash'] = md5( serialize( $json ) ); // used for checking if duplicates happen, move to next plugin
  620. wp_send_json( $json );
  621. } else {
  622. wp_send_json( array( 'done' => 1, 'message' => esc_html__( 'Success', 'taskereasy' ) ) );
  623. }
  624. exit;
  625. }
  626. public function envato_setup_default_content() {
  627. ?>
  628. <h1><?php esc_html_e( 'Let us Import Dummy Content', 'taskereasy' ); ?></h1>
  629. <form method="post">
  630. <?php if ( $this->is_possible_upgrade() ) { ?>
  631. <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>
  632. <?php } else { ?>
  633. <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>
  634. <?php } ?>
  635. <div class="content-importer-response">
  636. <div id="importer-response" class="clear pos-relative">
  637. <span class="res-text"></span>
  638. <img class="loadinerSearch" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/ajax-load.gif' ?>">
  639. <img class="checkImg" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/check-img.png' ?>">
  640. </div>
  641. <div id="importer-response-menu" class="clear pos-relative">
  642. <span class="res-text"></span>
  643. <img class="loadinerSearch" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/ajax-load.gif' ?>">
  644. <img class="checkImg" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/check-img.png' ?>">
  645. </div>
  646. <div id="importer-response-homepage" class="clear pos-relative">
  647. <span class="res-text"></span>
  648. <img class="loadinerSearch" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/ajax-load.gif' ?>">
  649. <img class="checkImg" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/check-img.png' ?>">
  650. </div>
  651. <div id="importer-response-themeoptions" class="clear pos-relative">
  652. <span class="res-text"></span>
  653. <img class="loadinerSearch" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/ajax-load.gif' ?>">
  654. <img class="checkImg" width="30px" src="<?php echo get_template_directory_uri().'/assets/images/misc/check-img.png' ?>">
  655. </div>
  656. <div class="clear"></div>
  657. </div>
  658. <p class="envato-setup-actions step">
  659. <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
  660. class="secondary-button bold button-next button-next-skip"><?php esc_html_e( 'Skip this step', 'taskereasy' ); ?></a>
  661. <a href="#" class="ta-import-content main-button bold pull-right"><?php esc_html_e( 'Import Content', 'taskereasy' ); ?></a>
  662. <?php wp_nonce_field( 'envato-setup' ); ?>
  663. </p>
  664. </form>
  665. <?php
  666. }
  667. public function setup_content() {
  668. $themeSelectedStyle = get_theme_mod('dtbwp_site_style',$this->get_default_theme_style());
  669. $file = get_template_directory().'/setup/content/'.$themeSelectedStyle.'/content.xml';
  670. if ( !defined('WP_LOAD_IMPORTERS') ) define('WP_LOAD_IMPORTERS', true);
  671. require_once ABSPATH . 'wp-admin/includes/import.php';
  672. $importer_error = false;
  673. if ( !class_exists( 'WP_Importer' ) ) {
  674. $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
  675. if ( file_exists( $class_wp_importer ) ){
  676. require_once($class_wp_importer);
  677. } else {
  678. $importer_error = true;
  679. }
  680. }
  681. if ( !class_exists( 'WP_Import' ) ) {
  682. $class_wp_import = get_template_directory().'/setup/importer/importer/wordpress-importer.php';
  683. if ( file_exists( $class_wp_import ) )
  684. require_once($class_wp_import);
  685. else
  686. $importer_error = true;
  687. }
  688. if($importer_error){
  689. ob_start();
  690. $msg = "Error on import";
  691. $msg = ob_get_contents();
  692. ob_end_clean();
  693. die($msg);
  694. }
  695. else {
  696. if(!is_file( $file )){
  697. ob_start();
  698. $msg = "Something went wrong";
  699. $msg = ob_get_contents();
  700. ob_end_clean();
  701. die($msg);
  702. } else {
  703. $wp_import = new WP_Import();
  704. $wp_import->fetch_attachments = true;
  705. ob_start();
  706. $res=$wp_import->import( $file );
  707. $res = ob_get_contents();
  708. ob_end_clean();
  709. $msg = 'Content imported success';
  710. die($msg);
  711. }
  712. }
  713. }
  714. //Assigns menu location
  715. public function taskereasy_menu(){
  716. $main_menu = get_term_by('name', 'main menu', 'nav_menu');
  717. set_theme_mod( 'nav_menu_locations', array(
  718. 'primary' => $main_menu->term_id,
  719. )
  720. );
  721. die('Menu setup successful');
  722. }
  723. public function taskereasy_homepage(){
  724. $blog = get_page_by_path( 'Blog' );
  725. $home = get_page_by_path( 'Home' );
  726. update_option( 'show_on_front', 'page' );
  727. update_option( 'page_on_front', $home->ID );
  728. update_option( 'page_for_posts',$blog->ID );
  729. die('Home page setup successful');
  730. }
  731. public function taskereasy_theme_options() {
  732. WP_Filesystem();
  733. global $wp_filesystem;
  734. $themeSelectedStyle = get_theme_mod('dtbwp_site_style',$this->get_default_theme_style());
  735. $file = get_template_directory().'/setup/content/'.$themeSelectedStyle.'/themeOptions.json';
  736. $data = $wp_filesystem->get_contents( $file );
  737. $data = json_decode( $data, true );
  738. $theme_option_name = 'taskereasy_options';
  739. if ( is_array( $data ) && !empty( $data ) ) {
  740. $data = apply_filters( 'solitaire_theme_import_theme_options', $data );
  741. update_option($theme_option_name, $data);
  742. die('Theme Options imported');
  743. } else {
  744. die('An error occured while importing theme options');
  745. }
  746. }
  747. public $logs = array();
  748. public function log( $message ) {
  749. $this->logs[] = $message;
  750. }
  751. public $errors = array();
  752. public function error( $message ) {
  753. $this->logs[] = 'ERROR!!!! ' . $message;
  754. }
  755. /* Function for the different styles */
  756. public function envato_setup_color_style() {
  757. ?>
  758. <div class="envato-setup-first-step-container envato-setup-first-step-containerwelcome plugins-container-heading">
  759. <h1><?php printf( esc_html__( "Select one of our pre-built demos.", 'taskereasy' ), wp_get_theme() ); ?></h1>
  760. </div>
  761. <form method="post" class="ta-demo-content-import-container">
  762. <div class="plugins-container-inner">
  763. <div class="theme-presets ta-select-demo-outer">
  764. <ul>
  765. <?php
  766. $current_style = get_theme_mod( 'dtbwp_site_style', $this->get_default_theme_style() );
  767. $stylecls = '';
  768. $i = 0;
  769. foreach ( $this->site_styles as $style_name => $style_data ) {
  770. ?>
  771. <li class="ta-imp-demo <?php if($i == 0){ echo 'current'; } ?>">
  772. <div class="ta-select-demo">
  773. <div class="ta-select-demo-image">
  774. <a href="#" data-style="<?php echo esc_attr( $style_name ); ?>"></a>
  775. <img style="width:100%;" src="<?php echo get_template_directory_uri().'/setup/content/demos/'.$style_name.'/style.jpg' ?>"/>
  776. <?php if('style1' == $style_name){
  777. $stylecls = 'opacity:1;visibility:visible';
  778. }else{
  779. $stylecls = '';
  780. } ?>
  781. <div class="ta-select-demo-image-overlay" style="<?php echo esc_attr( $stylecls ); ?>"></div>
  782. <div class="ta-select-demo-image-overlay-link" style="<?php echo esc_attr( $stylecls ); ?>">
  783. <a href="" class="ta-current-demo"></a>
  784. </div>
  785. </div>
  786. <div class="ta-ad-pri1ce-content text-center">
  787. <?php if('style1' == $style_name){ ?>
  788. <h5><?php echo esc_html__('Home 1', 'taskereasy') ?></h5>
  789. <a class="main-button bold" href="https://slidesigma.com/themes/wp/taskereasy/" target="_blank"><?php printf( esc_html__( 'Preview', 'taskereasy' ) ); ?></a>
  790. <?php } ?>
  791. <?php if('style2' == $style_name){ ?>
  792. <h5><?php echo esc_html__('Home 2', 'taskereasy') ?></h5>
  793. <a class="main-button bold" href="https://slidesigma.com/themes/wp/taskereasy/home-2/" target="_blank"><?php printf( esc_html__( 'Preview', 'taskereasy' ) ); ?></a>
  794. <?php } ?>
  795. <?php if('style3' == $style_name){ ?>
  796. <h5><?php echo esc_html__('Home 3', 'taskereasy') ?></h5>
  797. <a class="main-button bold" href="https://slidesigma.com/themes/wp/taskereasy/home-3/" target="_blank"><?php printf( esc_html__( 'Preview', 'taskereasy' ) ); ?></a>
  798. <?php } ?>
  799. <?php if('style4' == $style_name){ ?>
  800. <h5><?php echo esc_html__('Home 4', 'taskereasy') ?></h5>
  801. <a class="main-button bold" href="https://slidesigma.com/themes/wp/taskereasy/home-4/" target="_blank"><?php printf( esc_html__( 'Preview', 'taskereasy' ) ); ?></a>
  802. <?php } ?>
  803. </div>
  804. </div>
  805. </li>
  806. <?php
  807. $i++;
  808. }
  809. ?>
  810. </ul>
  811. </div>
  812. <div class="clearfix"></div>
  813. <input type="hidden" name="new_style" id="new_style" value="style1">
  814. <p class="envato-setup-actions step">
  815. <a href="<?php echo esc_url( $this->get_next_step_link() ); ?>"
  816. class="secondary-button bold button-next"><?php esc_html_e( 'No, Maybe Later', 'taskereasy' ); ?></a>
  817. <?php wp_nonce_field( 'envato-setup' ); ?>
  818. <input type="submit" class="main-button bold pointer pull-right button-next"
  819. value="<?php esc_attr_e( 'Yes, i am ready. ', 'taskereasy' ); ?>" name="save_step"/>
  820. </p>
  821. </div>
  822. </form>
  823. <?php
  824. }
  825. public function envato_setup_color_style_save() {
  826. check_admin_referer( 'envato-setup' );
  827. $new_style = isset( $_POST['new_style'] ) ? $_POST['new_style'] : false;
  828. if ( $new_style ) {
  829. set_theme_mod( 'dtbwp_site_style', $new_style );
  830. }
  831. wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
  832. exit;
  833. }
  834. public function envato_setup_ready() {
  835. update_option( 'envato_setup_complete', time() );
  836. update_option( 'dtbwp_update_notice', strtotime('-4 days') );
  837. ?>
  838. <h1><?php esc_html_e( 'Your Website is Ready!', 'taskereasy' ); ?></h1>
  839. <img src="<?php echo get_template_directory_uri(); ?>/assets/images/misc/congrats.png"/>
  840. <p class="ta-redirect-page-pragrahi"><?php esc_html_e( 'Your are being redirected to the welcome page.', 'taskereasy' ); ?></p>
  841. <?php
  842. $welcomePargeURL = admin_url().'themes.php?page=taskereasy';
  843. header("refresh:3;url=$welcomePargeURL");
  844. }
  845. private static $_current_manage_token = false;
  846. public function ajax_notice_handler() {
  847. check_ajax_referer( 'dtnwp-ajax-nonce', 'security' );
  848. // Store it in the options table
  849. update_option( 'dtbwp_update_notice', time() );
  850. }
  851. private function _array_merge_recursive_distinct( $array1, $array2 ) {
  852. $merged = $array1;
  853. foreach ( $array2 as $key => &$value ) {
  854. if ( is_array( $value ) && isset( $merged [ $key ] ) && is_array( $merged [ $key ] ) ) {
  855. $merged [ $key ] = $this->_array_merge_recursive_distinct( $merged [ $key ], $value );
  856. } else {
  857. $merged [ $key ] = $value;
  858. }
  859. }
  860. return $merged;
  861. }
  862. public static function cleanFilePath( $path ) {
  863. $path = str_replace( '', '', str_replace( array( '\\', '\\\\', '//' ), '/', $path ) );
  864. if ( $path[ strlen( $path ) - 1 ] === '/' ) {
  865. $path = rtrim( $path, '/' );
  866. }
  867. return $path;
  868. }
  869. public function is_submenu_page() {
  870. return ( $this->parent_slug == '' ) ? false : true;
  871. }
  872. }
  873. }// if !class_exists
  874. /**
  875. * Loads the main instance of Envato_Theme_Setup_Wizard to have
  876. * ability extend class functionality
  877. *
  878. * @since 1.1.1
  879. * @return object Envato_Theme_Setup_Wizard
  880. */
  881. add_action( 'after_setup_theme', 'envato_theme_setup_wizard', 10 );
  882. if ( ! function_exists( 'envato_theme_setup_wizard' ) ) :
  883. function envato_theme_setup_wizard() {
  884. Envato_Theme_Setup_Wizard::get_instance();
  885. }
  886. endif;