Execute function activatedeactivate plugin in specific pages

admin2025-04-18  1

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

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

最新回复(0)