BuddyDev

Search

[Resolved] Can you help me with this code.

Tagged: 

  • Participant
    Level: Guru
    Posts: 772
    Tosin on #36840

    Hello Ravi,

    I think me and kumar have the same issue, but maybe your feedback is the solution, but I dont really know how to code or how to apply your solution. We just dont want the emails of other users to be exposed to the current recepient.

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2541
    Ravi on #36841

    Hello Tosin,

    Please replace the following line:

    
    $headers .= "From: " . $sender_name . " <" . $sender_email . ">" . "\r\n";
    

    with

    
    $headers .= "From: " . $sender_name . "\r\n";
    $headers .= "Bcc: " . $sender_email . "\r\n";
    
    

    Now, Give it a shot and let me know if it works or not.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 15
    kumar on #36854

    Thanks for replying Ravi, but the above code is not working and is still sending emails without BCC.

  • Participant
    Level: Guru
    Posts: 772
    Tosin on #36858

    I have tested it the emails of other followers are still exposed

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2541
    Ravi on #36884

    Hello Tosin,

    Can please share the screenshot and point me to the email you want to hide?.

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 772
    Tosin on #36885

    Hello Ravi,

    Kindly see screenshot https://ibb.co/YhzMN3J

    The mail was sent to one recipient but the emails of other recipients can viewed.

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2541
    Ravi on #36915

    Hello Tosin,

    Replace this function “bp_follow_notify_author_followers” with following code:

    
    
    function bp_follow_notify_author_followers( $new_status, $old_status, $post ) {
    
    	if ( $new_status === $old_status || 'publish' !== $new_status ) {
    		return;
    	}
    
    	$post = get_post( $post );
    
    	$options             = get_option( 'bp_follow_notify_settings' );
    	$selected_post_types = empty( $options['bp_follow_notify_post_types'] ) ? array() : $options['bp_follow_notify_post_types'];
    
    	if ( ! in_array( $post->post_type, $selected_post_types ) ) {
    		return;
    	}
    
    	$author_id   = $post->post_author;
    	$author_name = get_the_author_meta( 'display_name', $author_id );
    	$counts      = bp_follow_total_follow_counts( array( 'user_id' => $author_id ) );
    
    	if ( empty( $counts['followers'] ) ) {
    		return;
    	}
    
    	$followers = bp_follow_get_followers( array( 'user_id' => $author_id ) );
    
    	$blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    
    	$subject = '[' . $blog_name . '] New Post From ' . $author_name;
    
    	$message = sprintf( __( '
    				%2$s
    				
    				%3$s
    				
    				Link: %4$s
    				-----------
    				You are receiving this email because you are following %1$s.', 'bp-follow-notify' ),
    		$author_name,
    		$post->post_title,
    		wp_trim_words( $post->post_content ),
    		get_permalink( $post->ID )
    	);
    
    	$notifying_emails = array();
    	foreach ( $followers as $follower ) {
    
    		/* Email Notification */
    
    		$user               = get_user_by( 'id', $follower );
    		$notifying_emails[] = $user->user_email;
    
    		/* BP Notification */
    		if ( bp_is_active( 'notifications' ) ) {
    			bp_notifications_add_notification( array(
    				'user_id'           => $user->ID,
    				'item_id'           => $post->ID,
    				'secondary_item_id' => $author_id,
    				'component_name'    => 'bp_follow_notify',
    				'component_action'  => 'follow_new_post',
    				'date_notified'     => bp_core_current_time(),
    				'is_new'            => 1,
    			) );
    		}
    	}
    
    	$sender_name  = ( ! empty( $options['bp_follow_notify_sender_name'] ) ? $options['bp_follow_notify_sender_name'] : $blog_name );
    	$sender_email = ( ! empty( $options['bp_follow_notify_sender_email'] ) ? $options['bp_follow_notify_sender_email'] : 'no-reply@' . $blog_name );
    
    	$headers = '';
    
    	$headers = "MIME-Version: 1.0" . "\r\n";
    	$headers .= "Content-type: text/html; charset=" . get_bloginfo( 'charset' ) . "" . "\r\n";
    	$headers .= "From: " . $sender_name . " <" . $sender_email . ">" . "\r\n";
    
    	$bcc_emails = join( ',', $notifying_emails );
    
    	$headers .= "Bcc: " . $bcc_emails . "\r\n";
    
    	$admin_email = get_option( 'admin_email' );
    
    	@wp_mail( $admin_email, $subject, $message, $headers );
    }
    
    

    Try this.

    Regards
    Ravi

    • This reply was modified 1 year, 10 months ago by Ravi.
  • Participant
    Level: Guru
    Posts: 772
    Tosin on #36923

    I’ve tested it the post notification mail is no longer being sent. The plugin is not working as no post notification email was received.

  • Participant
    Level: Guru
    Posts: 772
    Tosin on #36939

    Any update sir please not that im not reffering to the screenshot I sent before but now the actual post notification mail itself is not being sent.

    Thanks

    • This reply was modified 1 year, 10 months ago by Tosin.
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2541
    Ravi on #36942

    Hello Tosin,

    I have tested this and it was working for me. By default, I am using admin email in the context of “To” and the rest of the followers emails under “Bcc”. Check the following URL:

    https://tinyurl.com/ygfmmtcx

    Have you replaced “bp_follow_notify_author_followers” with above mentioned?

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: resolved