Sometimes you’d like to store your contact’s data in the WP-SMS newsletter, so here is a simple function that helps you to do that.
/**
* @param WPCF7_ContactForm $WPCF7_ContactForm
*/
function addNumberToSubscriberList($WPCF7_ContactForm)
{
$name = isset($_POST['your-name']) ? sanitize_text_field($_POST['your-name']) : "";
$mobile = isset($_POST['your-mobile']) ? sanitize_text_field($_POST['your-mobile']) : "";
if ($name and $mobile) {
\WP_SMS\Newsletter::addSubscriber($name, $mobile, 'group-id');
}
}
add_action('wpcf7_before_send_mail', 'addNumberToSubscriberList');
If you would like to make show the groups list on your form, first you need to create a dropdown field on Contact Form 7 which contains the Groups
[select group "1|News" "2|Sport" "3|General"]
Then you can access the group ID by $_POST['group']
**
* @param WPCF7_ContactForm $WPCF7_ContactForm
*/
function addNumberToSubscriberList($WPCF7_ContactForm)
{
$name = isset($_POST['your-name']) ? sanitize_text_field($_POST['your-name']) : "";
$mobile = isset($_POST['mobile-number']) ? sanitize_text_field($_POST['mobile-number']) : "";
$group = isset($_POST['group']) ? sanitize_text_field($_POST['group']) : "";
if ($name and $mobile) {
\WP_SMS\Newsletter::addSubscriber($name, $mobile, $group);
}
}
add_action('wpcf7_before_send_mail', 'addNumberToSubscriberList');