$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - deactivating an active plugin using if page|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - deactivating an active plugin using if page

matteradmin9PV0评论

Good day! just wondering if you can help me out? I was trying to create a code for functions.php if the user currently lands on a specific page, thus the plugin will turn deactivated, but if the user re jumps on other pages, the plugin would be re activated.

Here's my code.

function disable_plugins(){
if( is_page(2690) ) {
    deactivate_plugins( '/popup-maker/popup-maker.php');
} else {
    //reactivate the plugin
}
} add_filter('option_active_plugins', 'disable_plugins');

Good day! just wondering if you can help me out? I was trying to create a code for functions.php if the user currently lands on a specific page, thus the plugin will turn deactivated, but if the user re jumps on other pages, the plugin would be re activated.

Here's my code.

function disable_plugins(){
if( is_page(2690) ) {
    deactivate_plugins( '/popup-maker/popup-maker.php');
} else {
    //reactivate the plugin
}
} add_filter('option_active_plugins', 'disable_plugins');
Share Improve this question asked Oct 18, 2018 at 10:30 rrwrrw 1 2
  • 2 This is entirely the wrong approach. It should not be necessary to disable a plugin entirely just because you don't want a pop-up to appear on a single page. It's overkill, and a hack. Look at the plugin's documentation to find a supported way to disable the pop-up on a specific page, or ask the author for help. If that doesn't work find a plugin that does support this feature. – Jacob Peattie Commented Oct 18, 2018 at 11:52
  • 1 if you deactivate a plugin by a users page visit, you would deactivate it entirely, also for every other user.. so yeah, your approach is kinda wrong here.. – honk31 Commented Oct 18, 2018 at 13:41
Add a comment  | 

1 Answer 1

Reset to default 2

Instead of deactivating the plugin completely (which would deactivate it everywhere on your site) look at the plugin's code and determine what JS and CSS it is enqueuing. Then in your theme's functions.php you can dequeue that plugin's JS/CSS - but only on whatever pages you want to disable the plugin on.

So for example, for the plugin Authorizer, if you want to remove the CSS from two pages, "about" and "contact":

add_action('wp_print_styles', 'wpse_317011_dequeue_authorizer');
function wpse_317011_dequeue_authorizer() {
    if(is_page('about') || is_page('contact')) {
        wp_dequeue_style('authorizer-public-css');
        wp_deregister_style('authorizer-public-css');
    }
}

Just replace authorizer-public-css with whatever CSS file you need to from your specific plugin. And dequeue JS as well, if that's needed.

Other conditionals like is_singular() work here too in case it's not just Pages you're dealing with.

Post a comment

comment list (0)

  1. No comments so far