1

I've developed a small plugin which empties the $plugin variable. And put it into the /mu-plugins folder. But it doesn't work.

What am I missing? The plugin is executed.

If I do a print_r on $plugin it contains all the name of the plugins of my Wordpress installation.

The plugin code is:

$uri = $_SERVER['REQUEST_URI'];

        if($uri == "/wp-admin/admin-ajax.php")
        {
            for($i=1; $i < count($plugins); $i++ ) 
            {
                {
                    unset( $plugins[$i] );
                }
            }   
        }

        return $plugins;

===========

This is the whole code

<?php

    class DisablePlugins {
    var $namespace = "disable-plugins";
    var $version = '1.0.0';

    /**
     * Instantiation construction
     * 
     * @uses add_filter()
     */
    function __construct() {
        // Directory path to this plugin's files
        $this->dirname = dirname( __FILE__ );
        // Rules configurations directory
        $this->rules_dirname = $this->dirname . '/' . $this->namespace . '-rules';

        $this->siteurl = get_option( 'siteurl' );
        $siteurl_http_host = parse_url( $this->siteurl );
        $this->siteurl_http_host = $siteurl_http_host['host'];

        add_filter( 'option_active_plugins', array( &$this, 'option_active_plugins' ), 1000, 1 );
    }

    /**
     * Initialization function to hook into the WordPress init action
     * 
     * Instantiates the class on a global variable and sets the class, actions
     * etc. up for use.
     */
    function instance() {
        global $DisablePlugins;

        $DisablePlugins = new DisablePlugins();
    }


    /**
     * Hook into WordPress option_$option filter
     * 
     * Get processed array of active plugins being loaded for a view to allow filtering
     * based off of a user's preferences
     */
    function option_active_plugins( $plugins ) {
        $rules = $this->load_rules();
        $uri = $_SERVER['REQUEST_URI'];

        if($uri == "/wp-admin/admin-ajax.php")
        {
            for($i=1; $i < count($plugins); $i++ ) 
            {
                {
                    unset( $plugins[$i] );
                }
            }   
        }

        return $plugins;

    }
}

// Initiate the DisablePlugins class
DisablePlugins::instance();
14
  • Could be a lot of things. What triggers your code and when?
    – jdm2112
    Sep 22, 2016 at 13:56
  • Is the code in a function triggered by a hook? Where does the value of $plugins come from? What happens to the returned value? Sep 22, 2016 at 14:03
  • 1
    You don't think $rules = $this->load_rules(); might be halting the script with an undefined function error? Have you checked for PHP errors? Sep 22, 2016 at 15:46
  • 1
    The instance() function references a hook to WP's init action but that statement appears to be missing. As it is, this plugin does not appear to actually do anything.
    – jdm2112
    Sep 22, 2016 at 19:50
  • 1
    Correct. The last line instantiates the class so the constructor fires, sets a few values, and hooks a callback function option_active_plugins() to a filter that doesn't exist, in WordPress anyway. Constructor finishes and nothing happens. I think we've found the problem.
    – jdm2112
    Sep 22, 2016 at 20:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.