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

FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler, version 1.6.5. 83 lines.

- Page: https://pluginprobe.com/plugins/fluent-cart/1.6.5/code/app/Hooks/Handlers/ShortCodes/ShortCode.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/1.6.5/raw/app/Hooks/Handlers/ShortCodes/ShortCode.php
- Modified: 2026-08-20T12:34:14+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.6.5/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\App\Services\Renderer\RenderContext;
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) {
            // WordPress exposes no "shortcode currently rendering" signal, so
            // this is the one place that has to say so. Every ShortCode
            // subclass registers through here, so it is the only place.
            return RenderContext::declaring(
                RenderContext::SOURCE_SHORTCODE,
                static::getShortCodeName(),
                function () use ($shortcodeAttributes, $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)
        );
    }
}

```
