Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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');
Add Comment
Please, Sign In to add comment