Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 1 replies (of 1 total)

  • twobyte
    Participant

    @twobyte

    Great thanks.

    I added a custom shortcode to the form to embed group_id as a hidden input field then changed the wpcf7_mail_components filter:

    
    add_filter( 'wpcf7_mail_components', 'ccc_group_mail_components', 10, 3 );
    
    function ccc_group_mail_components( $components ) {
    	global $bp;
    	if ( isset( $_POST['group_id']) && $_POST['group_id'] > 0 ) {
    		$group_id = $_POST['group_id'];
    		$groupadmins = groups_get_group_admins( $group_id );
    		$recipients = array();
    		foreach( $groupadmins as $admin ) {
    	   		$admin_info = get_userdata($admin->user_id);
    			$recipients[] = $admin_info->user_email;
    		}
    		if(count($recipients)>0){
    			$components['recipient'] = implode(",", $recipients);
    		}else {
    			// append a little alert to subject line so we know admin emails weren‘t found.
    			$components['subject'] = $components['subject']. ' (Error: No group admins found)' ;
    		}
    		// lets tag subject line with group section as well for traceability
    		$group = groups_get_group( array( 'group_id' => $group_id) );
    		$components['subject'] = '['.$group->name.'] '.$components['subject'];
    		
    	}
    		
    	return $components;
    }
    

    It works now but I was having a proper time trying to get group name using bp_get_group_name($group_id) instead of groups_get_group( array( ‘group_id’ => $group_id) ). I suppose the former must be used in the loop!

Viewing 1 replies (of 1 total)
Skip to toolbar