WPCF7_FormTagsManager::filter
Filters form-tags based on a condition array argument.
Метод класса: WPCF7_FormTagsManager{}
Хуков нет.
Возвращает
Массив. The filtered form-tags collection.
Использование
$WPCF7_FormTagsManager = new WPCF7_FormTagsManager(); $WPCF7_FormTagsManager->filter( $input, $cond );
- $input(массив|строка) (обязательный)
- The original form-tags collection. If it is a string, scans form-tags from it.
- $cond(массив) (обязательный)
- The conditions that filtering will be based on.
Код WPCF7_FormTagsManager::filter() WPCF7 FormTagsManager::filter CF7 6.1.5
public function filter( $input, $cond ) {
if ( is_array( $input ) ) {
$tags = $input;
} elseif ( is_string( $input ) ) {
$tags = $this->scan( $input );
} else {
$tags = $this->scanned_tags;
}
$cond = wp_parse_args( $cond, array(
'type' => array(),
'basetype' => array(),
'name' => array(),
'feature' => array(),
) );
$cond = array_map( static function ( $c ) {
return array_filter( array_map( 'trim', (array) $c ) );
}, $cond );
$tags = array_filter(
(array) $tags,
function ( $tag ) use ( $cond ) {
$tag = new WPCF7_FormTag( $tag );
if (
$cond['type'] and
! in_array( $tag->type, $cond['type'], true )
) {
return false;
}
if (
$cond['basetype'] and
! in_array( $tag->basetype, $cond['basetype'], true )
) {
return false;
}
if (
$cond['name'] and
! in_array( $tag->name, $cond['name'], true )
) {
return false;
}
foreach ( $cond['feature'] as $feature ) {
if ( str_starts_with( $feature, '!' ) ) { // Negation
$feature = trim( substr( $feature, 1 ) );
if ( $this->tag_type_supports( $tag->type, $feature ) ) {
return false;
}
} else {
if ( ! $this->tag_type_supports( $tag->type, $feature ) ) {
return false;
}
}
}
return true;
}
);
return array_values( $tags );
}