Tkt_Shortcodes_Processor
in package
The ShortCode Resolver Class.
Description
This is used to make shortcodes nested in ShortCode attributes, or HTML attributes work. WordPress 4.2.3 (thus also CP) breaks all ShortCodes in ShortCode attributes, or ShortCodes in HTML attributes.
Tags
Table of Contents
- $declarations : array<string|int, mixed>
- The Configuration object.
- $plugin_prefix : string
- The unique prefix of this plugin.
- $version : string
- The version of this plugin.
- __construct() : mixed
- Initialize the class and set its properties.
- get_all_matches_between() : array<string|int, mixed>
- Get all matches of between 2 delimiters.
- get_custom_shortcodes() : array<string|int, mixed>
- Get the list of registered shortcodes to be used inside other shortcodes.
- get_native_inner_shortcodes() : array<string|int, mixed>
- Get a list of inbuilt ShortCodes allowed inside other Shortcodes or HTML.
- post_process_shortcodes() : mixed
- Public facing filter callback on the_content.
- pre_process_shortcodes() : mixed
- Public facing filter callback on the_content.
- apply_decoder() : string
- Decoders and Resolvers passed to the post_process_shortcodes callback.
- apply_encoder() : string
- Encoders and Resolvers passed to the pre_process_shortcodes callback.
- decode_iterators() : string
- Decode base64.
- encode_html_attribute_shortcodes() : string
- WordPress does not like ShortCodes inside HTML attributes.
- encode_iterators() : string
- Encode loops to base64.
- find_outer_brackets() : int
- Find shortcodes that contain other shortcodes as attribute values, and populate a list of their opening tag, to process those internal shortcodes.
- get_inner_expressions() : array<string|int, mixed>
- Get ShortCodes we accept as inner ShortCodes, or HTML attributes.
- has_shortcode_as_attribute_value() : bool
- Make sure that a content which presumes to be a shortcode without brackets does contain an inner shortcode.
- html_split() : array<string|int, mixed>
- Separate HTML elements and comments from the text.
- is_unbracketed_shortcode() : bool
- Make sure that a given content is indeed a shortcode without brackets: - Can not start with a closing tag delimiter.
- resolve_html_shortcodes() : string
- Decode and resolve ShortCodes in HTML attributes.
- resolve_inner_shortcodes() : string
- Resolve internal shortcodes.
- should_skip_html_node() : bool
- Check if HTML note should be skipped.
Properties
$declarations
The Configuration object.
private
array<string|int, mixed>
$declarations
Description
All configurations and declarations of this plugin.
Tags
$plugin_prefix
The unique prefix of this plugin.
private
string
$plugin_prefix
Description
The string used to uniquely prefix technical functions of this plugin.
Tags
$version
The version of this plugin.
private
string
$version
Description
The current version of this plugin.
Tags
Methods
__construct()
Initialize the class and set its properties.
public
__construct(string $plugin_prefix, string $version, array<string|int, mixed> $declarations) : mixed
Parameters
- $plugin_prefix
- (string) The unique prefix of this plugin.
- $version
- (string) The version of this plugin.
- $declarations
- (array<string|int, mixed>) The Configuration object.
Tags
Return
(mixed)get_all_matches_between()
Get all matches of between 2 delimiters.
public
get_all_matches_between(string $str, string $start, string $end) : array<string|int, mixed>
Description
This generic helper function finds any string starting and ending with a flag. It then returns an array where the values are the strings between each start and end flag.
Parameters
- $str
- (string) The string to check.
- $start
- (string) The start flag to check for.
- $end
- (string) The end flag to check for.
Tags
Return
(array<string|int, mixed>) $contents The found occurrences of string betwen start and end.get_custom_shortcodes()
Get the list of registered shortcodes to be used inside other shortcodes.
public
get_custom_shortcodes() : array<string|int, mixed>
Tags
Return
(array<string|int, mixed>)get_native_inner_shortcodes()
Get a list of inbuilt ShortCodes allowed inside other Shortcodes or HTML.
public
get_native_inner_shortcodes() : array<string|int, mixed>
Tags
Return
(array<string|int, mixed>)post_process_shortcodes()
Public facing filter callback on the_content.
public
post_process_shortcodes(string $content) : mixed
Parameters
- $content
- (string) The Post Content.
Tags
Return
(mixed)pre_process_shortcodes()
Public facing filter callback on the_content.
public
pre_process_shortcodes(string $content) : mixed
Parameters
- $content
- (string) The Post Content.
Tags
Return
(mixed)apply_decoder()
Decoders and Resolvers passed to the post_process_shortcodes callback.
private
apply_decoder(string $content) : string
Parameters
- $content
- (string) The Post Content.
Tags
Return
(string) $content The Post Content Decoded and Resolved.apply_encoder()
Encoders and Resolvers passed to the pre_process_shortcodes callback.
private
apply_encoder(string $content) : string
Parameters
- $content
- (string) The Post Content.
Tags
Return
(string) $content The Post Content encoded and with first level of inner ShortCodes resolved.decode_iterators()
Decode base64.
private
decode_iterators(string $content) : string
Description
If the Content has loop
shortcodes, these are encoded to base64.
At this point we resolved surrouding shortcodes, and need to prepare the loops for resolution.
Parameters
- $content
- (string) The Post Content with base64 encoded loops.
Tags
Return
(string) $content The Post Content with decoded (but not resolved) loops.encode_html_attribute_shortcodes()
WordPress does not like ShortCodes inside HTML attributes.
private
encode_html_attribute_shortcodes(string $content) : string
Description
Encode all [shortcodes] (the applicable ones) to use {¡{shortcode}¡} format.
Parameters
- $content
- (string) The Post Content.
Tags
Return
(string) $content The Post Content with encoded HTML attribute ShortCodes.encode_iterators()
Encode loops to base64.
private
encode_iterators(string $content) : string
Description
Encode all loop
ShortCodes contents to base64 so WordPress does
not attempt to resolve them until we explicitly want to.
Parameters
- $content
- (string) The Post Content.
Tags
Return
(string) $content The Post Content with encoded loops.find_outer_brackets()
Find shortcodes that contain other shortcodes as attribute values, and populate a list of their opening tag, to process those internal shortcodes.
private
find_outer_brackets(string $content, array<string|int, mixed> &$matches) : int
Parameters
- $content
- (string) The content to check.
- $matches
- (array<string|int, mixed>) List of shortcodes: full shortcode without brackets.
Tags
Return
(int) $count Number of top level shortcodes found.get_inner_expressions()
Get ShortCodes we accept as inner ShortCodes, or HTML attributes.
private
get_inner_expressions() : array<string|int, mixed>
Description
Only registered, non-enclosing ShortCodes are allowed. Users can add theyr Custom ShortCodes by using the filter tkt_scs_custom_inner_shortcodes
Tags
Return
(array<string|int, mixed>) $inner_expressions An array of registered shortcodes.has_shortcode_as_attribute_value()
Make sure that a content which presumes to be a shortcode without brackets does contain an inner shortcode.
private
has_shortcode_as_attribute_value(string $unbracketed_shortcode) : bool
Parameters
- $unbracketed_shortcode
- (string) The content to check.
Tags
Return
(bool) Whether the Inner ShortCode is present.html_split()
Separate HTML elements and comments from the text.
private
html_split(string $input) : array<string|int, mixed>
Description
Heavily inspired in wp_html_split.
Parameters
- $input
- (string) The text which has to be formatted.
Tags
Return
(array<string|int, mixed>) The formatted text.is_unbracketed_shortcode()
Make sure that a given content is indeed a shortcode without brackets: - Can not start with a closing tag delimiter.
private
is_unbracketed_shortcode(string $unbracketed_shortcode) : bool
Description
- Can not start with a bracket for another inner shortcode.
- Must start with a valid shortcode tag.
Parameters
- $unbracketed_shortcode
- (string) The content to check.
Tags
Return
(bool) Whether the ShortCode is without brackets.resolve_html_shortcodes()
Decode and resolve ShortCodes in HTML attributes.
private
resolve_html_shortcodes(string $content) : string
Description
If there are encoded {¡{shortcodes}¡} then it means they are used in HTML attributes. Revert them to the native [shortcode] syntax, and resolve them.
Parameters
- $content
- (string) The Post Content with encoded HTML attribute ShortCodes.
Tags
Return
(string) $content The Post Content with decoded and resolved HTML attribute ShortCodes.resolve_inner_shortcodes()
Resolve internal shortcodes.
private
resolve_inner_shortcodes(string $content) : string
Parameters
- $content
- (string) The Post Content.
Tags
Return
(string)should_skip_html_node()
Check if HTML note should be skipped.
private
should_skip_html_node(mixed $element) : bool
Description
It is not necessary to process all this in HTML comments, or CDATA items.
Parameters
- $element
- (mixed) The HTML node to check.