-
Notifications
You must be signed in to change notification settings - Fork 1
/
nf-rest.php
63 lines (54 loc) · 1.53 KB
/
nf-rest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* @package NF_Rest
* @version 1.0
*/
/*
Plugin Name: NF Rest
Plugin URI: http://josegomezr.com.ve/
Description: Send your ninja-forms via rest.
Author: José Gómez
Version: 1.0
Author URI: http://josegomezr.com.ve/
*/
require_once ABSPATH . 'wp-content/plugins/ninja-forms/includes/Abstracts/Action.php';
require_once 'action.php';
add_filter( 'ninja_forms_register_actions', 'njrest_action' );
function njrest_action($actions)
{
$actions['nf_rest'] = new NFR_Action();
return $actions;
}
/**
* @tag my_ninja_forms_processing
* @callback my_ninja_forms_processing_callback
*/
/*add_filter( 'ninja_forms_after_submission', 'ninja_rest_handler' );
function ninja_rest_handler( $form_data ) {
$log = "\n------------\n";
$fields = $form_data["fields"];
$payload = array();
foreach($fields as $field){
$key = $field["key"];
$val = $field["value"];
$payload[$key] = $val;
}
$log .= print_r($payload, 1);
if(!isset($payload["rest_endpoint_url"]) or !isset($payload["rest_http_method"])){
$log .= "\n:::EXITED, NO WHERE TO SEND DATA\n";
file_put_contents("/tmp/phplog", $log);
return;
}
$url = $payload['rest_endpoint_url'];
$method = strtolower($payload['rest_http_method']);
$args = array(
'reject_unsafe_urls' => true,
'method' => $method,
'user-agent' => 'josegomezr/ninja-form',
'body' => $payload
);
$req = wp_remote_request($url, $args);
$log .= print_r($req, 1);
file_put_contents("/tmp/phplog", $log);
}
*/