_wp_check_alternate_file_names()WP 5.8.1

Helper function to test if each of an array of file names could conflict with existing files.

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

No Hooks.


true|false. True if the tested file name could match an existing file, false otherwise.


_wp_check_alternate_file_names( $filenames, $dir, $files );
$filenames(string[]) (required)
Array of file names to check.
$dir(string) (required)
The directory containing the files.
$files(array) (required)
An array of existing files in the directory. May be empty.


Since 5.8.1 Introduced.

_wp_check_alternate_file_names() code WP 6.5.4

function _wp_check_alternate_file_names( $filenames, $dir, $files ) {
	foreach ( $filenames as $filename ) {
		if ( file_exists( $dir . $filename ) ) {
			return true;

		if ( ! empty( $files ) && _wp_check_existing_file_names( $filename, $files ) ) {
			return true;

	return false;