Skip to content

Instantly share code, notes, and snippets.

@bahiirwa
Created July 10, 2021 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bahiirwa/4608a94998dbaf64164358ea32685d8c to your computer and use it in GitHub Desktop.
Save bahiirwa/4608a94998dbaf64164358ea32685d8c to your computer and use it in GitHub Desktop.
Get CF7 Data and send to API
<?php
/**
* Plugin Name: CF7 Form Trap
* Plugin URI: https://github.com/yttechiepress/cf7-trap-api
* Author: Techiepress
* Author URI: https://github.com/yttechiepress/cf7-trap-api
* Description: Get CF7 Data and send to API
* Version: 0.1.0
* License: GPL2
* License URL: http://www.gnu.org/licenses/gpl-2.0.txt
* text-domain: cf7-trap-api
*/
defined( 'ABSPATH' ) or die( 'Unauthorized access!' );
add_action( 'cfdb7_before_save', 'techiepress_cf7_data' );
function techiepress_cf7_data( $form_data ) {
$upload_dir = home_url( 'wp-content/uploads/cfdb7_uploads/' );
$data = [
'name' => $form_data['text-504'],
'email' => $form_data['email-347'],
'food' => $form_data['menu-340'][0],
'upload' => $upload_dir . $form_data['file-337cfdb7_file'],
];
$url = 'https://hook.integromat.com/mcmufrx6en3zmf1xltvxwfc6efcnu7ag';
$args = [
'method' => 'POST',
'body' => $data,
];
wp_remote_post( $url, $args );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment