Skip to main content
deleted 1 character in body
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

If your 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()
    {
        returnprint 'bar';
    }
}

Theme

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

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

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

If your 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()
    {
        return 'bar';
    }
}

Theme

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

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

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

If your 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'
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

If your 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()
    {
        return 'bar';
    }
}

Theme

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

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

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