Guest User

Untitled

a guest
Jan 27th, 2016
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. class Incsub_Subscribe_By_Email_Confirmation_Template {
  5.  
  6. private $settings;
  7. private $to;
  8. private $user_key;
  9.  
  10.  
  11. public function __construct( $settings, $email ) {
  12. $this->settings = $settings;
  13. $this->to = $email;
  14.  
  15. $subscriber = incsub_sbe_get_subscriber( $email );
  16. $this->user_key = $subscriber->subscription_key;
  17. }
  18.  
  19.  
  20. /**
  21. * Render the mail template
  22. *
  23. * @param Boolean if the content must be returned or echoed
  24. *
  25. * @return String
  26. */
  27. public function render_mail_template() {
  28. $font_style = "style=\"font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif !important;background:#DEDEDE;padding-top:20px;margin-bottom:30px;\"";
  29. $table_top_style = 'style="padding:10px 20px;border-bottom:1px solid black;margin:0 auto;width:600px;border-top:5px solid ' . $this->settings['header_color'] . '"';
  30. $table_style = 'style="padding:10px 20px;width:600px;margin:0 auto;"';
  31. $column_style = 'style="display: block!important;"';
  32. $column_wrap_style = 'style="margin: 0 auto; display: block;"';
  33. $blogname_style = 'style="text-decoration:none !important; margin: 0!important; padding:0;font-weight: 900; font-size: 14px; text-transform: uppercase; color: ' . $this->settings['header_text_color'] . ' !important;"';
  34. $subject_style = 'style="font-weight: 500; font-size: 27px;line-height: 1.1; margin-bottom: 15px; color: #000 !important;"';
  35. $lead_style = 'style="font-size: 17px;margin-bottom: 10px; font-weight: normal; font-size: 14px; line-height: 1.6;"';
  36. $footer_style = 'style="font-size:11px;color:#666 !important;"';
  37. $button_style = 'style="background-color:#278AB6;border-radius:25px;text-decoration:none;color: #FFF;display: inline-block;line-height: 23px;height: 24px;padding: 0 10px 1px;cursor:pointer;box-sizing: border-box;font-size:12px"';
  38. ob_start();
  39.  
  40. ?>
  41. <div <?php echo $font_style; ?>>
  42. <table <?php echo $table_top_style; ?> bgcolor="#EFEFEF">
  43. <tbody>
  44. <tr>
  45. <td></td>
  46. <td <?php echo $column_style; ?>>
  47. <div <?php echo $column_wrap_style; ?>>
  48. <table <?php echo $table_style; ?> >
  49. <tbody>
  50. <tr>
  51. <td><strong><?php printf( __( ' <a href="%s">%s</a>', INCSUB_SBE_LANG_DOMAIN ), home_url(), get_bloginfo( 'name' ) ); ?></strong></td>
  52. </tr>
  53. </tbody>
  54. </table>
  55. </div>
  56. </td>
  57. <td></td>
  58. </tr>
  59. </tbody>
  60. </table><!-- /HEADER -->
  61. <table <?php echo $table_style; ?> bgcolor="#FFFFFF">
  62. <tbody>
  63. <tr>
  64. <td></td>
  65. <td <?php echo $column_style; ?> >
  66. <div <?php echo $column_wrap_style; ?>>
  67. <table <?php echo $table_style; ?>>
  68. <tbody>
  69. <tr>
  70. <td>
  71. <?php
  72. echo wpautop( $this->settings['subscribe_email_content'] );
  73. echo $this->get_confirmation_text( $button_style );
  74. ?>
  75. </td>
  76. </tr>
  77. </tbody>
  78. </table>
  79. </div><!-- /content -->
  80. </td>
  81. <td></td>
  82. </tr>
  83. </tbody>
  84. </table>
  85. </div>
  86. <?php
  87.  
  88. return ob_get_clean();
  89. }
  90.  
  91. function get_confirmation_text( $button_style ) {
  92. $blogname = get_bloginfo( 'name' );
  93. $home_url = get_home_url();
  94. $link = add_query_arg( 'sbe_confirm', $this->user_key, get_home_url() );
  95.  
  96. $text .= '<p><a ' . $button_style . ' href="' . $link . '">' . __( 'Confirm Subscription', INCSUB_SBE_LANG_DOMAIN ) . '</a></p>' . "\r\n";
  97.  
  98. return $text;
  99. }
  100.  
  101.  
  102.  
  103. /**
  104. * Send the mail based on the template
  105. *
  106. * @param False/String $to False if just sending Bcc
  107. * @param Array $bcc Bcc list
  108. */
  109. public function send_mail() {
  110.  
  111. add_filter( 'wp_mail_content_type', array( &$this, 'set_html_content_type' ) );
  112. add_filter( 'wp_mail_from', array( &$this, 'set_mail_from' ) );
  113. add_filter( 'wp_mail_from_name', array( &$this, 'set_mail_from_name' ) );
  114.  
  115. $content = $this->render_mail_template();
  116. wp_mail( $this->to, __( 'Please confirm subscription', INCSUB_SBE_LANG_DOMAIN ), $content );
  117.  
  118. remove_filter( 'wp_mail_content_type', array( &$this, 'set_html_content_type' ) );
  119. remove_filter( 'wp_mail_from', array( &$this, 'set_mail_from' ) );
  120. remove_filter( 'wp_mail_from_name', array( &$this, 'set_mail_from_name' ) );
  121.  
  122.  
  123. }
  124.  
  125. /*************************/
  126. /* HEADERS */
  127. /*************************/
  128. public function set_html_content_type() {
  129. return 'text/html';
  130. }
  131.  
  132.  
  133. function set_mail_from( $content_type ) {
  134. return $this->settings['from_email'];
  135. }
  136.  
  137. function set_mail_from_name( $name ) {
  138. return $this->settings['from_sender'];
  139. }
  140.  
  141.  
  142.  
  143. }
Add Comment
Please, Sign In to add comment