1. Home
  2. Docs
  3. Subscribe2
  4. Hooks, API & Customization
  5. s2_send_plain_excerpt_subscribers s2_send_plain_fullcontent_subscribers s2_send_html_excerpt_subscribers s2_send_html_fullcontent_subscribers

s2_send_plain_excerpt_subscribers s2_send_plain_fullcontent_subscribers s2_send_html_excerpt_subscribers s2_send_html_fullcontent_subscribers

These hooks allow the list of recipients (who will be Registered Subscribers) to be amended immediately prior to the email notification being sent. These hooks are quite useful to sites running role management plugins. Each of these filters passes 2 arguments. The first is an array of recipient email addresses and the second if the post ID number.

Based upon your desired functionality you can collect and assess information related to the post via the post ID number and then add recipients to or remove recipients from the email address array.

function s2member_filter($subscribers, $post_id) {
    // $subscribers is an array of subscriber email addresses
    $args = array(
        'role' => 's2member_level1',
        'fields' => array('user_email')
    );
    $s2_level1 = get_users($args);
 
    $args = array(
        'role' => 's2member_level2',
        'fields' => array('user_email')
    );
    $s2_level2 = get_users($args);
 
    $args = array(
        'role' => 's2member_level3',
        'fields' => array('user_email')
    );
    $s2_level3 = get_users($args);
 
    $all_s2_members = array_merge($s2_level1, $s2_level2, $s2_level3);
 
    foreach ($all_s2_members as $user) {
        $s2members[] = $user->user_email;
    }
 
    // we can do thins with the $postid also
    // like amend the subscribers list of the post id is in a specific category
    $categories = wp_get_post_categories($post_id);
    if ( in_array('1', $categories) ) {
        //The post is in category 1 so do something different
    }
 
    $filtered_subscribers = array_intersect($subscribers, $s2members);
} // end s2member_filter()
 
add_filter('s2_send_plain_excerpt_subscribers', 's2member_filter', 10, 2);
add_filter('s2_send_plain_fullcontent_subscribers', 's2member_filter', 10, 2);
add_filter('s2_send_html_excerpt_subscribers', 's2member_filter', 10, 2);
add_filter('s2_send_html_fullcontent_subscribers', 's2member_filter', 10, 2);
Was this article helpful to you? Yes No

How can we help?