Search
Close
AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

AI Assistant
Notifications
Clear all

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

4 Posts
2 Users
0 Reactions
2,631 Views
(@maroelamedia)
Member Customer
Joined: 9 years ago
Posts: 2
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
  [#4759]

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: 7 years ago
Posts: 1403
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

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: 7 years ago
Posts: 1403
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

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: 9 years ago
Posts: 2
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
 

Hi Elvina, thank you so much!



   
Share:
Scroll to top