Created
February 14, 2018 07:45
-
-
Save Jursdotme/68c96926abe3b377f395d702fb5c76a8 to your computer and use it in GitHub Desktop.
Mailpoet bulk subscribe
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
// Add Shortcode | |
function mailpoet_bulk_subscribe_func() | |
{ | |
ob_start(); ?> | |
<form action="?submit=true" method="POST"> | |
<input name="email" type="text" required placeholder="Email address"> | |
<input name="first_name" type="text" placeholder="First name"> | |
<input name="last_name" type="text" placeholder="Last name"> | |
<input type="checkbox" name="lists[]" value="1"/>List 1<br/> | |
<input type="checkbox" name="lists[]" value="2"/>List 2<br/> | |
<input value="Subscribe!" type="submit"> | |
</form> | |
<?php | |
$content = ob_get_contents(); | |
ob_end_clean(); | |
$slide = (isset($_GET["submit"]) && trim($_GET["submit"]) == 'true') ? trim($_GET["submit"]) : ''; | |
if ("true" === $slide) { | |
$subscriber_data = array( | |
'email' => sanitize_text_field($_POST['email']), | |
'first_name' => sanitize_text_field($_POST['first_name']), | |
'last_name' => sanitize_text_field($_POST['first_name']) | |
); | |
$options = array( | |
'send_confirmation_email' => true,// default: true | |
'schedule_welcome_email' => false // default: true | |
); | |
$lists = array_map('intval', $_POST['lists']); | |
try { | |
$subscriber = \MailPoet\API\API::MP('v1')->addSubscriber($subscriber_data, $lists, $options); | |
} catch (Exception $exception) { | |
return $exception->getMessage(); | |
} | |
} | |
return $content; | |
} | |
add_shortcode('mailpoet_bulk_subscribe', 'mailpoet_bulk_subscribe_func'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment