Hi there
We need to constantly moderate comments on our website but it's a massive job and want to prevent visitors from leaving comments after hours each day.
We have done this before with WordPress's built-in comments by switching the comments template with the filter 'comments_template' if the current time is after 19:30 and before 05:30.
Now we plan on switching to wpDiscuz. Which filter should I use to hide the form and display a custom message in it's place after hours?
Any help would be greatly appreciated. The current code follows:
// Filters
if ( mm_is_afterhours() ) {
add_filter( 'comments_template', 'mm_comm_schedule_template', 10 );
add_filter( 'comment_reply_link', 'mm_comm_schedule_reply_remove', 10 );
}
function mm_is_afterhours() {
$tz = 'Africa/Johannesburg';
$timestamp = time();
$dt = new DateTime( "now", new DateTimeZone( $tz ) ); //first argument "must" be a string
$dt->setTimestamp( $timestamp ); //adjust the object to correct timestamp
$current_time = $dt->format( 'Gi' ); //24 hour (without leading zero) and minutes
if ( 1930 <= $current_time || $current_time < 530 ) {
// After 19:30 or before 05:30
return true;
} else {
return false;
}
}
Hi @maroelamedia,
I've just asked our developers and currently I'm waiting for the response from them.
I'll update the topic asap.
Hi @maroelamedia,
// Filters
if ( mm_is_afterhours() ) {
add_filter( 'comments_template', 'mm_comm_schedule_template', 10 );
add_filter( 'comment_reply_link', 'mm_comm_schedule_reply_remove', 10 );
}function mm_is_afterhours() {
$tz = 'Africa/Johannesburg';
$timestamp = time();
$dt = new DateTime( "now", new DateTimeZone( $tz ) ); //first argument "must" be a string
$dt->setTimestamp( $timestamp ); //adjust the object to correct timestamp$current_time = $dt->format( 'Gi' ); //24 hour (without leading zero) and minutes
if ( 1930 <= $current_time || $current_time < 530 ) {
// After 19:30 or before 05:30
return true;
} else {
return false;
}
}
Please replace the red mark code with the following.
if (mm_is_afterhours()) {
add_filter('comments_open', '__return_false');
add_action('wpdiscuz_comment_form_closed', function () {
echo '//Here should be your custom message';
});
}
Save, delete all caches and check again.
Hi Elvina, thank you so much!