• Resolved Rodrigo Arias

    (@kreppar)


    Hi,

    Thanks for your work on this plugin, I’ve been using it for a while now and it’s been really useful.

    I was wondering if it is possible to add a filter to disable the plugin from the code, perhaps by wrapping the initial run function.

    The automatic counter question is, why not just disable it from the admin?

    The reason is that I am installing Autoptimize through the WordPress Packagegist in a larger plugin that I use on both PHP and headless sites. In the latter, I would like to disable Autoptimize without losing it completely.

    Thanks in advance

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    sure, you can disable AO using this code snippet;

    
    add_filter( 'autoptimize_filter_noptimize', '__return_true' );

    hope this helps,
    frank

    Thread Starter Rodrigo Arias

    (@kreppar)

    Thanks Frank for your answer.

    The filter you suggest refers to output buffering, I’m looking for something to not instantiate the plugin at all (admin notices, admin menus, etc.) since the optimizations just don’t apply when the front-end is in a different layer.

    Do you think it is possible to add a filter in autoptimize.php? Willing to submit a PR if there was a repository.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    ah, no need for an extra filter for that, you can use something like this (based on https://kinsta.com/blog/disable-wordpress-plugins-loading/):

    add_filter( 'option_active_plugins', function( $plugins ){
    	$myplugin = "autoptimize/autoptimize.php";
    	if( !in_array( $myplugin, $plugins ) ){
    		$plugins[] = $myplugin;
    	}
    	return $plugins;
    } );
    Thread Starter Rodrigo Arias

    (@kreppar)

    Thanks for the answer Frank.

    The options filter works only if the plugin you want to disable is installed in root (you can see it in admin), not if it is a dependency of another plugin. That’s why I’m looking for a filter in Autoptimize. If it’s disabled by default it shouldn’t hurt, right?

    autoptimize.php#L97

    if ( apply_filters( 'autoptimize_filter_disable_plugin', false ) ) {
        return;
    }
    Plugin Author Optimizing Matters

    (@optimizingmatters)

    Too complex for me to wrap my head around it, but if default false I can live with it ?? Feel free to issue a PR in https://github.com/futtta/autoptimize ??

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    added your PR in the beta, will normally release later this month ??

    Thread Starter Rodrigo Arias

    (@kreppar)

    Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Filter to deactivate the plugin’ is closed to new replies.