Skip to:
Content
Pages
Categories
Search
Top
Bottom

Notify all group members


  • puresaian
    Participant

    @puresaian

    Hi,

    In a group, I want the admin to be able to post a message and other group members to receive a notification.

    Or, be able to tag all members of the group.

    Is it possible ?

    Thanx

Viewing 2 replies - 1 through 2 (of 2 total)

  • Varun Dubey
    Participant

    @vapvarun

    @puresaian To mention all group members simultaneously, you must implement a custom solution. This could be a special shortcode or command that automatically translates into individual mentions for all group members when used by the admin.

    
    /**
     * Handles the custom mention "@everyone" within BuddyPress groups.
     * When @everyone is used in a group's post or comment, it replaces it with mentions of all group members.
     */
    function wbcom_custom_everyone_mention_handler( $content ) {
        // Check if BuddyPress is loaded and @everyone is used in the content
        if ( function_exists( 'groups_get_current_group' ) && strpos( $content, '@everyone' ) !== false ) {
            // Get the current group details
            $group = groups_get_current_group();
    
            // Proceed only if we are in a group context
            if ( $group ) {
                // Fetch all members of the group
                $group_members = groups_get_group_members( array( 'group_id' => $group->id ) );
                $mentions = array();
    
                // Loop through each member to build the mentions array
                foreach ( $group_members['members'] as $member ) {
                    $mentions[] = '@' . $member->user_nicename; // Prepares the mention syntax for each member
                }
    
                // Replace @everyone in the content with the individual member mentions
                $content = str_replace('@everyone', implode(' ', $mentions), $content);
            }
        }
    
        // Return the modified (or unmodified, if no changes were made) content
        return $content;
    }
    
    // Add filters to apply the custom mention handler in different BuddyPress content types
    add_filter( 'the_content', 'wbcom_custom_everyone_mention_handler' ); // For regular WordPress content
    add_filter( 'bp_activity_new_update_content', 'wbcom_custom_everyone_mention_handler' ); // For new BuddyPress activity updates
    add_filter( 'bp_activity_comment_content', 'wbcom_custom_everyone_mention_handler' ); // For comments on BuddyPress activities
    
    

    It’s not a tested code; it’s just giving implementation directions.


    puresaian
    Participant

    @puresaian

    Thank you !

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar