Last active
March 1, 2022 07:11
-
-
Save smartdeal/c23a7e88ac2dc9ce22875ea5fe98c2e8 to your computer and use it in GitHub Desktop.
пример интеграции #Wordpress #Sendpulse #WP_CF7
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 | |
| function add_email_to_sendpulse($contact_form) { | |
| $wpcf7 = WPCF7_ContactForm::get_current(); | |
| $submission = WPCF7_Submission::get_instance(); | |
| $data = $submission->get_posted_data(); | |
| $cur_email = $data['Email']; | |
| if ($cur_email != '') { | |
| define( 'API_USER_ID', '' ); | |
| define( 'API_SECRET', '' ); | |
| define( 'TOKEN_STORAGE', 'file' ); | |
| $SPApiProxy = new SendpulseApi( API_USER_ID, API_SECRET, TOKEN_STORAGE ); | |
| $SPApiProxy->addEmails(633919, array($cur_email) ); | |
| } | |
| } | |
| ?> |
@snmazko Не срабатывает, выдаёт ошибку в CF7 при отправке данных: Unexpected token u in JSON at position 0
@snmazko действительно рабочий вариант!!!
Спасибо за подробную инструкцию.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Рабочий вариант интеграции без использования автозагрузчика:
my-theme - папка темы, в которой будет вызываться метод
в папке wp-content/themes/my-theme создать директории sendpulse-library/sendpulse-rest-api-php в которую разархивировать содержимое папки sendpulse-rest-api-php-master архива API Sendpulse, (zip архив кода https://github.com/sendpulse/sendpulse-rest-api-php/archive/master.zip), должна получиться следующая структура: http://joxi.ru/12MEngMc43M0G2
в папке wp-content/themes/my-theme создать файл cf7-sendpulse.php со следующим содержимым
(API_USER_ID, API_SECRET, 17145866 подставлять свои с действующего акк):
require get_parent_theme_file_path('/cf7-sendpulse.php');
remove_all_filters('wpcf7_before_send_mail');
add_action('wpcf7_before_send_mail', 'add_email_to_sendpulse');