BuddyDev

Search

Custom notification

Tagged: 

  • Participant
    Level: Initiated
    Posts: 14
    Abhist on #43814

    Hi
    Thankyou for great forums.

    I want to send notification to particle particular user when its role /member Type change.

    Can it possible by some code in bp-custom

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #43820

    Hello Abhist,

    Thank you for posting. Please use the following code:

    
    
    add_action( 'bp_set_member_type', function ( $user_id, $member_type ) {
    	// $user_id     ID of the user whose member type has been updated.
    	// $member_type The member type name or an array of member type names.
    
    	$user = get_user_by( 'id', $user_id );
    
    	if ( ! $user ) {
    		return;
    	}
    
    	// Provide the email subject.
    	$subject = '';
    
    	// Provide the email message.
    	$message = '';
    
    	@wp_mail( $user->user_email, $subject, $message );
    } );
    

    Please check and let me know if it helps or not.

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 14
    Abhist on #44102

    hi
    thanks ravi for responce

    i want to send message instead of email
    please help

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #44104

    Hello,

    Try the following code:

    
    
    add_action( 'bp_set_member_type', function ( $user_id, $member_type ) {
    	// If message component not exists return.
    	if ( ! bp_is_active( 'messages' ) ) {
    		return;
    	}
    
    	// $user_id     ID of the user whose member type has been updated.
    	// $member_type The member type name or an array of member type names.
    	$user = get_user_by( 'id', $user_id );
    
    	if ( ! $user ) {
    		return;
    	}
    
    	// Provide the email subject.
    	$subject = '';
    
    	// Provide the email message.
    	$message = '';
    
    	// Send only if member type send by other user. You may skip this.
    	if ( get_current_user_id() != $user->ID ) {
    		messages_new_message(
    			array(
    				'sender_id'  => get_current_user_id(),
    				'recipients' => array( $user->ID ),
    				'subject'    => $subject,
    				'content'    => $message,
    			)
    		);
    	}
    } );
    
    

    Regards
    Ravi

  • Participant
    Level: Initiated
    Posts: 14
    Abhist on #45335

    THANK YOU SO MUCH.
    Given code is working perfectly .

    but I want to send notification instead of message .

    please guide.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 2934
    Ravi on #45353

    Hi,

    You are welcome.

    I am sorry, I lack the time to assist you further with custom code.

    Please take a look at this page, especially the bottom links to see how to create BuddyPress Notifications.

    https://codex.buddypress.org/administrator-guide/notifications/

    Regards
    Ravi

You must be logged in to reply to this topic.

This topic is: not resolved