Schedule WordPress plugin activation and / or deactivation on a custom date and time, how to do?

It’s not something that WordPress supports out of the box, but I think you can whip up some custom code to achieve this.

I think you can use WordPress cron job that will check the current date and time for this to activate/deactivate the plugin accordingly.

Here’s an example for deactivating:

add_action('wp', 'plugin_deactivation_schedule');
function plugin_deactivation_schedule() {
    if (!wp_next_scheduled('custom_deactivate_plugin')) {
        // Schedule to run on 7th January 2024, at 15:00
        $timestamp = strtotime('2024-01-07 15:00:00');
        wp_schedule_single_event($timestamp, 'custom_deactivate_plugin');
    }
}

add_action('custom_deactivate_plugin', 'deactivate_my_plugin');

function deactivate_my_plugin() {
    // Replace with your plugin string
    $plugin = 'my-cool-plugin/my-cool-plugin.php';

    if (is_plugin_active($plugin)) {
        deactivate_plugins($plugin);
    }
}

For the activation one, you can follow the same snippet and just change the last set of if condition to check if the plugin is not activated, you activate it.

if (!is_plugin_active($plugin)) {
     activate_plugin($plugin);
}

About the plugin string, you can find it in your plugin files. For example, if your plugin’s main file is located at wp-content/plugins/your-custom-plugin/your-custom-plugin.php, the plugin string would be your-custom-plugin/your-custom-plugin.php.

deneme bonusu veren sitelerbahis siteleripulibet girişdeneme bonusutürkçe altyazılı pornocanlı bahis casinocanlı bahis casino siteleriOnwin Güncel Girişholiganbetholiganbet girişholiganbet güncel giriş