PHP code example of gwa / zero-library-shortcodes

1. Go to this page and download the library: Download gwa/zero-library-shortcodes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gwa / zero-library-shortcodes example snippets

 php

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

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

 php

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

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

 php

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;
    }
}

 php
use Gwa\Wordpress\MockeryWpBridge\WpBridge;

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