newsletter.class.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @author ThemePunch <info@themepunch.com>
  4. * @link http://www.themepunch.com/
  5. * @copyright 2015 ThemePunch
  6. * @version 1.0.0
  7. */
  8. if( !defined( 'ABSPATH') ) exit();
  9. if(!class_exists('ThemePunch_Newsletter')) {
  10. class ThemePunch_Newsletter {
  11. protected static $remote_url = 'http://newsletter.themepunch.com/';
  12. protected static $subscribe = 'subscribe.php';
  13. protected static $unsubscribe = 'unsubscribe.php';
  14. public function __construct(){
  15. }
  16. /**
  17. * Subscribe to the ThemePunch Newsletter
  18. * @since: 1.0.0
  19. **/
  20. public static function subscribe($email){
  21. global $wp_version;
  22. $request = wp_remote_post(self::$remote_url.self::$subscribe, array(
  23. 'user-agent' => 'WordPress/'.$wp_version.'; '.get_bloginfo('url'),
  24. 'timeout' => 15,
  25. 'body' => array(
  26. 'email' => urlencode($email)
  27. )
  28. ));
  29. if(!is_wp_error($request)) {
  30. if($response = json_decode($request['body'], true)) {
  31. if(is_array($response)) {
  32. $data = $response;
  33. return $data;
  34. }else{
  35. return false;
  36. }
  37. }
  38. }
  39. }
  40. /**
  41. * Unsubscribe to the ThemePunch Newsletter
  42. * @since: 1.0.0
  43. **/
  44. public static function unsubscribe($email){
  45. global $wp_version;
  46. $request = wp_remote_post(self::$remote_url.self::$unsubscribe, array(
  47. 'user-agent' => 'WordPress/'.$wp_version.'; '.get_bloginfo('url'),
  48. 'timeout' => 15,
  49. 'body' => array(
  50. 'email' => urlencode($email)
  51. )
  52. ));
  53. if(!is_wp_error($request)) {
  54. if($response = json_decode($request['body'], true)) {
  55. if(is_array($response)) {
  56. $data = $response;
  57. return $data;
  58. }else{
  59. return false;
  60. }
  61. }
  62. }
  63. }
  64. }
  65. }
  66. ?>