_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.

This is an internal function for using it by WP core itself. It's 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.2.2

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;