\QuickApps\ShortcodeShortcodeTrait

Adds shortcode parsing functionality to any class.

A Shortcode is a QuickApps-specific code that lets you do nifty things with very little effort. Shortcodes can for example print current language code or call specifics plugins/themes functions.

Summary

Methods
Properties
Constants
shortcodes()
stripShortcodes()
escapeShortcodes()
enableShortcodes()
disableShortcodes()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

shortcodes()

shortcodes(string $content, object|null $context) : string

Look for shortcodes in the given text.

If any is found an event is triggered asking for its Event Lister method. For example:

{nice_button color=green}Click Me!{/nice_button}

You must define an Event Lister nice_button:

class YourListener implements EventListenerInterface {
    public function implementedEvents() {
        return ['nice_button' => 'shortcodeNiceButton'];
    }

    public function shortcodeNiceButton(Event $event, $atts, $content, $tag) {
        // return some text
    }
}

As you can see shortcodes methods will receive three arguments:

$atts

Array which may include any arbitrary attributes that are specified by the user. Attribute names are always converted to lowercase before they are passed into the handler function. Values remains untouched.

{some_shortcode Foo="bAr" /}

Produces:

$atts = ['foo' => 'bAr'];

TIP: Don't use camelCase or UPPER-CASE for your $atts attribute names

$content

Holds the enclosed content (if the shortcode is used in its enclosing form). For self-closing shortcodes $content will be null:

{self_close some=thing /}

$tag

The shortcode name. i.e.: some_shortcode

Parameters

string $content

The the text to parse

object|null $context

Context to use when triggering events

Returns

string —

Orginal string modified with no shortcodes [..]

stripShortcodes()

stripShortcodes(string $content) : string

Removes all shortcodes from the given content.

Parameters

string $content

Text from which to remove shortcodes

Returns

string —

Content without shortcodes

escapeShortcodes()

escapeShortcodes(string $content) : string

Escapes all shortcodes from the given content.

Parameters

string $content

Text from which to escape shortcodes

Returns

string —

Content with all shortcodes escaped

enableShortcodes()

enableShortcodes() : void

Enables shortcode parser.

disableShortcodes()

disableShortcodes() : void

Globally disables shortcode parser.

The shortcodes() method will not work when disabled.