id = 'import-export'; $this->title = __( 'Settings Import and Export', 'it-l10n-ithemes-security-pro' ); $this->description = __( 'Export your settings as a backup or to import on other sites for quicker setup.', 'it-l10n-ithemes-security-pro' ); $this->type = 'recommended'; $this->pro = true; $this->can_save = false; parent::__construct(); } public function enqueue_scripts_and_styles() { $vars = array( 'text' => array( 'exporting' => __( 'Creating Export...', 'it-l10n-ithemes-security-pro' ), 'importing' => __( 'Loading Settings...', 'it-l10n-ithemes-security-pro' ), ), ); wp_enqueue_script( 'jquery-fileupload', plugins_url( 'js/jquery.fileupload.js', __FILE__ ), array( 'jquery-ui-widget' ), '9.28.0', true ); wp_enqueue_script( 'itsec-import-export-page-script', plugins_url( 'js/settings-page.js', __FILE__ ), array( 'jquery-fileupload', 'itsec-settings-page-script' ), $this->version, true ); wp_localize_script( 'itsec-import-export-page-script', 'itsecImportExportSettingsPage', $vars ); } public function handle_ajax_request( $data ) { if ( 'export' === $data['method'] ) { if ( empty( $data['email'] ) ) { return new WP_Error( 'itsec-import-export-export-empty-email', __( 'You must supply an Email Address to receive the exported settings file.', 'it-l10n-ithemes-security-pro' ) ); } $email = sanitize_text_field( $data['email'] ); if ( ! is_email( $email ) ) { return new WP_Error( 'itsec-import-export-export-invalid-email', __( 'You must supply a valid Email Address to receive the exported settings file.', 'it-l10n-ithemes-security-pro' ) ); } require_once( dirname( __FILE__ ) . '/exporter.php' ); $result = ITSEC_Import_Export_Exporter::create( $email ); if ( is_wp_error( $result ) ) { ITSEC_Response::set_response( $result ); } else { $message = sprintf( __( 'The exported settings were successfully sent to %1$s.', 'it-l10n-ithemes-security-pro' ), $email ); $message = '

' . $message . '

'; ITSEC_Response::set_response( $message ); } } else if ( 'import' === $data['method'] ) { if ( empty( $_FILES['import_file'] ) ) { return new WP_Error( 'itsec-import-export-import-empty-file', __( 'You must supply a Settings File to import.', 'it-l10n-ithemes-security-pro' ) ); } require_once( dirname( __FILE__ ) . '/importer.php' ); $result = ITSEC_Import_Export_Importer::import_from_form( 'import_file' ); if ( is_wp_error( $result ) ) { ITSEC_Response::set_response( $result ); } else { $message = __( 'The submitted settings were successfully loaded onto the site.', 'it-l10n-ithemes-security-pro' ); ITSEC_Response::add_message( $message ); ITSEC_Response::reload_all_modules(); } } } protected function render_description( $form ) { ?>


add_text( 'email_address' ); ?>

add_button( 'export', array( 'value' => __( 'Create Export', 'it-l10n-ithemes-security-pro' ), 'class' => 'button-primary' ) ); ?>


add_file( 'settings_file' ); ?>

add_button( 'import', array( 'value' => __( 'Load Settings', 'it-l10n-ithemes-security-pro' ), 'class' => 'button-primary' ) ); ?>