Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ass_digest_fire( $type ) {
- global $bp;
- if ( !$type )
- $type = 'dig';
- // This is done with bp_has_groups because user subscription status is stored in groupmeta. Therefore you can't simply pull up a list of all members on the site and run through them one by one. The bp_has_groups method will result in far fewer db hits
- if ( bp_has_groups( 'per_page=100000' ) ) {
- if ( $type == 'dig' )
- $subject = sprintf( __( 'Your daily digest of group activity', 'bp-ass' ) );
- else
- $subject = sprintf( __( 'Your weekly summary of group topics', 'bp-ass' ) );
- $blogname = get_blog_option( BP_ROOT_BLOG, 'blogname' );
- $subject .= ' [' . $blogname . '] ';
- $footer = "\n-----------\n";
- $footer .= sprintf( __( "You have received this message because you are subscribed to receive a digest of activity in some of your groups on %s. To change your notification settings for a given group, click on the group\'s link above and visit the Email Options page.", 'bp-ass' ), $blogname );
- $member_sent = array();
- while ( bp_groups() ) {
- bp_the_group();
- $group_id = bp_get_group_id();
- $subscribers = groups_get_groupmeta( $group_id , 'ass_subscribed_users' );
- // number of sent emails
- $s = 0;
- foreach ( (array)$subscribers as $subscriber => $email_status ) {
- // Each user only gets one digest each time around
- if ( in_array( $subscriber, $member_sent ) )
- continue;
- // Get the activity items the user needs to receive. If there are none, move on to the next member
- if ( !$group_activity_ids_array = get_usermeta( $subscriber, 'ass_digest_items' ) )
- continue;
- // We only want the weekly or daily ones
- if ( !$group_activity_ids = (array)$group_activity_ids_array[$type] )
- continue;
- $message = $subject . "\n\n----------------------\n";
- $summary = __( 'Group Summary', 'bp-ass');
- foreach ( $group_activity_ids as $group_id => $activity_ids ) {
- // get group name and add it to this
- $group = new BP_Groups_Group( $group_id );
- $group_name = bp_get_group_name( $group );
- $act_count = count( $activity_ids );
- $summary .= "\n- " . $group_name . ' ' . sprintf( __( '(%s items)', 'bp-ass' ), $act_count );
- $activity_message .= ass_digest_format_item_group( $group_id, $activity_ids, $type );
- unset( $group_activity_ids[$group_id] );
- }
- $summary .= "\n----------------------\n\n";
- if ( $type == 'dig' )
- $message .= $summary;
- $message .= $activity_message;
- $message .= $footer;
- $message = strip_tags(stripslashes( $message ) );
- // Get the details for the user
- $ud = bp_core_get_core_userdata( $subscriber );
- // Set up and send the message
- $to = $ud->user_email;
- //echo '<br><br>========================================================<br><br>';// For testing only
- //echo '<pre> To: '.$to . '</pre>'; // For testing only
- //echo '<pre>'; print_r( $message ); echo '</pre>'; //die(); // For testing only
- wp_mail( $to, $subject, $message );
- unset( $message, $to );
- $group_activity_ids_array[$type] = $group_activity_ids;
- update_usermeta( $subscriber, 'ass_digest_items', $group_activity_ids_array ); // comment this out for helpful testing
- $member_sent[] = $subscriber;
- $s++;
- if ( $s % 50 == 0 )
- sleep(10); // to help server load, delay 10 seconds for every 50 messages sent
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement