Properties

$parsecode_tags

$parsecode_tags : array

Container for storing parsecode tags and their hook to call for the parsecode

Type

array

$instance

$instance : self

Type

self — The stored singleton instance

Methods

resetInstance()

resetInstance() 

Reset the Container instance.

getInstance()

getInstance() : self

Creates the original or retrieves the stored singleton instance

Returns

self

cleanPre()

cleanPre(  $matches) 

Parameters

$matches

add()

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>

Parameters

string $tag

Parsecode tag to be searched in post content.

callable $func

Hook to run when parsecode is found.

Returns

boolean

remove()

remove(string  $tag) 

Removes hook for parsecode.

Parameters

string $tag

parsecode tag to remove hook for.

removeAll()

removeAll() 

Clear all parsecodes.

This function is simple, it clears all of the parsecode tags by replacing the parsecodes global by a empty array. This is actually a very efficient method for removing all parsecodes.

exists()

exists(string  $tag) : boolean

Whether a registered parsecode exists named $tag

Parameters

string $tag

Returns

boolean

has()

has(string  $content, string  $tag) : boolean

Whether the passed content contains the specified parsecode.

Parameters

string $content
string $tag

Returns

boolean

doParsecode()

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.

Parameters

string $content

Content to search for parsecodes

Returns

string —

Content with parsecodes filtered out.

getRegex()

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 [[]]

Returns

string —

The parsecode search regular expression

parseAtts()

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.

Parameters

string $text

Returns

array —

List of attributes and their value.

atts()

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.

Parameters

array $pairs

Entire list of supported attributes and their defaults.

array $atts

User defined attributes in parsecode tag.

Returns

array —

Combined and filtered attribute list.

stripParsecodes()

stripParsecodes(string  $content) : string

Remove all parsecode tags from the given content.

Parameters

string $content

Content to remove parsecode tags.

Returns

string —

Content without parsecode tags.

stripParsecodeTag()

stripParsecodeTag(  $m) 

Parameters

$m

autop()

autop(string  $pee, boolean  $br = true) : string|mixed

Parameters

string $pee
boolean $br

Returns

string|mixed

autopNewlinePreservationHelper()

autopNewlinePreservationHelper(  $matches) 

Parameters

$matches

unAutop()

unAutop(  $pee) 

Parameters

$pee

doTag()

doTag(array  $m) : mixed

Regular Expression callable for $this->doParsecode() for calling parsecode hook.

Parameters

array $m

Regular expression match array

Returns

mixed —

False on failure.