WPCF7_FormTagsManager::scan_callback
The callback function for the form-tag scanning.
Метод класса: WPCF7_FormTagsManager{}
Хуки из метода
Возвращает
null. Ничего (null).
Использование
// private - только в коде основоного (родительского) класса $result = $this->scan_callback( $matches, $replace );
- $matches(обязательный)
- .
- $replace
- .
По умолчанию: false
Код WPCF7_FormTagsManager::scan_callback() WPCF7 FormTagsManager::scan callback CF7 6.1.3
private function scan_callback( $matches, $replace = false ) {
// allow [[foo]] syntax for escaping a tag
if ( '[' === $matches[1] and ']' === $matches[6] ) {
return substr( $matches[0], 1, -1 );
}
$tag_type = $matches[2];
$tag_basetype = trim( $tag_type, '*' );
$attr = $this->parse_atts( $matches[3] );
$scanned_tag = array(
'type' => $tag_type,
'basetype' => $tag_basetype,
'raw_name' => '',
'name' => '',
'options' => array(),
'raw_values' => array(),
'values' => array(),
'pipes' => null,
'labels' => array(),
'attr' => '',
'content' => '',
);
if ( $this->tag_type_supports( $tag_type, 'singular' ) ) {
$tags_in_same_basetype = $this->filter(
$this->scanned_tags,
array( 'basetype' => $tag_basetype )
);
if ( $tags_in_same_basetype ) {
// Another tag in the same base type already exists. Ignore this one.
return $matches[0];
}
}
if ( $this->tag_type_supports( $tag_type, 'name-attr' ) ) {
if ( ! is_array( $attr ) ) {
return $matches[0]; // Invalid form-tag.
}
$scanned_tag['raw_name'] = (string) array_shift( $attr['options'] );
if ( ! wpcf7_is_name( $scanned_tag['raw_name'] ) ) {
return $matches[0]; // Invalid name is used. Ignore this tag.
}
$scanned_tag['name'] = strtr( $scanned_tag['raw_name'], '.', '_' );
}
if ( is_array( $attr ) ) {
$scanned_tag['options'] = (array) $attr['options'];
$scanned_tag['raw_values'] = (array) $attr['values'];
if ( WPCF7_USE_PIPE ) {
$pipes = new WPCF7_Pipes( $scanned_tag['raw_values'] );
$scanned_tag['values'] = $pipes->collect_befores();
$scanned_tag['pipes'] = $pipes;
} else {
$scanned_tag['values'] = $scanned_tag['raw_values'];
}
$scanned_tag['labels'] = $scanned_tag['values'];
} else {
$scanned_tag['attr'] = $attr;
}
$scanned_tag['values'] = array_map( 'trim', $scanned_tag['values'] );
$scanned_tag['labels'] = array_map( 'trim', $scanned_tag['labels'] );
$content = trim( $matches[5] );
$content = preg_replace( "/<br[\r\n\t ]*\/?>$/m", '', $content );
$scanned_tag['content'] = $content;
$scanned_tag = apply_filters( 'wpcf7_form_tag', $scanned_tag, $replace );
$scanned_tag = new WPCF7_FormTag( $scanned_tag );
$this->scanned_tags[] = $scanned_tag;
if ( $replace ) {
$callback = $this->tag_types[$tag_type]['function'];
return $matches[1] . call_user_func( $callback, $scanned_tag ) . $matches[6];
} else {
return $matches[0];
}
}