$parsecode_tags
$parsecode_tags : array
Container for storing parsecode tags and their hook to call for the parsecode
add(string $tag, callable $func) : boolean
Add hook for parsecode tag.
There can only be one hook for each parsecode. Which means that if another
plugin has a similar parsecode, it will override yours or yours will override
theirs depending on which order the plugins are included and/or ran.
Simplest example of a parsecode tag using the API:
<code>
// [footag foo="bar"]
function footag_func($atts) {
return "foo = {$atts[foo]}";
}
Parsecode::add('footag', 'footag_func');
</code>
Example with nice attribute defaults:
<code>
// [bartag foo="bar"]
function bartag_func($atts) {
$args = Parsecode::atts([
'foo' => 'no foo',
'baz' => 'default baz',
], $atts);
return "foo = {$args['foo']}";
}
Parsecode::add('bartag', 'bartag_func');
</code>
Example with enclosed content:
<code>
// [baztag]content[/baztag]
function baztag_func($atts, $content='') {
return "content = $content";
}
Parsecode::add('baztag', 'baztag_func');
</code>
string | $tag | Parsecode tag to be searched in post content. |
callable | $func | Hook to run when parsecode is found. |
doParsecode(string $content) : string
Search content for parsecodes and filter parsecodes through their hooks.
If there are no parsecode tags defined, then the content will be returned without any filtering. This might cause issues when plugins are disabled but the parsecode will still show up in the post or content.
string | $content | Content to search for parsecodes |
Content with parsecodes filtered out.
getRegex() : string
Retrieve the parsecode regular expression for searching.
The regular expression combines the parsecode tags in the regular expression in a regex class.
The regular expression contains 6 different sub matches to help with parsing.
1 - An extra [ to allow for escaping parsecodes with double [[]] 2 - The parsecode name 3 - The parsecode argument list 4 - The self closing / 5 - The content of a parsecode when it wraps some content. 6 - An extra ] to allow for escaping parsecodes with double [[]]
The parsecode search regular expression
parseAtts(string $text) : array
Retrieve all attributes from the parsecodes tag.
The attributes list has the attribute name as the key and the value of the attribute as the value in the key/value pair. This allows for easier retrieval of the attributes, since all attributes have to be known.
string | $text |
List of attributes and their value.
atts(array $pairs, array $atts) : array
Combine user attributes with known attributes and fill in defaults when needed.
The pairs should be considered to be all of the attributes which are supported by the caller and given as a list. The returned attributes will only contain the attributes in the $pairs list.
If the $atts list has unsupported attributes, then they will be ignored and removed from the final returned list.
array | $pairs | Entire list of supported attributes and their defaults. |
array | $atts | User defined attributes in parsecode tag. |
Combined and filtered attribute list.