Thinking about using one or more methods of a plugin in a theme?
This post is going to help you then.

One good way is to use static class methods in plugins, and optionally write functions as an alias:

in Plugin:

class Pluginslug_Foo {

    static $foo = 'Bar!';

    public static function bar() {
       return self::$foo;
    }

}

if ( ! function_exists( 'pluginslug_bar' ) ) {
    function pluginslug_bar() {
       echo Pluginslug_Foo::bar();
    }
}

in Theme:

if ( function_exists( 'pluginslug_bar' ) ) {
    pluginslug_bar(); // echo 'Bar!';
}

or

if ( method_exists('Pluginslug_Foo', 'bar' ) ) {
     echo Pluginslug_Foo::bar(); // echo 'Bar!';
}

******************************************************************************************

If you aren’t very familiar with PHP, use simple actions and filters in your theme, and register callbacks for those in your plugin class.

A basic example

Plugin

class Plugin_Class
{
    public function __construct()
    {
        $this->register_callbacks();
    }

    protected function register_callbacks()
    {
        add_filter( 'theme_foo', array( $this, 'foo' ) );
        add_action( 'theme_bar', array( $this, 'bar' ) );
    }

    public function foo()
    {
        return 'foo';
    }

    public function bar()
    {
        print 'bar';
    }
}

Theme

$foo = apply_filters( 'theme_foo', FALSE );

if ( $foo )
    echo "foo is $foo";

do_action( 'theme_bar' ); // prints 'bar'


Note: Commenting on the post will appreciate us highly. If this post helped you a bit, please do put a thanks in the comment box.