BuddyDev

Search

[Resolved] Can you help me with this code.

Tagged: 

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #36946

    Hello

    I just removed this code I found out it was preventing posts from being published while using this plugin https://www.buddyboss.com/product/buddypress-user-blog/

    When I removed the code the email is now being sent

    I changed only this 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' ); 
    

    Back to this

    
     function bp_follow_notify_author_followers( $post ) {
    
    	$options             = get_option( 'bp_follow_notify_settings' ); 
    

    Also rather than use admin email, since this exposes site admin to security issues can you change it to the actual follower or recepient email.

    Thanks

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #36948

    Hello Tosin,

    Check this reply. you need to replace complete function instead.

    https://buddydev.com/support/forums/topic/can-you-help-me-with-this-code/page/3/#post-36915

    Regards
    Ravi

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #36957

    I did replace the complete function but I made 2 changes. Thank you so much for your patience this is the full code im using which is now working kindly review.

    The two changes are

    (1.) change of admin email to fixed email see below

     $follower_email = 'followers@website.com';
    
    	@wp_mail( $follower_email, $subject, $message, $headers ); 

    (2.) removal of code that prevented articles from being published

    
    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' );
    

    THE FULL CODE NOW IS

    
     function bp_follow_notify_author_followers ( $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";
    
    	$follower_email = 'followers@website.com';
    
    	@wp_mail( $follower_email, $subject, $message, $headers );
    } 
    
  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #36980

    Hello Tosin,

    Thank you for the acknowledgment. I hadn’t tested this code with the user blog plugin. If it is running fine it’s good.

    Regards
    Ravi

    • This reply was modified 3 years, 9 months ago by Ravi.
  • Participant
    Level: Initiated
    Posts: 15
    kumar on #37073

    Thank you for the help ravi your code is working fine.

You must be logged in to reply to this topic.

This topic is: resolved