Shortcodes final class
Minn\Runtime\Shortcodes · public/minn/src/Minn/Runtime/Shortcodes.php · 274 lines
The shortcode registry plugin code fills with add_shortcode, and the expansion do_shortcode performs: [tag attrs], [tag attrs/], [tag]…[/tag] (the first closing tag wins; content is not expanded again), [[tag]] as the literal, unregistered tags left as written.
Constants and properties
| const | ATTRIBUTES = '/([\\w-]+)\\s*=\\s*"([^"]*)"(?:\\s|$)|([\\w-]+)\\s*=\\s*\'([^\']*)\'(?:\\s|$)|([\\w-]+)\\s*=\\s*([^\\s\'"]+)(?:\\s|$)|"([^"]*)"(?:\\s|$)|\'([^\']*)\'(?:\\s|$)|(\\S+)(?:\\s|$)/' | The attribute pattern shortcode_parse_atts reads by (get_shortcode_atts_regex). |
| private | SET_ASIDE = array ( '[' => '[', ']' => ']', ) | |
| private | RESTORE = array ( '[' => '[', ']' => ']', ) | |
| private | array $tags |
Public
| method | tags(): array# | The registry itself, by reference, so the $shortcode_tags global plugin code reads and copies is this array and not a snapshot of it. @return array<string, callable> | |||
| method | add(string $tag, callable $callback): void# | Registers a shortcode. | |||
| method | remove(string $tag): void# | Forgets a shortcode. | |||
| method | removeAll(): void# | Forgets every shortcode. | |||
| method | has(string $tag): bool# | Whether a shortcode is registered. | |||
| method | all(): array# | Every shortcode with its callback. @return array<string, callable> every registered tag and its handler, to restore after a narrowed run | |||
| method | restore(array $tags): void# | Replaces the registry, after a save-and-restore.
| |||
| method | names(): array# | Every shortcode name. @return list<string> | |||
| method | pattern(?array $tags = NULL): ?string# | The regex matching the registered shortcodes, or null for none. | |||
| method | apply(string $content, string $tags = 'run'): string# | Content with its shortcodes run (do_shortcode, probe shortcode-run): only the registered names the text holds; inside HTML tags first (inTags: run, or with 'escape' as with ignore_html, left alone), then in the text, each through run(); the brackets set aside as entities come back at the end. Images rendered meanwhile see the do_shortcode context. | |||
| method | run(array $m): string# | One matched shortcode (do_shortcode_tag): [[tag]] gives the tag as written; otherwise pre_do_shortcode_tag may answer, or the callback runs with the attributes, the content ("" when it closes itself) and the name, and do_shortcode_tag sees the output in its brackets.
| |||
| method | inTags(string $content, string $tags, array $names): string# | Shortcodes inside HTML tags (do_shortcodes_in_html_tags), run before the text: a quoted attribute value's shortcode runs and the attribute is judged again by kses, kept when anything is left; an unquoted one (or one standing as a name or as the tag) runs as written. Comments, CDATA and, with 'escape', every tag are left alone. Brackets left in a tag (and entities already written for them) are set aside so the text pass cannot reach them.
| |||
| method | strip(string $content): string# | Content with its shortcodes taken out (strip_shortcodes): the names strip_shortcodes_tagnames leaves, never inside a tag; [[tag]] gives the tag as written. | |||
| static | stripped(array $m): string# | One matched shortcode taken out (strip_shortcode_tag): its outer brackets stay, [[tag]] gives the tag. @param array<int, string> $m
| |||
| static | parse(string $text): array# | Shortcode attribute text as an array (shortcode_parse_atts): no-break and zero-width spaces read as spaces; name=value pairs (names lower case) and bare values in order, each a token followed by whitespace or the end, backslash escapes undone; a value holding "<" that is not whole tags becomes "". @return array<int|string, string> |
Internals 2
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
Nothing matches.