wpcf7_acceptable_filetypes()
Returns a formatted list of acceptable filetypes.
Хуков нет.
Возвращает
Строку. Formatted list of acceptable filetypes.
Использование
wpcf7_acceptable_filetypes( $types, $format );
- $types(строка|массив)
- Array of filetypes.
По умолчанию:'default' - $format(строка)
- Pre-defined format designator.
По умолчанию:'regex'
Код wpcf7_acceptable_filetypes() wpcf7 acceptable filetypes CF7 6.1.6
function wpcf7_acceptable_filetypes( $types = 'default', $format = 'regex' ) {
if ( 'default' === $types or empty( $types ) ) {
$types = array(
'audio/*',
'video/*',
'image/*',
);
} else {
$types = array_map(
static function ( $type ) {
if ( is_string( $type ) ) {
return preg_split( '/[\s|,]+/', strtolower( $type ) );
}
},
(array) $types
);
$types = wpcf7_array_flatten( $types );
$types = array_filter( array_unique( $types ) );
}
if ( 'attr' === $format or 'attribute' === $format ) {
$types = array_map(
static function ( $type ) {
if ( false === strpos( $type, '/' ) ) {
return sprintf( '.%s', trim( $type, '.' ) );
} elseif ( preg_match( '%^([a-z]+)/[*]$%i', $type, $matches ) ) {
if (
in_array( $matches[1], array( 'audio', 'video', 'image' ), true )
) {
return $type;
} else {
return '';
}
} elseif ( wpcf7_convert_mime_to_ext( $type ) ) {
return $type;
}
},
$types
);
$types = array_filter( $types );
return implode( ',', $types );
} elseif ( 'regex' === $format ) {
$types = array_map(
static function ( $type ) {
if ( false === strpos( $type, '/' ) ) {
return preg_quote( trim( $type, '.' ) );
} elseif ( $type = wpcf7_convert_mime_to_ext( $type ) ) {
return $type;
}
},
$types
);
$types = wpcf7_array_flatten( $types );
$types = array_filter( array_unique( $types ) );
return implode( '|', $types );
}
return '';
}