importer.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * VamTam ACX Coming Soon Importer
  4. */
  5. if ( ! defined( 'WP_LOAD_IMPORTERS' ) )
  6. return;
  7. // Load Importer API
  8. require_once ABSPATH . 'wp-admin/includes/import.php';
  9. if ( ! class_exists( 'WP_Importer' ) ) {
  10. $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
  11. if ( file_exists( $class_wp_importer ) )
  12. require $class_wp_importer;
  13. }
  14. /**
  15. * WordPress Importer class for managing the import process of a WXR file
  16. *
  17. * @package Importer
  18. */
  19. if ( class_exists( 'WP_Importer' ) ) {
  20. class Vamtam_AcxComingSoon_Import extends WP_Importer {
  21. private $file;
  22. public function __construct() {
  23. $this->file = VAMTAM_SAMPLES_DIR . 'acx-coming-soon.json';
  24. }
  25. /**
  26. * Registered callback function for the WordPress Importer
  27. *
  28. * Manages the three separate stages of the WXR import process
  29. */
  30. public function dispatch() {
  31. $this->header();
  32. check_admin_referer( 'vamtam-import-acx-coming-soon' );
  33. set_time_limit( 0 );
  34. $this->import( );
  35. $this->footer();
  36. }
  37. /**
  38. * The main controller for the actual import stage.
  39. */
  40. public function import() {
  41. add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
  42. $this->import_start();
  43. wp_suspend_cache_invalidation( true );
  44. $theme = json_decode( file_get_contents( $this->file ), true );
  45. update_option( 'acx_csma_appearence_array', $theme['acx_csma_appearence_array'] );
  46. wp_suspend_cache_invalidation( false );
  47. $this->import_end();
  48. }
  49. private function import_start() {
  50. if ( ! file_exists( $this->file ) ) {
  51. echo '<p><strong>' . esc_html__( 'Sorry, there has been an error.', 'wordpress-importer' ) . '</strong><br />';
  52. echo esc_html__( 'The file does not exist, please try again.', 'wordpress-importer' ) . '</p>';
  53. $this->footer();
  54. die();
  55. }
  56. do_action( 'import_start' );
  57. }
  58. /**
  59. * Performs post-import cleanup of files and the cache
  60. */
  61. private function import_end() {
  62. $redirect = admin_url( '' );
  63. echo '<p>' . esc_html__( 'All done.', 'wordpress-importer' ) . ' <a href="' . esc_url( $redirect ) . '">' . esc_html__( 'Have fun!', 'wordpress-importer' ) . '</a></p>';
  64. echo '<!-- all done -->';
  65. do_action( 'import_end' );
  66. }
  67. // Display import page title
  68. private function header() {
  69. echo '<div class="wrap">';
  70. echo '<h2>' . esc_html__( 'Import Acurax Coming Soon Settings', 'wordpress-importer' ) . '</h2>'; }
  71. // Close div.wrap
  72. private function footer() {
  73. echo '</div>';
  74. }
  75. /**
  76. * Added to http_request_timeout filter to force timeout at 120 seconds during import
  77. * @return int 120
  78. */
  79. public function bump_request_timeout( $imp ) {
  80. return 120;
  81. }
  82. }
  83. } // class_exists( 'WP_Importer' )
  84. function vamtam_acx_coming_soon_importer_init() {
  85. $GLOBALS['vamtam_acx_coming_soon_import'] = new Vamtam_AcxComingSoon_Import();
  86. register_importer( 'vamtam_acx_coming_soon', 'Vamtam Acurax Coming Soon Importer', sprintf( esc_html__( 'Import Acurax Coming Soon settings used for the demo content of VamTam themes, not to be used as a stand-alone product.', 'wpv' ), VAMTAM_THEME_NAME ), array( $GLOBALS['vamtam_acx_coming_soon_import'], 'dispatch' ) );
  87. }
  88. add_action( 'admin_init', 'vamtam_acx_coming_soon_importer_init' );