Skip to content

Instantly share code, notes, and snippets.

@mattiasghodsian
Last active April 28, 2023 08:33
Show Gist options
  • Save mattiasghodsian/3f0d4e0f4c4a44ef7df771c249061404 to your computer and use it in GitHub Desktop.
Save mattiasghodsian/3f0d4e0f4c4a44ef7df771c249061404 to your computer and use it in GitHub Desktop.
[WordPress] Gravity Forms send entry to child site (WP)
/**
* Title: Gravity Forms send entry to child site (WP | Enable GF REST API on child site)
* Author: Mattias Ghodsian
* Donate a cup of coffee: https://www.buymeacoffee.com/mattiasghodsian
* Donate Eth: 0xBBB96204E45D11C9799c6B12E6eE6F0d4A071Ef5
*/
add_action( 'gform_after_submission_2', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {
$entry['form_id'] = 1; // change form ID to same ID on your child site
$consumer_key = '';
$consumer_secret = '';
$headers = [
'Authorization' => 'Basic ' . base64_encode( "{$consumer_key}:{$consumer_secret}") ,
'Content-Type' => 'application/json; charset=utf-8',
];
$endpoint_url = 'https://site.com/wp-json/gf/v2/entries';
$response = wp_remote_post( $endpoint_url, array( 'headers' => $headers, 'body' => json_encode($entry,true) ) );
if ($response['message'] == "Created") {
// do nothing
}else{
GFCommon::log_debug( 'gform_after_submission: response => ' . print_r( $response, true ) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment