Does an activated plugin automatically mean its methods are available to other WP functions?

Technically, it is possible. But I would use a slightly different approach. If your second plugin is loaded first you get an error. If you want to replace the class in another plugin, it is hard to do this.

So hook into plugins_loaded with a specific priority to create the object and use the object in your second plugin on the same hook with a lower (later) priority:

Plugin 1

add_action( 'plugins_loaded', array ( 'My_Class', 'init' ), 10 );

class My_Class
{
    /**
     * Handler for the action 'init'. Instantiates this class.
     *
     * @since 0.1
     * @return void
     */
    public static function init()
    {
        // Named global variable to make access for other scripts easier.
        $GLOBALS[ __CLASS__ ] = new self;
    }
    public function __construct() { /* Do something awesome. */ }
}

Plugin 2

add_action( 'plugins_loaded', 'depending_operation', 11 );

function depending_operation()
{
    if ( empty ( $GLOBALS[ 'My_Class' ] ) )
    {
        return;
    }
    /* Do something awesome again. */
}

Note the 10 and the 11 in add_action()? This guarantees that your second plugin will never run before the first. It still has to check if the first plugin is active and working.

Now you can even replace the class in another plugin:

Plugin 3

add_action( 'plugins_loaded', 'replace_global_class', 12 );

function replace_global_class()
{
    $GLOBALS[ 'My_Class' ] = new Replacement_Class;
}

class Replacement_Class {}

Leave a Comment