WP_HTML_Tag_Processor::parse_query
Parses tag query input into internal search criteria.
Method of the class: WP_HTML_Tag_Processor{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->parse_query( $query );
- $query(array|string|null) (required)
Which tag name to find, having which class, etc.
Default:
to find any tag-
tag_name(string|null)
Which tag to find, ornullfor "any tag." -
match_offset(int|null)
Find the Nth tag matching all search criteria.
1 for "first" tag, 3 for "third," etc.
Default: first tag -
class_name(string|null)
Tag must contain this class name to match. - tag_closers(string)
"visit" or "skip": whether to stop on tag closers, e.g. </div>.
-
Changelog
| Since 6.2.0 | Introduced. |
WP_HTML_Tag_Processor::parse_query() WP HTML Tag Processor::parse query code WP 7.0
private function parse_query( $query ) {
if ( null !== $query && $query === $this->last_query ) {
return;
}
$this->last_query = $query;
$this->sought_tag_name = null;
$this->sought_class_name = null;
$this->sought_match_offset = 1;
$this->stop_on_tag_closers = false;
// A single string value means "find the tag of this name".
if ( is_string( $query ) ) {
$this->sought_tag_name = $query;
return;
}
// An empty query parameter applies no restrictions on the search.
if ( null === $query ) {
return;
}
// If not using the string interface, an associative array is required.
if ( ! is_array( $query ) ) {
_doing_it_wrong(
__METHOD__,
__( 'The query argument must be an array or a tag name.' ),
'6.2.0'
);
return;
}
if ( isset( $query['tag_name'] ) && is_string( $query['tag_name'] ) ) {
$this->sought_tag_name = $query['tag_name'];
}
if ( isset( $query['class_name'] ) && is_string( $query['class_name'] ) ) {
$this->sought_class_name = $query['class_name'];
}
if ( isset( $query['match_offset'] ) && is_int( $query['match_offset'] ) && 0 < $query['match_offset'] ) {
$this->sought_match_offset = $query['match_offset'];
}
if ( isset( $query['tag_closers'] ) ) {
$this->stop_on_tag_closers = 'visit' === $query['tag_closers'];
}
}