I would like to limit the amount of reports overall (not for each listing) to 5 per week. I wrote this code, but it doesn’t work. How can I fix this?
add_filter(
'hivepress/v1/forms/listing_report/errors',
function( $errors, $form ) {
$user_id = get_current_user_id();
if ( $user_id ) {
$report_count = \HivePress\Models\Report::query()->filter(
[
'user' => $user_id,
'date_query' => [
[
'after' => '1 week ago',
'inclusive' => true,
],
],
]
)->get_count();
if ( $report_count >= 5 ) {
$errors[] = 'Only 5 reports per week are allowed.';
}
}
return $errors;
},
1000,
2
);