amostajo/wordpress-plugin-core

Core functionality and libraries for Wordpress Plugin (a light weight plugin template with composer and MVC).

v1.0.8 2017-06-09 01:46 UTC

This package is auto-updated.

Last update: 2024-12-21 20:41:24 UTC


README

Latest Stable Version Total Downloads License

Core library for Wordpress Plugin (A Wordpress template that comes with composer and MVC);

Installation

Add

"amostajo/wordpress-plugin-core": "1.0.*"

to your composer.json. Then run composer install or composer update.

Add-on development

WP Core now supports Add-on development. To create your custom package, simply create an Add-on main class that extends from this package abstract, like the following example:

namespace MyNamespace;

use Amostajo\WPPluginCore\Classes\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\Classes\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 the plugin 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 example addon_picker_filter.

Setup plugin or theme

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

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

Coding Guidelines

The coding is a mix between PSR-2 and Wordpress PHP guidelines.

License

Lightweight MVC is free software distributed under the terms of the MIT license.