functions - How to disableenable a plugin at a specific time

admin2025-01-07  5

Is there a hook that would allow me to disable and enable a specified plugin at a certain time?

For example, I would like to disable the wp contact form 7 plugin every Tuesday at 6 AM and enable it on Wednesday at 2 PM.

Is this feasible?

Thanks!


I guess I wasn't clear enough, but I only used Contact From 7 as an example. The plugin I want to disable is a random plugin, and I want to totally disable it and enable it based on a predefined time.

Is there a hook that would allow me to disable and enable a specified plugin at a certain time?

For example, I would like to disable the wp contact form 7 plugin every Tuesday at 6 AM and enable it on Wednesday at 2 PM.

Is this feasible?

Thanks!


I guess I wasn't clear enough, but I only used Contact From 7 as an example. The plugin I want to disable is a random plugin, and I want to totally disable it and enable it based on a predefined time.

Share Improve this question edited Feb 3, 2019 at 5:57 ali pik asked Feb 1, 2019 at 19:29 ali pikali pik 193 bronze badges 2
  • Do you actually want the plugin deactivated, or do you just want a form itself to be closed to submissions during this time? Those are two very different questions. – Jacob Peattie Commented Feb 2, 2019 at 0:58
  • @JacobPeattie I guess I wasn't clear enough, but I only used Contact From 7 as an example. The plugin I want to disable is a random plugin, and I want to totally disable it and enable it based on a predefined time. – ali pik Commented Feb 3, 2019 at 5:56
Add a comment  | 

1 Answer 1

Reset to default 0

You can use deactivate_plugins() function to deactivate a plugin

if ( ! wp_next_scheduled( 'deactivate_plugin_conditional_hook' ) ) {
  wp_schedule_event( time(), 'twicedaily', 'deactivate_plugin_conditional_hook' );
}

add_action( 'deactivate_plugin_conditional_hook', 'deactivate_plugin_conditional_2345678999343434' );

function deactivate_plugin_conditional_2345678999343434() {
$plugin_path = 'plugin-folder/plugin-name.php';
    if ( is_plugin_active($plugin_path) ) {
    deactivate_plugins($plugin_path);    
    }
}

You can set custom event see here https://codex.wordpress.org/Function_Reference/wp_schedule_event

Note: this is not tested code

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736254625a220.html

最新回复(0)