gwa/zero-library-shortcodes

Addon for zero library to build wordpress shortcodes faster.

v1.3.0 2015-11-05 10:01 UTC

This package is not auto-updated.

Last update: 2024-11-09 19:14:52 UTC


README

Latest Version on Packagist Total Downloads Software License

Master

Build Status Coverage Status Quality Score

Develop

Build Status Coverage Status Quality Score

Install

Via Composer

$ composer require gwa/zero-library-shortcodes

Usage

First you need to extend RendererData and create a getDefaults function.

use Gwa\Wordpress\Template\Zero\Library\Shortcodes\RendererData;

class CardData extends RendererData
{
    public function getDefaults()
    {
        return [
            'title' => null,
            'btn'   => null,
            'url'   => null,
        ];
    }
}

Now we extend the Renderer and add some values for some keys.

use Gwa\Wordpress\Template\Zero\Library\Shortcodes\Renderer;

class CardRenderer extends Renderer
{
    public function render()
    {
        return $this->get('title');
    }
}

Last thing now is to create a shortcode class.

use Gwa\Wordpress\Template\Zero\Library\Shortcodes\Shortcode;

class CardShortcode extends Shortcode
{
    public $atts = [
        'title' => ''
    ];

    public function getShortcode()
    {
        return 'card';
    }

    public function render($atts)
    {
        $attr = $this->getWpBridge()->shortcodeAtts($this->atts, $atts);

        return = (new CardRenderer())->setRendererData($this->getData())->render();
    }

    protected function getData()
    {
        $renderdata = new CardData();
        $renderdata->set('content', $this->getContent($id))
            ->set('url', 'http://google.com/')
            ->set('title', 'google');

        return $renderdata;
    }
}

Register you plugin.

use Gwa\Wordpress\MockeryWpBridge\WpBridge;

(new CardShortcode())->setWpBridge(new WpBridge())->init();

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.