Guest User

Untitled

a guest
Feb 25th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. // Add Shortcode
  2. function mailpoet_bulk_subscribe_func()
  3. {
  4.  
  5. ob_start(); ?>
  6.  
  7. <form action="?submit=true" method="POST">
  8. <input name="email" type="text" required placeholder="Email address">
  9. <input name="first_name" type="text" placeholder="First name">
  10. <input name="last_name" type="text" placeholder="Last name">
  11. <input type="checkbox" name="lists[]" value="1"/>List 1<br/>
  12. <input type="checkbox" name="lists[]" value="2"/>List 2<br/>
  13. <input value="Subscribe!" type="submit">
  14. </form>
  15.  
  16. <?php
  17.  
  18. $content = ob_get_contents();
  19.  
  20. ob_end_clean();
  21.  
  22. $slide = (isset($_GET["submit"]) && trim($_GET["submit"]) == 'true') ? trim($_GET["submit"]) : '';
  23.  
  24.  
  25. if ("true" === $slide) {
  26. $subscriber_data = array(
  27. 'email' => sanitize_text_field($_POST['email']),
  28. 'first_name' => sanitize_text_field($_POST['first_name']),
  29. 'last_name' => sanitize_text_field($_POST['first_name'])
  30. );
  31.  
  32. $options = array(
  33. 'send_confirmation_email' => true,// default: true
  34. 'schedule_welcome_email' => false // default: true
  35. );
  36.  
  37. $lists = array_map('intval', $_POST['lists']);
  38.  
  39. try {
  40. $subscriber = \MailPoet\API\API::MP('v1')->addSubscriber($subscriber_data, $lists, $options);
  41. } catch (Exception $exception) {
  42. return $exception->getMessage();
  43. }
  44. }
  45.  
  46.  
  47.  
  48. return $content;
  49.  
  50. }
  51. add_shortcode('mailpoet_bulk_subscribe', 'mailpoet_bulk_subscribe_func');
Add Comment
Please, Sign In to add comment