shortcode_manager implements shortcode_manager_interface
Shortcode Manager.
Service responsible for managing and rendering shortcodes. Registered as a singleton in the DI container.
Table of Contents
Interfaces
- shortcode_manager_interface
- Interface for the Shortcode Manager.
Properties
- $shortcodes : array<string, callable>
Methods
- clear() : void
- Clears all registered shortcodes.
- has() : bool
- Checks whether a shortcode is registered.
- register() : void
- Registers a shortcode by associating a tag with a callback function.
- render() : string
- Processes the given text, parses shortcode patterns, and replaces them with corresponding content based on registered shortcode types.
- parse_attributes() : array<string|int, mixed>
- Parses a string containing attribute key-value pairs.
Properties
$shortcodes
private
array<string, callable>
$shortcodes
= []
Methods
clear()
Clears all registered shortcodes.
public
clear() : void
Intended for testing purposes only. It will only clear when the PHPUNIT_TEST constant is defined and set to true. In production, this method is a no-op (or you may throw an exception if desired).
has()
Checks whether a shortcode is registered.
public
has(string $tag) : bool
Parameters
- $tag : string
-
the shortcode tag name to check
Return values
bool —true if the shortcode is registered; false otherwise
register()
Registers a shortcode by associating a tag with a callback function.
public
register(string $tag, callable $callback) : void
Parameters
- $tag : string
-
the name of the shortcode tag to register
- $callback : callable
-
the callback function that renders the content for the shortcode
render()
Processes the given text, parses shortcode patterns, and replaces them with corresponding content based on registered shortcode types.
public
render(string $text) : string
Parameters
- $text : string
-
the input text containing shortcodes to be rendered
Return values
string —the text with shortcodes replaced by their respective rendered content
parse_attributes()
Parses a string containing attribute key-value pairs.
private
parse_attributes(string $string) : array<string|int, mixed>
Supports both double and single quotes.
Parameters
- $string : string
-
input string like 'type="foo" id="123"'
Return values
array<string|int, mixed> —associative array ['type' => 'foo', 'id' => '123']