Please go to Dashboard > Front End PM PRO > Settings > General and set “Time delay” as 0
Then add following code in your theme’s (child theme’s if any) functions.php
add_action( 'fep_action_validate_form', 'fep_cus_diff_time_delay_for_roles', 10, 2);
function fep_cus_diff_time_delay_for_roles( $where, $errors ) {
if( 'newmessage' != $where )
return;
$args = array(
'post_type' => 'fep_message',
'post_status' => array( 'pending', 'publish' ),
'posts_per_page' => 2,
'author' => get_current_user_id(),
'date_query' => array(
'after' => '-1 week'
)
);
if( 'threaded' == fep_get_message_view() )
$args['post_parent'] = 0;
$posts = get_posts( $args );
if( ! $posts )
return;
$roles = wp_get_current_user()->roles;
if( array_intersect( array( 's2member_level1', 's2member_level2'), $roles ) ) {
$errors->add('time_delay', __( 'You can send maximum 1 message a week.', 'front-end-pm' ) );
} elseif( count( $posts ) >= 2 && array_intersect( array( 's2member_level3', 's2member_level4'), $roles ) ){
$errors->add('time_delay', __( 'You can send maximum 2 messages a week.', 'front-end-pm' ) );
}
}