Created
July 28, 2014 17:45
-
-
Save dabernathy89/5143157b18182eeef6ef to your computer and use it in GitHub Desktop.
Gravity Forms queues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Gravity Forms Queue Listener | |
*/ | |
class GravityFormsQueueListener { | |
function __construct() { | |
add_action('wp_loaded', array($this,'process_push_queue_msg'), 10 ); | |
add_action('gform_after_submission', array( $this, 'send_to_ironio'), 10, 2); | |
} | |
public function process_push_queue_msg() { | |
if ( isset($_GET['gf_queue']) ) { | |
// POST data sent from iron.io will be a raw JSON string - not form data | |
$data = file_get_contents("php://input"); | |
$data = json_decode($data,true); | |
$entry = isset($data['entry']) ? $data['entry'] : array(); | |
$form = isset($data['form']) ? $data['form'] : array(); | |
if (empty($entry) || empty($form)) { | |
exit; | |
} | |
// Allow other plugins to hook in here to process form submissions | |
// add_action() must be called earlier than the "wp_loaded" hook | |
do_action( 'gf_queue', $entry, $form ); | |
} | |
} | |
public function send_to_ironio( $entry, $form ) { | |
require_once plugin_dir_path(__FILE__) . "includes/IronCore.class.php"; | |
require_once plugin_dir_path(__FILE__) . "includes/IronMQ.class.php"; | |
$ironmq = new IronMQ(array( | |
"token" => 'IRON.IO TOKEN HERE', | |
"project_id" => 'PROJECT ID HERE' | |
)); | |
$message = array( | |
'entry' => $entry, | |
'form' => $form | |
); | |
$ironmq->postMessage('Form Submission', json_encode($message)); | |
} | |
} | |
$gravity_forms_queue_listener = new GravityFormsQueueListener(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment