Reply To: How to see old announcements after the role change


Home Forums Front End PM PRO How to see old announcements after the role change Reply To: How to see old announcements after the role change

#17272
Shamim Hasan
Keymaster

Use this code

add_action( 'add_user_role', 'fep_cus_update_ann_when_role_change', 10, 2 );
add_action( 'set_user_role', 'fep_cus_update_ann_when_role_change', 10, 2 );
function fep_cus_update_ann_when_role_change( $user_id, $role ) {
	global $wpdb;
	
	if ( ! defined( 'FEP_PARTICIPANT_TABLE' ) ) {
		return false;
	}
	$mgs_ids = $wpdb->get_col( $wpdb->prepare( "SELECT fep_message_id FROM $wpdb->fep_messagemeta where meta_key = %s AND meta_value = %s", '_fep_participant_roles', $role ) );
	if ( $mgs_ids ) {
		$query = 'INSERT INTO ' . FEP_PARTICIPANT_TABLE . ' (mgs_id, mgs_participant) VALUES ';
		
		foreach ( $mgs_ids as $mgs_id ) {
			$values[] = $mgs_id;
			$values[] = $user_id;
			
			$place_holders[] = '(%d, %d)';
		}
		$query .= implode( ', ', $place_holders );
		$wpdb->query( $wpdb->prepare( $query, $values ) );
		
		delete_user_meta( $user_id, '_fep_user_announcement_count' );
	}
}