WP_Filesystem_FTPext::exists( string $path ): bool
Checks if a file or directory exists.
Parameters
-
$path
string Required -
Path to file or directory.
Return
bool Whether $path exists or not.
Source
File: wp-admin/includes/class-wp-filesystem-ftpext.php
.
View all references
public function exists( $path ) {
/*
* Check for empty path. If ftp_nlist() receives an empty path,
* it checks the current working directory and may return true.
*
* See https://core.trac.wordpress.org/ticket/33058.
*/
if ( '' === $path ) {
return false;
}
$list = ftp_nlist( $this->link, $path );
if ( empty( $list ) && $this->is_dir( $path ) ) {
return true; // File is an empty directory.
}
return ! empty( $list ); // Empty list = no file, so invert.
}
Changelog
Version | Description |
---|---|
6.3.0 | Returns false for an empty path. |
2.5.0 | Introduced. |