Skip to content

gwa/zero-library-shortcodes

Repository files navigation

zero-library-shortcodes

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.

About

Tools for creating WordPress shortcodes with the Zero Library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages