Skip to content

Instantly share code, notes, and snippets.

@dancameron
Created August 3, 2014 16:58
Show Gist options
  • Select an option

  • Save dancameron/c696ec47caf78c55c74e to your computer and use it in GitHub Desktop.

Select an option

Save dancameron/c696ec47caf78c55c74e to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: NinjaDemo AJAX Callbacks
Plugin URI: https://sproutapps.co/
Description: Allow for the demo form to be remotely retreived.
Author: Sprout Apps
Version: 0.8
Author URI: https://sproutapps.co
*/
function sa_try_demo_form() {
$allowed_domains = array(
home_url(),
'http://sprout.dev',
'https://sproutapps.co'
);
// Check to make sure that the requested origin is an allowed domain.
// This will prevent direct access too.
if ( in_array( $_SERVER['HTTP_ORIGIN'], $allowed_domains ) ) {
header('Access-Control-Allow-Origin: *');
// Form
print do_shortcode( '[try_demo]' );
}
exit();
}
add_action( 'wp_ajax_nopriv_try_demo_form', 'sa_try_demo_form', 10, 0 );
add_action( 'wp_ajax_try_demo_form', 'sa_try_demo_form', 10, 0 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment