Good evening, I'm not a php developer but I wrote this script (tested and fully working):
function deactivate_plugin_conditional() { if ( is_plugin_active('plugin-name/plugin.php') ) { require_once(ABSPATH .'/wp-admin/includes/plugin.php'); deactivate_plugins('plugin-name/plugin.php'); } } add_action( 'admin_init', 'deactivate_plugin_conditional' ); sleep(1); function activate_plugin_conditional() { if ( is_plugin_inactive('plugin-name/plugin.php') ) { require_once(ABSPATH .'/wp-admin/includes/plugin.php'); activate_plugins('plugin-name/plugin.php'); } } add_action( 'admin_init', 'activate_plugin_conditional' );
I inserted it in functions.php theme, but doing so everytime some one (backed or front end) open the website it runs (obviously). I have to make it run in two specific page (imagine with id 321 and 322). To intercept a page from functions.php I wrote this code:
add_filter( 'template_include', function( $template ) { if ( is_page( array( 321, 322 ) ) ) echo 'Here You are'; else { echo 'KO'; } return $template; });
And this script works too, BUT if I try to merge theme....it doesn't work. Is there anyone that could help me to figure it out? Warm regards Ale
sleep
function call? Note that deactivating and reactivating plugins at runtime is extremely unusual, and bad practice. You're clearly trying to solve a problem caused by a plugin on a page, maybe you should ask about that rather than trying to get this solution to work? By asking about this you've severely limited your options, and easier solutions to your original problem can't be posted as answerssleep
, I also don't see why this would solve your problem if it takes half an hour of cumulative time for it to slow down. I would ignore CPanel and focus on performance data from that page load that was slow, eitherway diagnosing issues with that plugin is the vendors support task not Stack Exchange, and I very much doubt that disabling and enabling will help. Your proposed solution also triggers a number of other potential problems, e.g. triggering activation/deactivation triggers that might cleanup tables