Notifications
Clear all

Limited Support

Our support team is currently on holiday from December 25, 2025 to January 7, 2026, and replies may be delayed during this period.

We appreciate your patience and understanding while our team is away. Thank you for being part of the gVectors community!

Merry Christmas and Happy Holidays! 🎄

[Solved] Hide and display comment form according to daily schedule

4 Posts
2 Users
0 Reactions
2,479 Views
(@maroelamedia)
Member Customer
Joined: 8 years ago
Posts: 2
Topic starter  

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;
}
}

 



   
Elvina
(@elvina)
Support
Joined: 6 years ago
Posts: 1403
 

Hi @maroelamedia,

I've just asked our developers and currently I'm waiting for the response from them.
I'll update the topic asap.



   
Elvina
(@elvina)
Support
Joined: 6 years ago
Posts: 1403
 

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.



   
(@maroelamedia)
Member Customer
Joined: 8 years ago
Posts: 2
Topic starter  

Hi Elvina, thank you so much!



   
Share:
Scroll to top