Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_wp_check_alternate_file_names() WordPress Function

The wp_check_alternate_file_names() function is used to check if a given file name is available for use on the current WordPress installation. This function is useful when you want to ensure that a file name is unique before using it for a new attachment or other file.

_wp_check_alternate_file_names( string[] $filenames, string $dir, array $files ) #

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


Parameters

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


Top ↑

Return

(bool) True if the tested file name could match an existing file, false otherwise.


Top ↑

Source

File: wp-includes/functions.php

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;
}


Top ↑

Changelog

Changelog
VersionDescription
5.8.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More