Noptin_Ajax::download_forms()

Downloads optin forms


Source Source

File: includes/class-noptin-ajax.php

	public function download_forms() {

		if ( ! current_user_can( get_noptin_capability() ) ) {
			wp_die( -1, 403 );
		}

		// Check nonce.
		$nonce = $_GET['admin_nonce'];
		if ( ! wp_verify_nonce( $nonce, 'noptin_admin_nonce' ) ) {
			_e ( 'Reload the page and try again.', 'newsletter-optin-box' );
			exit;
		}

		/**
		 * Runs before downloading opt-in forms.
		 *
		 */
		do_action( 'noptin_before_download_forms' );

		$output = fopen( 'php://output', 'w' ) or die( 'Unsupported server' );

		// Let the browser know what content we're streaming and how it should save the content.
		$time = time();
		header( "Content-Type:application/json" );
		header( "Content-Disposition:attachment;filename=noptin-forms-$time.json" );

		$forms = array();

		foreach( get_noptin_optin_forms() as $form ) {
			$forms[] = $form->get_all_data();
		}

		echo wp_json_encode( wp_unslash( $forms ) );

		fclose( $output );

		/**
		 * Runs after after downloading opt-in forms.
		 *
		 */
		do_action( 'noptin_after_download_forms' );

		exit; // This is important.
	}


Top ↑

Changelog Changelog

Changelog
VersionDescription
1.2.6Introduced.

Top ↑

User Contributed Notes User Contributed Notes

30 day money back guarantee
Safe & Secure online payment
Custom CSS Slide Example
Custom Animation Example
Default Animation