Jetpack_Subscriptions

The Jetpack by WordPress.com Jetpack Subscriptions class.

Defined (1)

The class is defined in the following location(s).

/modules/subscriptions.php  
  1. class Jetpack_Subscriptions { 
  2. public $jetpack = false; 
  3.  
  4. public static $hash; 
  5.  
  6. /** 
  7. * Singleton 
  8. * @static 
  9. */ 
  10. static function init() { 
  11. static $instance = false; 
  12.  
  13. if ( !$instance ) { 
  14. $instance = new Jetpack_Subscriptions; 
  15.  
  16. return $instance; 
  17.  
  18. function __construct() { 
  19. $this->jetpack = Jetpack::init(); 
  20.  
  21. // Don't use COOKIEHASH as it could be shared across installs && is non-unique in multisite. 
  22. // @see: https://twitter.com/nacin/status/378246957451333632 
  23. self::$hash = md5( get_option( 'siteurl' ) ); 
  24.  
  25. add_filter( 'jetpack_xmlrpc_methods', array( $this, 'xmlrpc_methods' ) ); 
  26.  
  27. // @todo remove sync from subscriptions and move elsewhere... 
  28.  
  29. // Add Configuration Page 
  30. add_action( 'admin_init', array( $this, 'configure' ) ); 
  31.  
  32. // Set up the subscription widget. 
  33. add_action( 'widgets_init', array( $this, 'widget_init' ) ); 
  34.  
  35. // Catch subscription widget submits 
  36. if ( isset( $_REQUEST['jetpack_subscriptions_widget'] ) ) 
  37. add_action( 'template_redirect', array( $this, 'widget_submit' ) ); 
  38.  
  39. // Set up the comment subscription checkboxes 
  40. add_action( 'comment_form', array( $this, 'comment_subscribe_init' ) ); 
  41.  
  42. // Catch comment posts and check for subscriptions. 
  43. add_action( 'comment_post', array( $this, 'comment_subscribe_submit' ), 50, 2 ); 
  44.  
  45. // Adds post meta checkbox in the post submit metabox 
  46. if ( 
  47. /** 
  48. * Filter whether or not to show the per-post subscription option. 
  49. * @module subscriptions 
  50. * @since 3.7.0 
  51. * @param bool true = show checkbox option on all new posts | false = hide the option. 
  52. */ 
  53. apply_filters( 'jetpack_allow_per_post_subscriptions', false ) ) 
  54. add_action( 'post_submitbox_misc_actions', array( $this, 'subscription_post_page_metabox' ) ); 
  55.  
  56. add_action( 'transition_post_status', array( $this, 'maybe_send_subscription_email' ), 10, 3 ); 
  57.  
  58. function post_is_public( $the_post ) { 
  59. if ( !$post = get_post( $the_post ) ) { 
  60. return false; 
  61.  
  62. if ( 'publish' === $post->post_status && strlen( (string) $post->post_password ) < 1 ) { 
  63. /** 
  64. * Filter whether posts can be emailed to subscribers. 
  65. * @module subscriptions 
  66. * @since 2.4.0 
  67. * @param bool true Can the post be emailed to Subscribers. Default to true. 
  68. */ 
  69. return apply_filters( 'jetpack_is_post_mailable', true ); 
  70.  
  71. /** 
  72. * Jetpack_Subscriptions::xmlrpc_methods() 
  73. * Register subscriptions methods with the Jetpack XML-RPC server. 
  74. * @param array $methods 
  75. */ 
  76. function xmlrpc_methods( $methods ) { 
  77. return array_merge( 
  78. $methods,  
  79. array( 
  80. 'jetpack.subscriptions.subscribe' => array( $this, 'subscribe' ),  
  81. ); 
  82.  
  83. /** 
  84. * Disable Subscribe on Single Post 
  85. * Register post meta 
  86. */ 
  87. function subscription_post_page_metabox() { 
  88. if ( has_filter( 'jetpack_subscriptions_exclude_these_categories' ) || has_filter( 'jetpack_subscriptions_include_only_these_categories' ) ) { 
  89. return; 
  90.  
  91. global $post; 
  92. $disable_subscribe_value = get_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', true ); 
  93. // Nonce it 
  94. wp_nonce_field( 'disable_subscribe', 'disable_subscribe_nonce' ); 
  95. // only show checkbox if post hasn't been published and is a 'post' post type. 
  96. if ( get_post_status( $post->ID ) !== 'publish' && get_post_type( $post->ID ) == 'post' ) : ?> 
  97. <div class="misc-pub-section"> 
  98. <label for="_jetpack_dont_email_post_to_subs"><?php _e( 'Jetpack Subscriptions:', 'jetpack' ); ?></label><br> 
  99. <input type="checkbox" name="_jetpack_dont_email_post_to_subs" id="jetpack-per-post-subscribe" value="1" <?php checked( $disable_subscribe_value, 1, true ); ?> /> 
  100. <?php _e( 'Don’t send this to subscribers', 'jetpack' ); ?> 
  101. </div> 
  102. <?php endif; 
  103.  
  104. /** 
  105. * Checks whether or not the post should be emailed to subscribers 
  106. * It checks for the following things in order: 
  107. * - Usage of filter jetpack_subscriptions_exclude_these_categories 
  108. * - Usage of filter jetpack_subscriptions_include_only_these_categories 
  109. * - Existence of the per-post checkbox option 
  110. * Only one of these can be used at any given time. 
  111. * @param $new_status string - the "new" post status of the transition when saved 
  112. * @param $old_status string - the "old" post status of the transition when saved 
  113. * @param $post obj - The post object 
  114. */ 
  115. function maybe_send_subscription_email( $new_status, $old_status, $post ) { 
  116. // Only do things on publish 
  117. if ( 'publish' !== $new_status ) { 
  118. return; 
  119. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 
  120. return; 
  121.  
  122. /** 
  123. * Array of categories that will never trigger subscription emails. 
  124. * Will not send subscription emails from any post from within these categories. 
  125. * @module subscriptions 
  126. * @since 3.7.0 
  127. * @param array $args Array of category slugs or ID's. 
  128. */ 
  129. $excluded_categories = apply_filters( 'jetpack_subscriptions_exclude_these_categories', array() ); 
  130.  
  131. // Never email posts from these categories 
  132. if ( ! empty( $excluded_categories ) && in_category( $excluded_categories, $post->ID ) ) { 
  133. update_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', 1 ); 
  134.  
  135. /** 
  136. * ONLY send subscription emails for these categories 
  137. * Will ONLY send subscription emails to these categories. 
  138. * @module subscriptions 
  139. * @since 3.7.0 
  140. * @param array $args Array of category slugs or ID's. 
  141. */ 
  142. $only_these_categories = apply_filters( 'jetpack_subscriptions_exclude_all_categories_except', array() ); 
  143.  
  144. // Only emails posts from these categories 
  145. if ( ! empty( $only_these_categories ) && ! in_category( $only_these_categories, $post->ID ) ) { 
  146. update_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', 1 ); 
  147.  
  148. // Email the post, depending on the checkbox option 
  149. if ( ! empty( $_POST['disable_subscribe_nonce'] ) && wp_verify_nonce( $_POST['disable_subscribe_nonce'], 'disable_subscribe' ) ) { 
  150. if ( isset( $_POST['_jetpack_dont_email_post_to_subs'] ) ) { 
  151. update_post_meta( $post->ID, '_jetpack_dont_email_post_to_subs', $_POST['_jetpack_dont_email_post_to_subs'] ); 
  152.  
  153. /** 
  154. * Jetpack_Subscriptions::configure() 
  155. * Jetpack Subscriptions configuration screen. 
  156. */ 
  157. function configure() { 
  158. // Create the section 
  159. add_settings_section( 
  160. 'jetpack_subscriptions',  
  161. __( 'Jetpack Subscriptions Settings', 'jetpack' ),  
  162. array( $this, 'subscriptions_settings_section' ),  
  163. 'discussion' 
  164. ); 
  165.  
  166. /** Subscribe to Posts ***************************************************/ 
  167.  
  168. add_settings_field( 
  169. 'jetpack_subscriptions_post_subscribe',  
  170. __( 'Follow Blog', 'jetpack' ),  
  171. array( $this, 'subscription_post_subscribe_setting' ),  
  172. 'discussion',  
  173. 'jetpack_subscriptions' 
  174. ); 
  175.  
  176. register_setting( 
  177. 'discussion',  
  178. 'stb_enabled' 
  179. ); 
  180.  
  181. /** Subscribe to Comments ******************************************************/ 
  182.  
  183. add_settings_field( 
  184. 'jetpack_subscriptions_comment_subscribe',  
  185. __( 'Follow Comments', 'jetpack' ),  
  186. array( $this, 'subscription_comment_subscribe_setting' ),  
  187. 'discussion',  
  188. 'jetpack_subscriptions' 
  189. ); 
  190.  
  191. register_setting( 
  192. 'discussion',  
  193. 'stc_enabled' 
  194. ); 
  195.  
  196. /** Subscription Messaging Options ******************************************************/ 
  197.  
  198. register_setting( 
  199. 'reading',  
  200. 'subscription_options',  
  201. array( $this, 'validate_settings' ) 
  202. ); 
  203.  
  204. add_settings_section( 
  205. 'email_settings',  
  206. __( 'Follower Settings', 'jetpack' ),  
  207. array( $this, 'reading_section' ),  
  208. 'reading' 
  209. ); 
  210.  
  211. add_settings_field( 
  212. 'invitation',  
  213. __( 'Blog follow email text', 'jetpack' ),  
  214. array( $this, 'setting_invitation' ),  
  215. 'reading',  
  216. 'email_settings' 
  217. ); 
  218.  
  219. add_settings_field( 
  220. 'comment-follow',  
  221. __( 'Comment follow email text', 'jetpack' ),  
  222. array( $this, 'setting_comment_follow' ),  
  223. 'reading',  
  224. 'email_settings' 
  225. ); 
  226.  
  227. /** 
  228. * Discussions setting section blurb 
  229. */ 
  230. function subscriptions_settings_section() { 
  231. ?> 
  232.  
  233. <p id="jetpack-subscriptions-settings"><?php _e( 'Change whether your visitors can subscribe to your posts or comments or both.', 'jetpack' ); ?></p> 
  234.  
  235. <?php 
  236.  
  237. /** 
  238. * Post Subscriptions Toggle 
  239. */ 
  240. function subscription_post_subscribe_setting() { 
  241.  
  242. $stb_enabled = get_option( 'stb_enabled', 1 ); ?> 
  243.  
  244. <p class="description"> 
  245. <input type="checkbox" name="stb_enabled" id="jetpack-post-subscribe" value="1" <?php checked( $stb_enabled, 1 ); ?> /> 
  246. <?php _e( "Show a <em>'follow blog'</em> option in the comment form", 'jetpack' ); ?> 
  247. </p> 
  248. <?php 
  249.  
  250. /** 
  251. * Comments Subscriptions Toggle 
  252. */ 
  253. function subscription_comment_subscribe_setting() { 
  254.  
  255. $stc_enabled = get_option( 'stc_enabled', 1 ); ?> 
  256.  
  257. <p class="description"> 
  258. <input type="checkbox" name="stc_enabled" id="jetpack-comment-subscribe" value="1" <?php checked( $stc_enabled, 1 ); ?> /> 
  259. <?php _e( "Show a <em>'follow comments'</em> option in the comment form", 'jetpack' ); ?> 
  260. </p> 
  261.  
  262. <?php 
  263.  
  264. function validate_settings( $settings ) { 
  265. global $allowedposttags; 
  266.  
  267. $default = $this->get_default_settings(); 
  268.  
  269. // Blog Follow 
  270. $settings['invitation'] = trim( wp_kses( $settings['invitation'], $allowedposttags ) ); 
  271. if ( empty( $settings['invitation'] ) ) 
  272. $settings['invitation'] = $default['invitation']; 
  273.  
  274. // Comments Follow (single post) 
  275. $settings['comment_follow'] = trim( wp_kses( $settings['comment_follow'], $allowedposttags ) ); 
  276. if ( empty( $settings['comment_follow'] ) ) 
  277. $settings['comment_follow'] = $default['comment_follow']; 
  278.  
  279. return $settings; 
  280.  
  281. public function reading_section() { 
  282. echo '<p id="follower-settings">'; 
  283. _e( 'These settings change emails sent from your blog to followers.', 'jetpack' ); 
  284. echo '</p>'; 
  285.  
  286. public function setting_invitation() { 
  287. $settings = $this->get_settings(); 
  288. echo '<textarea name="subscription_options[invitation]" class="large-text" cols="50" rows="5">' . esc_textarea( $settings['invitation'] ) . '</textarea>'; 
  289. echo '<p><span class="description">'.__( 'Introduction text sent when someone follows your blog. (Site and confirmation details will be automatically added for you.)', 'jetpack' ).'</span></p>'; 
  290.  
  291. public function setting_comment_follow() { 
  292. $settings = $this->get_settings(); 
  293. echo '<textarea name="subscription_options[comment_follow]" class="large-text" cols="50" rows="5">' . esc_textarea( $settings['comment_follow'] ) . '</textarea>'; 
  294. echo '<p><span class="description">'.__( 'Introduction text sent when someone follows a post on your blog. (Site and confirmation details will be automatically added for you.)', 'jetpack' ).'</span></p>'; 
  295.  
  296. function get_default_settings() { 
  297. return array( 
  298. 'invitation' => __( "Howdy.\n\nYou recently followed this blog's posts. This means you will receive each new post by email.\n\nTo activate, click confirm below. If you believe this is an error, ignore this message and we'll never bother you again.", 'jetpack' ),  
  299. 'comment_follow' => __( "Howdy.\n\nYou recently followed one of my posts. This means you will receive an email when new comments are posted.\n\nTo activate, click confirm below. If you believe this is an error, ignore this message and we'll never bother you again.", 'jetpack' ) 
  300. ); 
  301.  
  302. function get_settings() { 
  303. return wp_parse_args( (array) get_option( 'subscription_options', array() ), $this->get_default_settings() ); 
  304.  
  305. /** 
  306. * Jetpack_Subscriptions::subscribe() 
  307. * Send a synchronous XML-RPC subscribe to blog posts or subscribe to post comments request. 
  308. * @param string $email 
  309. * @param array $post_ids (optional) defaults to 0 for blog posts only: array of post IDs to subscribe to blog's posts 
  310. * @param bool $async (optional) Should the subscription be performed asynchronously? Defaults to true. 
  311. * @return true|Jetpack_Error true on success 
  312. * invalid_email : not a valid email address 
  313. * invalid_post_id : not a valid post ID 
  314. * unknown_post_id : unknown post 
  315. * not_subscribed : strange error. Jetpack servers at WordPress.com could subscribe the email. 
  316. * disabled : Site owner has disabled subscriptions. 
  317. * active : Already subscribed. 
  318. * unknown : strange error. Jetpack servers at WordPress.com returned something malformed. 
  319. * unknown_status : strange error. Jetpack servers at WordPress.com returned something I didn't understand. 
  320. */ 
  321. function subscribe( $email, $post_ids = 0, $async = true, $extra_data = array() ) { 
  322. if ( !is_email( $email ) ) { 
  323. return new Jetpack_Error( 'invalid_email' ); 
  324.  
  325. if ( !$async ) { 
  326. Jetpack::load_xml_rpc_client(); 
  327. $xml = new Jetpack_IXR_ClientMulticall(); 
  328.  
  329. foreach ( (array) $post_ids as $post_id ) { 
  330. $post_id = (int) $post_id; 
  331. if ( $post_id < 0 ) { 
  332. return new Jetpack_Error( 'invalid_post_id' ); 
  333. } else if ( $post_id && !$post = get_post( $post_id ) ) { 
  334. return new Jetpack_Error( 'unknown_post_id' ); 
  335.  
  336. if ( $async ) { 
  337. Jetpack::xmlrpc_async_call( 'jetpack.subscribeToSite', $email, $post_id, serialize( $extra_data ) ); 
  338. } else { 
  339. $xml->addCall( 'jetpack.subscribeToSite', $email, $post_id, serialize( $extra_data ) ); 
  340.  
  341. if ( $async ) { 
  342. return; 
  343.  
  344. // Call 
  345. $xml->query(); 
  346.  
  347. if ( $xml->isError() ) { 
  348. return $xml->get_jetpack_error(); 
  349.  
  350. $responses = $xml->getResponse(); 
  351.  
  352. $r = array(); 
  353. foreach ( (array) $responses as $response ) { 
  354. if ( isset( $response['faultCode'] ) || isset( $response['faultString'] ) ) { 
  355. $r[] = $xml->get_jetpack_error( $response['faultCode'], $response['faultString'] ); 
  356. continue; 
  357.  
  358. if ( !is_array( $response[0] ) || empty( $response[0]['status'] ) ) { 
  359. $r[] = new Jetpack_Error( 'unknown' ); 
  360. continue; 
  361.  
  362. switch ( $response[0]['status'] ) { 
  363. case 'error' : 
  364. $r[] = new Jetpack_Error( 'not_subscribed' ); 
  365. continue 2; 
  366. case 'disabled' : 
  367. $r[] = new Jetpack_Error( 'disabled' ); 
  368. continue 2; 
  369. case 'active' : 
  370. $r[] = new Jetpack_Error( 'active' ); 
  371. continue 2; 
  372. case 'pending' : 
  373. $r[] = true; 
  374. continue 2; 
  375. default : 
  376. $r[] = new Jetpack_Error( 'unknown_status', (string) $response[0]['status'] ); 
  377. continue 2; 
  378.  
  379. return $r; 
  380.  
  381. /** 
  382. * Jetpack_Subscriptions::widget_init() 
  383. * Initialize and register the Jetpack Subscriptions widget. 
  384. */ 
  385. function widget_init() { 
  386. register_widget( 'Jetpack_Subscriptions_Widget' ); 
  387.  
  388. /** 
  389. * Jetpack_Subscriptions::widget_submit() 
  390. * When a user submits their email via the blog subscription widget, check the details and call the subsribe() method. 
  391. */ 
  392. function widget_submit() { 
  393. // Check the nonce. 
  394. if ( is_user_logged_in() ) { 
  395. check_admin_referer( 'blogsub_subscribe_' . get_current_blog_id() ); 
  396.  
  397. if ( empty( $_REQUEST['email'] ) ) 
  398. return false; 
  399.  
  400. $redirect_fragment = false; 
  401. if ( isset( $_REQUEST['redirect_fragment'] ) ) { 
  402. $redirect_fragment = preg_replace( '/[^a-z0-9_-]/i', '', $_REQUEST['redirect_fragment'] ); 
  403. if ( !$redirect_fragment ) { 
  404. $redirect_fragment = 'subscribe-blog'; 
  405.  
  406. $subscribe = Jetpack_Subscriptions::subscribe( 
  407. $_REQUEST['email'],  
  408. 0,  
  409. false,  
  410. array( 
  411. 'source' => 'widget',  
  412. 'widget-in-use' => is_active_widget( false, false, 'blog_subscription', true ) ? 'yes' : 'no',  
  413. 'comment_status' => '',  
  414. 'server_data' => $_SERVER,  
  415. ); 
  416.  
  417. if ( is_wp_error( $subscribe ) ) { 
  418. $error = $subscribe->get_error_code(); 
  419. } else { 
  420. $error = false; 
  421. foreach ( $subscribe as $response ) { 
  422. if ( is_wp_error( $response ) ) { 
  423. $error = $response->get_error_code(); 
  424. break; 
  425.  
  426. switch ( $error ) { 
  427. case false: 
  428. $result = 'success'; 
  429. break; 
  430. case 'invalid_email': 
  431. $result = $error; 
  432. break; 
  433. case 'active': 
  434. case 'blocked_email': 
  435. $result = 'opted_out'; 
  436. break; 
  437. case 'pending': 
  438. $result = 'already'; 
  439. break; 
  440. default: 
  441. $result = 'error'; 
  442. break; 
  443.  
  444. $redirect = add_query_arg( 'subscribe', $result ); 
  445.  
  446. /** 
  447. * Fires on each subscription form submission. 
  448. * @module subscriptions 
  449. * @since 3.7.0 
  450. * @param string $result Result of form submission: success, invalid_email, already, error. 
  451. */ 
  452. do_action( 'jetpack_subscriptions_form_submission', $result ); 
  453.  
  454. wp_safe_redirect( "$redirect#$redirect_fragment" ); 
  455. exit; 
  456.  
  457. /** 
  458. * Jetpack_Subscriptions::comment_subscribe_init() 
  459. * Set up and add the comment subscription checkbox to the comment form. 
  460. */ 
  461. function comment_subscribe_init() { 
  462. global $post; 
  463.  
  464. $comments_checked = ''; 
  465. $blog_checked = ''; 
  466.  
  467. // Check for a comment / blog submission and set a cookie to retain the setting and check the boxes. 
  468. if ( isset( $_COOKIE[ 'jetpack_comments_subscribe_' . self::$hash ] ) && $_COOKIE[ 'jetpack_comments_subscribe_' . self::$hash ] == $post->ID ) 
  469. $comments_checked = ' checked="checked"'; 
  470.  
  471. if ( isset( $_COOKIE[ 'jetpack_blog_subscribe_' . self::$hash ] ) ) 
  472. $blog_checked = ' checked="checked"'; 
  473.  
  474. // Some themes call this function, don't show the checkbox again 
  475. remove_action( 'comment_form', 'subscription_comment_form' ); 
  476.  
  477. // Check if Mark Jaquith's Subscribe to Comments plugin is active - if so, suppress Jetpack checkbox 
  478.  
  479. $str = ''; 
  480.  
  481. if ( FALSE === has_filter( 'comment_form', 'show_subscription_checkbox' ) && 1 == get_option( 'stc_enabled', 1 ) && empty( $post->post_password ) ) { 
  482. // Subscribe to comments checkbox 
  483. $str .= '<p class="comment-subscription-form"><input type="checkbox" name="subscribe_comments" id="subscribe_comments" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;"' . $comments_checked . ' /> '; 
  484. $comment_sub_text = __( 'Notify me of follow-up comments by email.', 'jetpack' ); 
  485. $str .= '<label class="subscribe-label" id="subscribe-label" for="subscribe_comments">' . esc_html( 
  486. /** 
  487. * Filter the Subscribe to comments text appearing below the comment form. 
  488. * @module subscriptions 
  489. * @since 3.4.0 
  490. * @param string $comment_sub_text Subscribe to comments text. 
  491. */ 
  492. apply_filters( 'jetpack_subscribe_comment_label', $comment_sub_text ) 
  493. ) . '</label>'; 
  494. $str .= '</p>'; 
  495.  
  496. if ( 1 == get_option( 'stb_enabled', 1 ) ) { 
  497. // Subscribe to blog checkbox 
  498. $str .= '<p class="comment-subscription-form"><input type="checkbox" name="subscribe_blog" id="subscribe_blog" value="subscribe" style="width: auto; -moz-appearance: checkbox; -webkit-appearance: checkbox;"' . $blog_checked . ' /> '; 
  499. $blog_sub_text = __( 'Notify me of new posts by email.', 'jetpack' ); 
  500. $str .= '<label class="subscribe-label" id="subscribe-blog-label" for="subscribe_blog">' . esc_html( 
  501. /** 
  502. * Filter the Subscribe to blog text appearing below the comment form. 
  503. * @module subscriptions 
  504. * @since 3.4.0 
  505. * @param string $comment_sub_text Subscribe to blog text. 
  506. */ 
  507. apply_filters( 'jetpack_subscribe_blog_label', $blog_sub_text ) 
  508. ) . '</label>'; 
  509. $str .= '</p>'; 
  510.  
  511. /** 
  512. * Filter the output of the subscription options appearing below the comment form. 
  513. * @module subscriptions 
  514. * @since 1.2.0 
  515. * @param string $str Comment Subscription form HTML output. 
  516. */ 
  517. echo apply_filters( 'jetpack_comment_subscription_form', $str ); 
  518.  
  519. /** 
  520. * Jetpack_Subscriptions::comment_subscribe_init() 
  521. * When a user checks the comment subscribe box and submits a comment, subscribe them to the comment thread. 
  522. */ 
  523. function comment_subscribe_submit( $comment_id, $approved ) { 
  524. if ( 'spam' === $approved ) { 
  525. return; 
  526.  
  527. // Set cookies for this post/comment 
  528. $this->set_cookies( isset( $_REQUEST['subscribe_comments'] ), isset( $_REQUEST['subscribe_blog'] ) ); 
  529.  
  530. if ( !isset( $_REQUEST['subscribe_comments'] ) && !isset( $_REQUEST['subscribe_blog'] ) ) 
  531. return; 
  532.  
  533. $comment = get_comment( $comment_id ); 
  534. $post_ids = array(); 
  535.  
  536. if ( isset( $_REQUEST['subscribe_comments'] ) ) 
  537. $post_ids[] = $comment->comment_post_ID; 
  538.  
  539. if ( isset( $_REQUEST['subscribe_blog'] ) ) 
  540. $post_ids[] = 0; 
  541.  
  542. Jetpack_Subscriptions::subscribe( 
  543. $comment->comment_author_email,  
  544. $post_ids,  
  545. true,  
  546. array( 
  547. 'source' => 'comment-form',  
  548. 'widget-in-use' => is_active_widget( false, false, 'blog_subscription', true ) ? 'yes' : 'no',  
  549. 'comment_status' => $approved,  
  550. 'server_data' => $_SERVER,  
  551. ); 
  552.  
  553. /** 
  554. * Jetpack_Subscriptions::set_cookies() 
  555. * Set a cookie to save state on the comment and post subscription checkboxes. 
  556. */ 
  557. function set_cookies( $comments = true, $posts = true ) { 
  558. global $post; 
  559.  
  560. /** This filter is already documented in core/wp-includes/comment-functions.php */ 
  561. $cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 ); 
  562. /** 
  563. * Filter the Jetpack Comment cookie path. 
  564. * @module subscriptions 
  565. * @since 2.5.0 
  566. * @param string COOKIEPATH Cookie path. 
  567. */ 
  568. $cookie_path = apply_filters( 'jetpack_comment_cookie_path', COOKIEPATH ); 
  569. /** 
  570. * Filter the Jetpack Comment cookie domain. 
  571. * @module subscriptions 
  572. * @since 2.5.0 
  573. * @param string COOKIE_DOMAIN Cookie domain. 
  574. */ 
  575. $cookie_domain = apply_filters( 'jetpack_comment_cookie_domain', COOKIE_DOMAIN ); 
  576.  
  577. if ( $comments ) 
  578. setcookie( 'jetpack_comments_subscribe_' . self::$hash, $post->ID, time() + $cookie_lifetime, $cookie_path, $cookie_domain ); 
  579. else 
  580. setcookie( 'jetpack_comments_subscribe_' . self::$hash, '', time() - 3600, $cookie_path, $cookie_domain ); 
  581.  
  582. if ( $posts ) 
  583. setcookie( 'jetpack_blog_subscribe_' . self::$hash, 1, time() + $cookie_lifetime, $cookie_path, $cookie_domain ); 
  584. else 
  585. setcookie( 'jetpack_blog_subscribe_' . self::$hash, '', time() - 3600, $cookie_path, $cookie_domain );