Forked from csalzano/elementor-form-additional-webhook.php
Created
March 22, 2022 21:08
-
-
Save asllanmaciel/fdfe88ced3a64b2da7cdac3dc3c3df34 to your computer and use it in GitHub Desktop.
Elementor Form additional webhook example
This file contains 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: Elementor Form Additional Webhook | |
* Plugin URI: https://gist.github.com/csalzano/dfd754e0fe8b6ac10731fad8f257c0bf | |
* Description: Adds a second Webhook to an Elementor form | |
* Version: 1.0.1 | |
* Author: Corey Salzano | |
* Author URI: https://breakfastco.xyz/ | |
* License: GPLv2 or later | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
class Elementor_Form_Additional_Webhook { | |
function hooks(){ | |
//Add our additional webhook right here | |
add_action( 'elementor_pro/forms/new_record', array( $this, 'manipulate_form_submission' ), 10, 2 ); | |
} | |
function manipulate_form_submission( $record, $ajax_handler ) { | |
$form_data = $record->get_formatted_data(); | |
//change the names of fields before we send them somewhere | |
$new_data = array( | |
'First_Name' => $form_data['First Name'] ?? '', | |
'Last_Name' => $form_data['Last Name'] ?? '', | |
'URL' => $form_data['Website'] ?? '', | |
); | |
$response = wp_remote_post( 'http://api.somewhere.com/', array( 'body' => $new_data ) ); | |
//if the failure of our additional webhook should prevent the form from submitting... | |
if( is_wp_error( $response ) ) { | |
$msg = 'There was a problem with the additional webhook.'; | |
$ajax_handler->add_error( 0, $msg ); | |
$ajax_handler->add_error_message( $msg ); | |
$ajax_handler->is_success = false; | |
} | |
} | |
} | |
$elementor_webhook_239909870234 = new Elementor_Form_Additional_Webhook(); | |
$elementor_webhook_239909870234->hooks(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment