0

I have a function which unset plugins on the front-end.
The only extra criteria, in_category ( 'my-cat-name' ), I am not able to achieve.

Where and how to add the category so the plugins are only unset on post types which belong to this category?

I tried if( !is_admin() && is_category('my-cat-name') ) but that seems not correct.

Below the code I have add, in a separate file, in the mu-plugins folder.
As it is now, the plugins are removed from all post and that is not what I want to achieve.

if( !is_admin() ) {
    add_filter( 'option_active_plugins', 'de_active_plugins' );    
}
function de_active_plugins( $plugins ) 
{
    $skip   = array();   
    $skip[] = 'plugin01_foldername/plugin01_name.php';   
    $skip[] = 'plugin02_foldername/plugin02_name.php';   

    foreach ( $skip as $plugin ) {
        $collected = array_search( $plugin, $plugins );
        if( false !== $collected ) {
            unset( $plugins[$collected] );
        }
    }
    return $plugins; 
}

I appreciate all help.

  • The problem is timing- if you refer to this action reference list, plugin loading has completed on action #4, is_category starts working on action #26. – Milo Feb 26 '19 at 3:25
  • @Milo, Is there perhaps another way (or other action/filter) to achieve this? Triggering on post types, terms, tags or some are all 'too late' if I understand you correctly?! – Jerry.S Feb 26 '19 at 12:28
  • Why are you trying to disable plugins on specific requests? What are you trying to prevent? – Milo Feb 26 '19 at 14:07
  • Some plugins are loaded on the front-end although sometimes not needed/used on a post /cpt/category. To prevent piling up (unnecessarily) http/s request I want to unset those plugins (some plugins have no option to select where/when to load). It's of course easy to say 'just' a few more request aint such a big deal, true when having not that many users but it starts counting when having daily over 7k users on a site with several k postings and a multiple of that amount images. Anyway, is there no 'easy' way to unset, the way I hoped to achieve? – Jerry.S Feb 26 '19 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.