Add-ons development

The framework supports Add-ons.

External packages that act as add-ons or partials for your project, giving you additional functionality. These are created exclusively for the framework.

Create an Add-on

Start your add-on development (in form of package) by adding Plugin Core package as dependency.

Create an Add-on main class that extends from this package abstract, like the following example:

namespace MyNamespace;

use Amostajo\WPPluginCore\Addon;

class PostPicker extends Addon
{
    /**
     * Function called when plugin or theme starts.
     * Add wordpress hooks (actions, filters) here.
     */
    public function init()
    {
        // YOUR CUSTOM CODE HERE.
    }

    /**
     * Function called when user is on admin dashboard.
     * Add wordpress hooks (actions, filters) here.
     */
    public function on_admin()
    {
        // YOUR CUSTOM CODE HERE.
    }
}

This is how you should add your WordPress hooks:

namespace MyNamespace;

use Amostajo\WPPluginCore\Addon;

class PostPicker extends Addon
{
    /**
     * Function called when plugin or theme starts.
     * Add wordpress hooks (actions, filters) here.
     */
    public function init()
    {
        add_filter( 'post_content', [ &$this, 'picker_filter' ] )
    }

    /**
     * Called by wordpress.
     */
    public function picker_filter()
    {
        // YOUR CUSTOM CODE HERE.
    }
}

Accessing Main class

You can call the main class from any custom method in your Add-on class, like this:

/**
 * Custom method.
 */
public function picker_filter()
{
    // Getting a config settings.
    $this->main->config->get( 'setting' );
}

Calling for Add-on’s controllers or views:

MVC

/**
 * Custom method.
 */
public function picker_filter()
{
    // Calling MVC.
    $this->mvc->call( 'Controller@method' );
}

Your controllers should be placed in a controllers folder on the same level as your Add-on class, same for the views folder.

Calling ADD-ON methods from main class

The Main class can call methods in the Add-on by adding the addon_ prefic, like for exampleaddon_picker_filter.

Using cache

Cache can be used to improve performance. Only Cache function remember() should be used since some projects might have Cache disabled.

Setup plugin or theme

Finally add your package in the configuration file. For example:

    'addons' => [
        'MyNamespace\PostPicker',
    ],