PageRenderTime 48ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/184.168.182.1/wp-content/plugins/quick-setup/quick-setup/quick-setup.php

https://gitlab.com/endomorphosis/falkenstein
PHP | 696 lines | 430 code | 81 blank | 185 comment | 90 complexity | 8bd9aebf2be2ea4c899aa2c3ff12e7ac MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: Go Daddy Quick Setup
  4. Author: GoDaddy.com, LLC
  5. Author URI: http://www.godaddy.com/
  6. Plugin URI: http://www.godaddy.com/
  7. Description: Get your site started in ten minutes by answering some easy questions. Use our beautiful themes and popular plugin configurations to get your website started quickly.
  8. Version: 1.03
  9. Text Domain: gd_quicksetup
  10. Domain Path: /lang
  11. Network: false
  12. License: Proprietary
  13. */
  14. /**
  15. * Copyright 2013 Go Daddy Operating Company, LLC. All Rights Reserved.
  16. */
  17. // Make sure it's wordpress
  18. if ( !defined( 'ABSPATH' ) )
  19. die( 'Forbidden' );
  20. // Load languages
  21. load_plugin_textdomain( 'gd_quicksetup', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
  22. // Our path
  23. define( 'GD_QUICKSETUP_DIR', realpath( dirname( __FILE__ ) ) );
  24. // Run the plugin
  25. $gd_quicksetup_plugin = new GD_QuickSetup_Plugin();
  26. // Activation hook -- reload the environment settings
  27. register_activation_hook( __FILE__, array( $gd_quicksetup_plugin, 'activate' ) );
  28. // Cleanup -- roll back environment changes
  29. register_deactivation_hook( __FILE__, array( $gd_quicksetup_plugin, 'deactivate' ) );
  30. /**
  31. * Go Daddy Quick Setup Plugin for WordPress
  32. */
  33. class GD_QuickSetup_Plugin {
  34. /**
  35. * Plugin slug
  36. * @var string
  37. */
  38. public $slug = '';
  39. /**
  40. * API communicator
  41. * @var object
  42. */
  43. public $api = null;
  44. /**
  45. * Current plugin options
  46. * @var array
  47. */
  48. protected $_current_plugin_options = array();
  49. /**
  50. * Current theme options
  51. * @var array
  52. */
  53. protected $_current_theme_options = array();
  54. /**
  55. * Constructor
  56. * @return GD_QuickSetup_Plugin
  57. */
  58. public function __construct() {
  59. $this->slug = 'gd_quicksetup';
  60. $this->hooks();
  61. }
  62. /**
  63. * Add all of our admnin hooks
  64. * @return void
  65. */
  66. public function hooks() {
  67. // Always run
  68. if ( is_admin() ) {
  69. add_action( 'init', array( $this, 'library_init' ) );
  70. add_action( 'admin_init', array( $this, 'modules_init' ) );
  71. add_action( 'admin_init', array( $this, 'init_api' ) );
  72. }
  73. // Ajax hooks
  74. if ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) {
  75. add_action( 'wp_ajax_quick_setup_ajax_poll', array( $this, 'done_install' ) );
  76. // Admin UI hooks
  77. } elseif ( is_admin() && !defined( 'DOING_AJAX' ) || ( defined( 'DOING_AJAX' ) && !DOING_AJAX ) ) {
  78. add_filter( 'plugin_row_meta', array( $this, 'add_leave_feedback_link' ), 10, 2 );
  79. add_action( 'admin_init', array( $this, 'upgrade' ) );
  80. add_action( 'admin_menu', array( $this, 'settings_page' ) );
  81. add_action( 'admin_notices', array( $this, 'show_banner' ) );
  82. add_action( 'admin_init', array( $this, 'self_upgrade' ) );
  83. }
  84. }
  85. /**
  86. * Enqueue javascripts
  87. * Respect SCRIPT_DEBUG
  88. */
  89. public function enqueue_scripts() {
  90. if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
  91. wp_enqueue_script( 'gd_quicksetup_js', plugins_url( 'quick-setup/js/gd-quick-setup.js' ) );
  92. wp_enqueue_script( 'jquery_tiptip', plugins_url( 'quick-setup/js/jquery.tiptip.js' ) );
  93. wp_enqueue_script( 'jquery_placeholder', plugins_url( 'quick-setup/js/jquery.placeholder.js' ) );
  94. } else {
  95. wp_enqueue_script( 'gd_quicksetup_js', plugins_url( 'quick-setup/js/gd-quick-setup.min.js' ) );
  96. wp_enqueue_script( 'jquery_tiptip', plugins_url( 'quick-setup/js/jquery.tiptip.min.js' ) );
  97. wp_enqueue_script( 'jquery_placeholder', plugins_url( 'quick-setup/js/jquery.placeholder.min.js' ) );
  98. }
  99. wp_enqueue_script( 'jquery-ui-core' );
  100. wp_enqueue_script( 'jquery-ui-dialog' );
  101. add_thickbox();
  102. wp_localize_script(
  103. 'gd_quicksetup_js',
  104. 'objectL10n',
  105. array(
  106. 'add' => __( 'Add', 'gd_quicksetup' ),
  107. 'remove' => __( 'Remove', 'gd_quicksetup' ),
  108. 'building' => __( 'Building Site...', 'gd_quicksetup' ),
  109. 'publish' => __( 'Publish Website', 'gd_quicksetup' ),
  110. )
  111. );
  112. }
  113. /**
  114. * Enqueue css
  115. * Respect SCRIPT_DEBUG
  116. */
  117. public function enqueue_styles() {
  118. global $wp_styles;
  119. if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
  120. wp_enqueue_style( 'gd_quicksetup_css', plugins_url( 'quick-setup/css/gd-quick-setup.css' ) );
  121. wp_register_style( 'gd_quicksetup_ie_css', plugins_url( 'quick-setup/css/gd-quick-setup-ie.css' ) );
  122. $wp_styles->add_data( 'gd_quicksetup_ie_css', 'conditional', 'lte IE 9' );
  123. wp_enqueue_style( 'gd_quicksetup_ie_css' );
  124. } else {
  125. wp_enqueue_style( 'gd_quicksetup_css', plugins_url( 'quick-setup/css/gd-quick-setup.min.css' ) );
  126. wp_register_style( 'gd_quicksetup_ie_css', plugins_url( 'quick-setup/css/gd-quick-setup-ie.min.css' ) );
  127. $wp_styles->add_data( 'gd_quicksetup_ie_css', 'conditional', 'lte IE 9' );
  128. wp_enqueue_style( 'gd_quicksetup_ie_css' );
  129. }
  130. }
  131. /**
  132. * Bootstrap our own upgrader
  133. */
  134. public function self_upgrade() {
  135. $options = get_option( 'gd_quicksetup_options' );
  136. if ( !empty( $options['key'] ) ) {
  137. $plugin_slug = plugin_basename( __FILE__ );
  138. $gd_quicksetup_upgrader = new GD_QuickSetup_Upgrader( $plugin_slug );
  139. $gd_quicksetup_upgrader->set_api( $this->api );
  140. }
  141. }
  142. /**
  143. * Include required libraries
  144. */
  145. public function library_init() {
  146. // Autoload if possible
  147. if ( function_exists( 'spl_autoload_register' ) ) {
  148. spl_autoload_register( array( $this, 'autoload' ) );
  149. } else {
  150. require_once( ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' );
  151. require_once( GD_QUICKSETUP_DIR . '/classes/class.gd-quicksetup-api.php' );
  152. require_once( GD_QUICKSETUP_DIR . '/classes/class.gd-quicksetup-plugin-upgrader.php' );
  153. require_once( GD_QUICKSETUP_DIR . '/classes/class.gd-quicksetup-installer-skin.php' );
  154. require_once( GD_QUICKSETUP_DIR . '/classes/class.gd-quicksetup-object-cache.php' );
  155. }
  156. }
  157. /**
  158. * Init API communicator
  159. */
  160. public function init_api() {
  161. // API communicator
  162. $this->api = new GD_QuickSetup_API();
  163. }
  164. /**
  165. * Autoloader
  166. * @param string $class_name
  167. */
  168. public function autoload( $class_name ) {
  169. switch ( $class_name ) {
  170. case 'GD_QuickSetup_API' :
  171. require_once( GD_QUICKSETUP_DIR . '/classes/class.gd-quicksetup-api.php' );
  172. break;
  173. case 'GD_QuickSetup_Plugin_Upgrader' :
  174. require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
  175. require_once( ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' );
  176. require_once( GD_QUICKSETUP_DIR . '/classes/class.gd-quicksetup-plugin-upgrader.php' );
  177. break;
  178. case 'GD_QuickSetup_Installer_Skin' :
  179. require_once( ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' );
  180. require_once( GD_QUICKSETUP_DIR . '/classes/class.gd-quicksetup-installer-skin.php' );
  181. break;
  182. case 'GD_QuickSetup_ObjectCache' :
  183. require_once( GD_QUICKSETUP_DIR . '/classes/class.gd-quicksetup-object-cache.php' );
  184. break;
  185. case 'GD_QuickSetup_Upgrader' :
  186. require_once( GD_QUICKSETUP_DIR . '/classes/class.gd-quicksetup-upgrader.php' );
  187. break;
  188. case 'GD_QuickSetup_Theme_Upgrader' :
  189. require_once( ABSPATH . '/wp-admin/includes/upgrade.php' );
  190. require_once( ABSPATH . '/wp-admin/includes/class-wp-upgrader.php' );
  191. require_once( GD_QUICKSETUP_DIR . '/classes/class.gd-quicksetup-theme-upgrader.php' );
  192. break;
  193. case 'GD_QuickSetup_Shortcodes' :
  194. require_once( GD_QUICKSETUP_DIR . '/classes/class.gd-quicksetup-shortcodes.php' );
  195. break;
  196. }
  197. }
  198. /**
  199. * Get current plugin options
  200. * @return array
  201. */
  202. public function get_current_plugin_options() {
  203. return $this->_current_plugin_options;
  204. }
  205. /**
  206. * Get current theme options
  207. * @return array
  208. */
  209. public function get_current_theme_options() {
  210. return $this->_current_theme_options;
  211. }
  212. /**
  213. * Include all of the modules
  214. */
  215. public function modules_init() {
  216. // Get installer modules
  217. foreach ( glob( GD_QUICKSETUP_DIR . '/modules/*.php' ) as $module ) {
  218. if ( 'index.php' === pathinfo( $module, PATHINFO_BASENAME ) ) {
  219. continue;
  220. }
  221. require_once( $module );
  222. }
  223. do_action( 'gd_quicksetup_modules_init' );
  224. }
  225. /**
  226. * Install routine
  227. * All of the heavy lifting happens here
  228. */
  229. public function do_install() {
  230. // Don't time out
  231. set_time_limit( 0 );
  232. // Don't abort the site in a bad state if the connection drops
  233. ignore_user_abort( true );
  234. // Ask the API what to do
  235. $result = $this->api->get_setup_instructions( $_POST['site_type'], $_POST['theme_slug'] );
  236. if ( is_wp_error( $result ) ) {
  237. wp_die( __( 'There was a problem fetching the data', 'gd_quicksetup' ) );
  238. } else {
  239. $result = json_decode( $result['body'], true );
  240. }
  241. // Start the installation process
  242. do_action( 'gd_quicksetup_install' );
  243. // Install plugins
  244. $this->_current_plugin_options = array();
  245. $plugin_installer_skin = new GD_QuickSetup_Installer_Skin();
  246. $plugin_installer = new GD_QuickSetup_Plugin_Upgrader( $plugin_installer_skin );
  247. do_action( 'gd_quicksetup_install_plugins' );
  248. foreach ( (array) $result['plugins'] as $plugin ) {
  249. $this->_current_plugin_options = ( isset( $plugin['options'] ) ? $plugin['options'] : array() );
  250. $plugin_installer->install( $plugin['url'] );
  251. $plugin_installer->activate_plugin( $plugin['slug'] );
  252. }
  253. do_action( 'gd_quicksetup_install_plugins_done' );
  254. // Theme
  255. do_action( 'gd_quicksetup_install_theme' );
  256. $this->_current_theme_options = ( isset( $result['theme']['options'] ) ? $result['theme']['options'] : array() );
  257. $theme_installer_skin = new GD_QuickSetup_Installer_Skin();
  258. $theme_installer = new GD_QuickSetup_Theme_Upgrader( $theme_installer_skin );
  259. $theme_installer->install( $result['theme']['url'] );
  260. $theme_installer->switch_theme( $result['theme']['stylesheet'] );
  261. do_action( 'gd_quicksetup_install_theme_done' );
  262. // Content
  263. do_action( 'gd_quicksetup_install_content' );
  264. // Start the menu at 30
  265. // home = 10
  266. // gallery = 20
  267. // location = 700
  268. // contact = 800
  269. // blog = 999
  270. $menu = 30;
  271. // Create pages
  272. foreach ( (array) $_POST['type'] as $k => $v ) {
  273. if ( !$_POST['enabled'][$k] || 'false' === $_POST['enabled'][$k] ) {
  274. continue;
  275. }
  276. if ( 'page' === $v ) {
  277. if ( !isset( $_POST['title'][$k] ) || empty( $_POST['title'][$k] ) ) {
  278. $title = __( 'Untitled', 'gd_quicksetup' );
  279. } else {
  280. $title = $_POST['title'][$k];
  281. }
  282. $pageid = wp_insert_post(
  283. array(
  284. 'comment_status' => 'closed',
  285. 'ping_status' => 'closed',
  286. 'post_content' => wp_kses( $_POST['content'][$k], wp_kses_allowed_html( 'post' ) ),
  287. 'post_name' => sanitize_title( $title ),
  288. 'post_title' => strip_tags( $title ),
  289. 'post_type' => 'page',
  290. 'post_status' => 'publish',
  291. 'menu_order' => ( $_POST['home'][$k] ? 10 : $menu += 10 ),
  292. )
  293. );
  294. if ( $_POST['home'][$k] && 0 !== strcasecmp( $_POST['home'][$k], 'false' ) ) {
  295. update_option( 'show_on_front', 'page' );
  296. update_option( 'page_on_front', $pageid );
  297. }
  298. }
  299. }
  300. // Create gallery
  301. foreach ( (array) $_POST['type'] as $k => $v ) {
  302. if ( !$_POST['enabled'][$k] || 'false' === $_POST['enabled'][$k] ) {
  303. continue;
  304. }
  305. if ( 'gallery' === $v ) {
  306. $gallery_ids = array();
  307. foreach ( $_FILES as $k2 => $v2 ) {
  308. if ( 0 === strpos( $k2, 'upload_image_' . $k . '_' ) && is_uploaded_file( $_FILES[$k2]['tmp_name'] ) ) {
  309. // Check mime type, only allow "image/*" files
  310. $info = wp_check_filetype_and_ext( $_FILES[$k2]['tmp_name'], $_FILES[$k2]['name'] );
  311. if ( isset( $info['type'] ) && 0 === stripos( $info['type'], 'image/' ) ) {
  312. $id = media_handle_upload( $k2, 0 );
  313. if ( !is_wp_error( $id ) && is_numeric( $id ) ) {
  314. $gallery_ids[] = $id;
  315. }
  316. }
  317. }
  318. }
  319. if ( empty( $gallery_ids ) ) {
  320. continue;
  321. }
  322. $pageid = wp_insert_post(
  323. array(
  324. 'comment_status' => 'closed',
  325. 'ping_status' => 'closed',
  326. 'post_content' => '[gallery ids="' . implode( ',', $gallery_ids ) . '"]',
  327. 'post_name' => __( 'gallery', 'gd_quicksetup' ),
  328. 'post_title' => __( 'Gallery', 'gd_quicksetup' ),
  329. 'post_type' => 'page',
  330. 'post_status' => 'publish',
  331. 'menu_order' => 20,
  332. )
  333. );
  334. if ( $_POST['home'][$k] && 0 !== strcasecmp( $_POST['home'][$k], 'false' ) ) {
  335. update_option( 'show_on_front', 'page' );
  336. update_option( 'page_on_front', $pageid );
  337. }
  338. }
  339. }
  340. // Create blog post
  341. foreach ( (array) $_POST['type'] as $k => $v ) {
  342. if ( !$_POST['enabled'][$k] || 'false' === $_POST['enabled'][$k] ) {
  343. continue;
  344. }
  345. if ( 'blog' === $v ) {
  346. if ( !isset( $_POST['title'][$k] ) || empty( $_POST['title'][$k] ) ) {
  347. $title = __( 'Untitled', 'gd_quicksetup' );
  348. } else {
  349. $title = $_POST['title'][$k];
  350. }
  351. wp_insert_post(
  352. array(
  353. 'post_content' => wp_kses( $_POST['content'][$k], wp_kses_allowed_html( 'post' ) ),
  354. 'post_name' => sanitize_title( $title ),
  355. 'post_title' => strip_tags( $title ),
  356. 'post_type' => 'post',
  357. 'post_status' => 'publish',
  358. )
  359. );
  360. if ( 'page' === get_option( 'show_on_front', 'page' ) ) {
  361. $pageid = wp_insert_post(
  362. array(
  363. 'comment_status' => 'closed',
  364. 'ping_status' => 'closed',
  365. 'post_content' => '',
  366. 'post_name' => __( 'blog', 'gd_quicksetup' ),
  367. 'post_title' => __( 'Blog', 'gd_quicksetup' ),
  368. 'post_type' => 'page',
  369. 'post_status' => 'publish',
  370. 'menu_order' => 999,
  371. )
  372. );
  373. update_option( 'page_for_posts', $pageid );
  374. }
  375. }
  376. }
  377. do_action( 'gd_quicksetup_install_content_done' );
  378. // Done
  379. do_action( 'gd_quicksetup_install_done' );
  380. // Stash $_POST in a fake transient (needed for communicating with the install_after_done action
  381. // we can't use a real transient because of volatility with the database and object cache after
  382. // resetting the site
  383. update_option( 'gd_quicksetup_last_post', $_POST );
  384. // Save the response as a fake transient so the theme skin (and any other options) can be switched
  385. // (deleted after ajax call is done, we don't need it for longer than that)
  386. set_transient( 'gd_quicksetup_last_api_response', $result, 3600 );
  387. // "Done" Flag
  388. update_option( 'gd_quicksetup_wizard_complete', time() );
  389. }
  390. /**
  391. * Install is done, move on
  392. * Call the gd_quicksetup_after_install_done hook
  393. * This is called via ajax
  394. */
  395. public function done_install() {
  396. if ( get_option( 'gd_quicksetup_wizard_complete' ) > 0 ) {
  397. $flag = get_transient( 'gd_quicksetup_doing_done_install' );
  398. if ( empty( $flag ) ) {
  399. set_transient( 'gd_quicksetup_doing_done_install', time(), 120 );
  400. do_action( 'gd_quicksetup_after_install_done' );
  401. wp_die( admin_url() );
  402. }
  403. }
  404. wp_die( 2 );
  405. }
  406. /**
  407. * Upgrade between versions
  408. * @return void
  409. */
  410. public function upgrade() {
  411. // Get the current version
  412. $version = get_option( 'gd_quicksetup_version' );
  413. // Set default options
  414. if ( empty( $version ) || version_compare( $version, '1.0' ) < 0 ) {
  415. update_option( 'gd_quicksetup_version', '1.0' );
  416. $options = array(
  417. 'key' => '',
  418. 'api_url' => 'https://wpqs.secureserver.net/v1/',
  419. );
  420. if ( !get_option( 'gd_quicksetup_options' ) ) {
  421. update_option( 'gd_quicksetup_options', $options );
  422. }
  423. }
  424. // Upgrade to 1.03
  425. if ( empty( $version ) || version_compare( $version, '1.03' ) < 0 ) {
  426. update_option( 'gd_quicksetup_version', '1.03' );
  427. }
  428. }
  429. /**
  430. * Hook into the admin menu
  431. * @return void
  432. */
  433. public function settings_page() {
  434. $page = add_management_page( __( 'Go Daddy Quick Setup', 'gd_quicksetup' ), __( 'Go Daddy Quick Setup', 'gd_quicksetup' ), 'manage_options', $this->slug . '-wizard', array( $this, 'quicksetup_wizard' ) );
  435. add_action( 'admin_print_scripts-' . $page, array( $this, 'enqueue_scripts' ) );
  436. add_action( 'admin_print_styles-' . $page, array( $this, 'enqueue_styles' ) );
  437. }
  438. /**
  439. * Start the wizard
  440. * @return void
  441. */
  442. public function quicksetup_wizard() {
  443. // Check permissions
  444. if ( !current_user_can( 'manage_options' ) ) {
  445. wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
  446. }
  447. // Shortcodes handler
  448. $this->shortcodes = new GD_QuickSetup_Shortcodes();
  449. // Run the wizard
  450. if ( !isset( $_GET['step'] ) || !in_array( $_GET['step'], array( -1, 2, 3, 4 ) ) ) {
  451. include_once( GD_QUICKSETUP_DIR . '/resources/header.php' );
  452. include_once( GD_QUICKSETUP_DIR . '/resources/step1.php' );
  453. include_once( GD_QUICKSETUP_DIR . '/resources/footer.php' );
  454. } elseif ( 2 == $_GET['step'] ) {
  455. check_admin_referer( 'quick_setup_step2' ) || wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
  456. include_once( GD_QUICKSETUP_DIR . '/resources/header.php' );
  457. include_once( GD_QUICKSETUP_DIR . '/resources/step2.php' );
  458. include_once( GD_QUICKSETUP_DIR . '/resources/footer.php' );
  459. } elseif ( 3 == $_GET['step'] ) {
  460. check_admin_referer( 'quick_setup_step3' ) || wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
  461. include_once( GD_QUICKSETUP_DIR . '/resources/header.php' );
  462. include_once( GD_QUICKSETUP_DIR . '/resources/step3.php' );
  463. include_once( GD_QUICKSETUP_DIR . '/resources/footer.php' );
  464. } elseif ( 4 == $_GET['step'] ) {
  465. check_admin_referer( 'quick_setup_step4' ) || wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
  466. // Don't force a specific file system method
  467. $method = '';
  468. // Define any extra pass-thru fields (none)
  469. $form_fields = array();
  470. // Define the URL to post back to (this one)
  471. $url = wp_nonce_url( $_SERVER['REQUEST_URI'], 'quick_setup_step4' );
  472. // Ask for credentials, if necessary
  473. if ( false === ( $creds = request_filesystem_credentials( $url, $method, false, false, $form_fields ) ) ) {
  474. // Show the credentials form
  475. include_once( GD_QUICKSETUP_DIR . '/resources/filesystem-message.php' );
  476. return true;
  477. } elseif ( ! WP_Filesystem( $creds ) ) {
  478. // The credentials are bad, ask again
  479. request_filesystem_credentials( $url, $method, true, false, $form_fields );
  480. include_once( GD_QUICKSETUP_DIR . '/resources/filesystem-message.php' );
  481. return true;
  482. } else {
  483. // Once we get here, we should have credentials, do the file system operations
  484. global $wp_filesystem;
  485. delete_option( 'gd_quicksetup_wizard_complete' );
  486. /**
  487. * Use some aggressive cache-busting to get the "Building your site..." message to
  488. * appear as soon as possible. This is based on core ticket #18525
  489. * @link http://core.trac.wordpress.org/ticket/18525
  490. */
  491. // Stop compressing
  492. if ( !headers_sent() && ini_get( 'zlib.output_handler' ) ) {
  493. ini_set( 'zlib.output_handler', '' );
  494. ini_set( 'zlib.output_compression', 0 );
  495. }
  496. if ( !headers_sent() && function_exists( 'apache_setenv' ) ) {
  497. apache_setenv( 'no-gzip', '1' );
  498. }
  499. ini_set( 'output_handler', '' );
  500. ini_set( 'output_buffering', false );
  501. ini_set( 'implicit_flush', true );
  502. $this->flush();
  503. include_once( GD_QUICKSETUP_DIR . '/resources/header.php' );
  504. $this->flush();
  505. include_once( GD_QUICKSETUP_DIR . '/resources/step4.php' );
  506. $this->flush();
  507. include_once( GD_QUICKSETUP_DIR . '/resources/footer.php' );
  508. $this->flush();
  509. add_action( 'shutdown', array( $this, 'do_install' ) );
  510. }
  511. } elseif ( -1 == $_GET['step'] ) {
  512. wp_die( __( 'Error', 'gd_quicksetup' ) );
  513. }
  514. }
  515. /**
  516. * Show the banner on the dashboard
  517. */
  518. public function show_banner() {
  519. // Only works for admins
  520. if ( !current_user_can( 'manage_options' ) ) {
  521. return;
  522. }
  523. // Only works on dashboard
  524. if ( 'dashboard' != get_current_screen()->id ) {
  525. return;
  526. }
  527. // Get a list of dismissed pointers
  528. $pointers = array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) );
  529. // Show the "Go play with your new site!" banner?
  530. if ( get_option( 'gd_quicksetup_wizard_complete' ) && !in_array( 'gd-quicksetup-wizard-complete', $pointers ) ) {
  531. if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
  532. wp_enqueue_style( 'gd_quicksetup_banner_css', plugins_url( 'quick-setup/css/gd-quick-setup-banner.css' ) );
  533. } else {
  534. wp_enqueue_style( 'gd_quicksetup_banner_css', plugins_url( 'quick-setup/css/gd-quick-setup-banner.min.css' ) );
  535. }
  536. include_once( GD_QUICKSETUP_DIR . '/resources/site-built-banner.php' );
  537. return;
  538. }
  539. // If they haven't dismissed the "Build your site!" pointer, show that
  540. if ( !in_array( 'gd-quicksetup-start-wizard', $pointers ) ) {
  541. if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
  542. wp_enqueue_style( 'gd_quicksetup_banner_css', plugins_url( 'quick-setup/css/gd-quick-setup-banner.css' ) );
  543. } else {
  544. wp_enqueue_style( 'gd_quicksetup_banner_css', plugins_url( 'quick-setup/css/gd-quick-setup-banner.min.css' ) );
  545. }
  546. include_once( GD_QUICKSETUP_DIR . '/resources/build-site-banner.php' );
  547. return;
  548. }
  549. }
  550. /**
  551. * Activate
  552. */
  553. public function activate() {
  554. global $wp_version;
  555. // Version check, only 3.5+
  556. if ( ! version_compare( $wp_version, '3.5-beta', '>=' ) ) {
  557. if ( function_exists( 'deactivate_plugins' ) ) {
  558. deactivate_plugins( __FILE__ );
  559. }
  560. // Don't call wp_die, this will take over the screen
  561. add_filter( 'wp_die_handler', create_function( '', "{return '_ajax_wp_die_handler';}" ) );
  562. wp_die( __( '<strong>Go Daddy Quick Setup</strong> requires WordPress 3.5 or later', 'gd_quicksetup' ) );
  563. }
  564. // Not for multisite
  565. if ( is_multisite() ) {
  566. if ( function_exists( 'deactivate_plugins' ) ) {
  567. deactivate_plugins( __FILE__ );
  568. }
  569. // Don't call wp_die, this will take over the screen
  570. add_filter( 'wp_die_handler', create_function( '', "{return '_ajax_wp_die_handler';}" ) );
  571. wp_die( __( '<strong>Go Daddy Quick Setup</strong> will not work on multisite installations', 'gd_quicksetup' ) );
  572. }
  573. // Add our option
  574. add_option( 'gd_quicksetup_last_post', array(), '', false );
  575. }
  576. /**
  577. * Clean up when deactivated
  578. * Currently there's nothing to clean up, so we'll leave
  579. * that for uninstall.php
  580. * @return void
  581. */
  582. public function deactivate() {
  583. // todo
  584. }
  585. /**
  586. * Flush
  587. * Use some aggressive flushing to make the "Building ..." dialog appear as soon as possible
  588. * on step 4. This is based on ticket #18525
  589. * @link http://core.trac.wordpress.org/ticket/18525
  590. */
  591. public function flush() {
  592. if ( 'cli' === php_sapi_name() ) {
  593. return;
  594. }
  595. wp_ob_end_flush_all();
  596. $buffer_string = '<!--' . str_repeat( chr( ' ' ), 16384 ) . '-->'; // 16 KB
  597. if ( headers_sent() ) {
  598. echo $buffer_string;
  599. flush();
  600. }
  601. }
  602. /**
  603. * Show the "Leave feedback" link on the plugins table
  604. * @param array $links
  605. * @param string $file
  606. * @return array New links
  607. */
  608. public static function add_leave_feedback_link( $links, $file ) {
  609. if ( $file === plugin_basename( __FILE__ ) ) {
  610. $links['feedback'] = '<a href="http://x.co/quickwp" target="_blank">' . __( 'Leave feedback', 'gd_quicksetup' ) . '</a>';
  611. $links['support'] = '<a href="http://x.co/quicksetup" target="_blank">' . __( 'Get support', 'gd_quicksetup' ) . '</a>';
  612. }
  613. return $links;
  614. }
  615. }