0

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.

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. 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

1 Answer 1

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

3
  • If the actual plugin itself is totally deactivated then the short code is going to appear in the content. Commented Feb 2, 2019 at 0:58
  • You can check if a plugin active with this function is_plugin_active($plugin_path), then can conditionally output short code
    – Maidul
    Commented Feb 2, 2019 at 5:18
  • Not inside content you can’t. Commented Feb 2, 2019 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.