# fluent-cart/1.3.21/app/Hooks/Handlers/ShortCodes/ShortCode.php

FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler, version 1.3.21. 73 lines.

- Page: https://pluginprobe.com/plugins/fluent-cart/1.3.21/code/app/Hooks/Handlers/ShortCodes/ShortCode.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.3.21/raw/app/Hooks/Handlers/ShortCodes/ShortCode.php
- Modified: 2026-01-08T14:05:50+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-cart/1.3.21/code/app/Hooks/Handlers/ShortCodes/ShortCode.php#L10-L20`.

```php
<?php

namespace FluentCart\App\Hooks\Handlers\ShortCodes;

use FluentCart\Api\Contracts\CanEnqueue;
use FluentCart\App\App;
use FluentCart\Framework\Support\Arr;
use FluentCart\Framework\Support\Str;

abstract class ShortCode
{
    use CanEnqueue;

    protected static string $shortCodeName;
    protected ?array $shortCodeAttributes = null;
    protected ?string $slugPrefix = null;

    public function __construct(array $shortcodeAttributes = [])
    {
        $this->shortCodeAttributes = $this->parseAttribute($shortcodeAttributes);
        $this->slugPrefix = App::config()->get('app.slug');
    }

    abstract public function render(?array $viewData = null);


    public function renderShortcode($block = null)
    {
        $this->enqueueAssets();
        ob_start(null);
        $this->render(
            $this->viewData()
        );
        return ob_get_clean();
    }

    public function parseAttribute(array $shortcodeAttributes): array
    {
        return $shortcodeAttributes;
    }

    public function viewData(): ?array
    {
        return $this->shortCodeAttributes;
    }

    public static function getShortCodeName(): string
    {
        return static::$shortCodeName;
    }

    public static function register()
    {
        add_shortcode(static::getShortCodeName(), function ($shortcodeAttributes, $content, $block) {
            return static::make($shortcodeAttributes)->renderShortcode($block);
        });
    }

    protected function generateEnqueueSlug(): string
    {
        return Str::of(
            $this->slugPrefix . '_' . static::getShortCodeName()
        )->snake('')->replace('-', '_')->toString();
    }

    public static function make($shortcodeAttributes = null): ShortCode
    {
        return new static(
            Arr::wrap($shortcodeAttributes)
        );
    }
}

```
