Title: WP_CLI\Utils\make_temp_file()
Published: October 6, 2026
Last modified: October 7, 2026

---

# WP_CLI\Utils\make_temp_file()

## In this article

 * [Usage](https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-utils-make-temp-file/?output_format=md#usage)
 * [Notes](https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-utils-make-temp-file/?output_format=md#notes)
 * [Related](https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-utils-make-temp-file/?output_format=md#related)

[↑ Back to top](https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-utils-make-temp-file/?output_format=md#wp--skip-link--target)

Create a unique temporary file safely without following symlinks.

---

## 󠀁[Usage](https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-utils-make-temp-file/?output_format=md#usage)󠁿

    ```
    WP_CLI\Utils\make_temp_file( $prefix = wp-cli-, $suffix = '' )
    ```

 **$prefix** (string) Optional. Prefix for the temporary file name. Default ‘wp-
cliWP-CLI WP-CLI is the Command Line Interface for WordPress, used to do administrative
and development tasks in a programmatic way. The project page is [http://wp-cli.org/](http://wp-cli.org/)
[https://make.wordpress.org/cli/](https://make.wordpress.org/cli/)-‘.
 **$suffix**(
string) Optional. Suffix for the temporary file name. Default ”. **@return** (string)
to the created temporary file.

---

## 󠀁[Notes](https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-utils-make-temp-file/?output_format=md#notes)󠁿

The file is only readable and writable by its owner on non-Windows systems.

The file is created in the directory returned by WP-CLI’s `get_temp_dir()`
 (based
on `sys_get_temp_dir()`), not WordPress’s `get_temp_dir()`, and is not removed automatically;
callers are responsible for cleaning it up.

On failure, this function exits via `WP_CLI::error()` rather than throwing.

_Internal APIAPI An API or Application Programming Interface is a software intermediary
that allows programs to interact with each other and share data in limited, clearly
defined ways. documentation is generated from the WP-CLI codebase on every release.
To suggest improvements, please submit a pull request._

---

## 󠀁[Related](https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-utils-make-temp-file/?output_format=md#related)󠁿

 * **[WP_CLI\Utils\get_home_dir()](https://make.wordpress.org/cli/handbook/internal-api/wp-cli-utils-get-home-dir/)**–
   Get the home directory.
 * **[WP_CLI\Utils\trailingslashit()](https://make.wordpress.org/cli/handbook/internal-api/wp-cli-utils-trailingslashit/)**–
   Appends a trailing slash.
 * **[WP_CLI\Utils\is_stream()](https://make.wordpress.org/cli/handbook/internal-api/wp-cli-utils-is-stream/)**–
   Check if a path is a PHPPHP PHP (recursive acronym for PHP: Hypertext Preprocessor)
   is a widely-used open source general-purpose scripting language that is especially
   suited for web development and can be embedded into HTML. [https://www.php.net/manual/en/index.php](https://www.php.net/manual/en/index.php)
   stream URLURL A specific web address of a website or web page on the Internet,
   such as a website’s URL www.wordpress.org.
 * **[WP_CLI\Utils\normalize_path()](https://make.wordpress.org/cli/handbook/internal-api/wp-cli-utils-normalize-path/)**–
   Normalize a filesystem path.
 * **[WP_CLI\Utils\get_temp_dir()](https://make.wordpress.org/cli/handbook/internal-api/wp-cli-utils-get-temp-dir/)**–
   Get the system’s temp directory. Warns user if it isn’t writable.
 * **[WP_CLI\Utils\make_temp_dir()](https://make.wordpress.org/cli/handbook/internal-api/wp-cli-utils-make-temp-dir/)**–
   Create a unique temporary directory safely without following symlinks.
 * **[WP_CLI\Utils\get_php_binary()](https://make.wordpress.org/cli/handbook/internal-api/wp-cli-utils-get-php-binary/)**–
   Get the path to the PHP binary used when executing WP-CLI.
 * **[WP_CLI::get_php_binary()](https://make.wordpress.org/cli/handbook/internal-api/wp-cli-get-php-binary/)**–
   Get the path to the PHP binary used when executing WP-CLI.

First published

October 6, 2026

Last updated

October 7, 2026

Edit article

[ Improve it on GitHub: [article_title] ](https://github.com/wp-cli/handbook/edit/main/references/internal-api/wp-cli-utils-make-temp-file.md)

Changelog

[ See list of changes: [article_title] ](https://github.com/wp-cli/handbook/commits/main/references/internal-api/wp-cli-utils-make-temp-file.md)

[  Previous: WP_CLI\Utils\make_temp_dir()](https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-utils-make-temp-dir/)

[  Next: WP_CLI\Utils\normalize_path()](https://make.wordpress.org/cli/handbook/references/internal-api/wp-cli-utils-normalize-path/)