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

#17233
shamim
Keymaster

Add following code in your theme’s (child theme’s if any) functions.php

add_action( 'set_user_role', function( $user_id, $role, $old_roles ) {
	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' );
	}
}, 10, 3 );