How I can Activate and deactivate two plugins automatically at certain hours?
For example,
I want the "akismet" plugin to be active only from 10am to 7pm and the other Times deactivated.
and
"Yoast Seo" plugin to be active only from 7pm-10am and the other Times deactivated.
Note:
1- akismet and Yoast Seo For example and Not Real.
2- omits the fact that function.php will not run code unless the site is hit. This could cause some potential misses. The other answer here using wp_schedule_event() uses CRON, and does not rely on "outside" forces.
This code is Activate and deactivate on specific days and a plugin
$timestamp = time(); // Timestamp
$day = date( 'D', $timestamp ); // Get day from timestamp
$active = array( 'Mon', 'Wed', 'Fri', 'Sat' ); // Days plugin to be active
if ( in_array( $day, $active, true ) ) { // Yoast SEO is active
activate_plugin( '/wordpress-seo/wp-seo.php' );
} else { // Yoast SEO is deactivated
deactivate_plugins( '/wordpress-seo/wp-seo.php' );
}
How can I do it? Thanks.