Created
March 14, 2021 01:06
-
-
Save sajt/81e53232a159cb45bacd7c60c8c13242 to your computer and use it in GitHub Desktop.
Ezt a file-t feltöltve a Wordpress wp-content/plugins-ba és bekapcsolva, az Elementor Pro-ban form adatokat lehet küldeni a SAPI-nak. Fontos, hogy a form-ban lévő mezők id-ja megegyezzen a SAPI-ban lévő Mező nevekkel. A kódban a megfelelő változók értékeit át kell írni
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: Elementor SAPI integration | |
* Plugin URI: https://webfeszek.hu | |
* Description: Adds a webhook for easy integration to SAPI | |
* Version: 0.1.0 | |
* Author: Tamas Amon | |
* Author URI: https://amon.hu | |
* License: GPLv2 or later | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
use ElementorPro\Modules\Forms\Classes\Ajax_Handler; | |
if (!defined('ABSPATH')) { | |
exit; // Exit if accessed directly. | |
} | |
add_action('elementor_pro/forms/new_record', function ($record, Ajax_Handler $handler) { | |
//Ezeket az integrációnál találod | |
$sapi_user = 'sapi_user'; | |
$sapi_password = 'sapi_password'; | |
$listId = 000000; | |
$formId = 000000; | |
$url = "https://{$sapi_user}:{$sapi_password}@api.salesautopilot.com/subscribe/{$listId}/form/{$formId}"; | |
$form_name = $record->get_form_settings('form_name'); | |
//Fontos, hogy a form neve 'feliratkozas legyen' | |
if ('feliratkozas' !== $form_name) { | |
return; | |
} | |
$raw_fields = $record->get('fields'); | |
$fields = []; | |
foreach ($raw_fields as $id => $field) { | |
$fields[$id] = $field['value']; | |
} | |
wp_remote_post($url, [ | |
'headers' => array('Content-Type' => 'application/json; charset=utf-8'), | |
'body' => json_encode($fields), | |
'method' => 'POST', | |
'data_format' => 'body', | |
]); | |
$handler->set_success(true); | |
}, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment