{"id":18587,"date":"2026-10-06T13:20:18","date_gmt":"2026-10-06T13:20:18","guid":{"rendered":"https:\/\/make.wordpress.org\/cli\/handbook\/references\/internal-api\/wp-cli-utils-make-temp-dir\/"},"modified":"2026-10-07T07:49:02","modified_gmt":"2026-10-07T07:49:02","slug":"wp-cli-utils-make-temp-dir","status":"publish","type":"handbook","link":"https:\/\/make.wordpress.org\/cli\/handbook\/references\/internal-api\/wp-cli-utils-make-temp-dir\/","title":{"rendered":"WP_CLI\\Utils\\make_temp_dir()"},"content":{"rendered":"<p>Create a unique temporary directory safely without following symlinks.<\/p>\n<hr>\n<h2>Usage<\/h2>\n<pre><code>WP_CLI\\Utils\\make_temp_dir( $prefix = wp-cli- )\n<\/code><\/pre>\n<div>\n<strong>$prefix<\/strong> (string) Optional. Prefix for the temporary directory name. Default \u2018<span tabindex='0' class='glossary-item-container'>wp-cli<span class='glossary-item-hidden-content'><span class='glossary-item-header'>WP-CLI<\/span> <span class='glossary-item-description'>WP-CLI is the Command Line Interface for WordPress, used to do administrative and development tasks in a programmatic way. The project page is <a href=\"http:\/\/wp-cli.org\/\">http:\/\/wp-cli.org\/<\/a> <a href=\"https:\/\/make.wordpress.org\/cli\/\">https:\/\/make.wordpress.org\/cli\/<\/a><\/span><\/span><\/span>-\u2018.<br>\n<strong>@return<\/strong> (string) to the created temporary directory with a trailing slash.\n<\/div>\n<hr>\n<h2>Notes<\/h2>\n<p>The directory is only accessible by its owner on non-Windows systems.<\/p>\n<p>The directory is created in the directory returned by WP-CLI\u2019s <code>get_temp_dir()<\/code><br>\n(based on <code>sys_get_temp_dir()<\/code>), not WordPress\u2019s <code>get_temp_dir()<\/code>, and is<br>\nnot removed automatically; callers are responsible for cleaning it up.<\/p>\n<p>On failure, this function exits via <code>WP_CLI::error()<\/code> rather than throwing.<\/p>\n<p><em>Internal <span tabindex='0' class='glossary-item-container'>API<span class='glossary-item-hidden-content'><span class='glossary-item-header'>API<\/span> <span class='glossary-item-description'>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.<\/span><\/span><\/span> documentation is generated from the WP-CLI codebase on every release. To suggest improvements, please submit a pull request.<\/em><\/p>\n<hr>\n<h2>Related<\/h2>\n<ul>\n<li><strong><a href=\"https:\/\/make.wordpress.org\/cli\/handbook\/internal-api\/wp-cli-utils-get-home-dir\/\">WP_CLI\\Utils\\get_home_dir()<\/a><\/strong> \u2013 Get the home directory.<\/li>\n<li><strong><a href=\"https:\/\/make.wordpress.org\/cli\/handbook\/internal-api\/wp-cli-utils-trailingslashit\/\">WP_CLI\\Utils\\trailingslashit()<\/a><\/strong> \u2013 Appends a trailing slash.<\/li>\n<li><strong><a href=\"https:\/\/make.wordpress.org\/cli\/handbook\/internal-api\/wp-cli-utils-is-stream\/\">WP_CLI\\Utils\\is_stream()<\/a><\/strong> \u2013 Check if a path is a <span tabindex='0' class='glossary-item-container'>PHP<span class='glossary-item-hidden-content'><span class='glossary-item-header'>PHP<\/span> <span class='glossary-item-description'>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. <a href=\"https:\/\/www.php.net\/manual\/en\/index.php\">https:\/\/www.php.net\/manual\/en\/index.php<\/a><\/span><\/span><\/span> stream <span tabindex='0' class='glossary-item-container'>URL<span class='glossary-item-hidden-content'><span class='glossary-item-header'>URL<\/span> <span class='glossary-item-description'>A specific web address of a website or web page on the Internet, such as a website\u2019s URL www.wordpress.org<\/span><\/span><\/span>.<\/li>\n<li><strong><a href=\"https:\/\/make.wordpress.org\/cli\/handbook\/internal-api\/wp-cli-utils-normalize-path\/\">WP_CLI\\Utils\\normalize_path()<\/a><\/strong> \u2013 Normalize a filesystem path.<\/li>\n<li><strong><a href=\"https:\/\/make.wordpress.org\/cli\/handbook\/internal-api\/wp-cli-utils-get-temp-dir\/\">WP_CLI\\Utils\\get_temp_dir()<\/a><\/strong> \u2013 Get the system\u2019s temp directory. Warns user if it isn\u2019t writable.<\/li>\n<li><strong><a href=\"https:\/\/make.wordpress.org\/cli\/handbook\/internal-api\/wp-cli-utils-make-temp-file\/\">WP_CLI\\Utils\\make_temp_file()<\/a><\/strong> \u2013 Create a unique temporary file safely without following symlinks.<\/li>\n<li><strong><a href=\"https:\/\/make.wordpress.org\/cli\/handbook\/internal-api\/wp-cli-utils-get-php-binary\/\">WP_CLI\\Utils\\get_php_binary()<\/a><\/strong> \u2013 Get the path to the PHP binary used when executing WP-CLI.<\/li>\n<li><strong><a href=\"https:\/\/make.wordpress.org\/cli\/handbook\/internal-api\/wp-cli-get-php-binary\/\">WP_CLI::get_php_binary()<\/a><\/strong> \u2013 Get the path to the PHP binary used when executing WP-CLI.<\/li>\n<\/ul>\n<nav class='o2-post-footer-actions'><ul class='o2-post-footer-action-row'><\/ul><div class='o2-post-footer-action-likes'><\/div><ul class='o2-post-footer-action-row'><\/ul><\/nav>","protected":false},"author":0,"featured_media":0,"parent":18132,"menu_order":0,"template":"","meta":{"footnotes":""},"class_list":["post-18587","handbook","type-handbook","status-publish","hentry","make-wp-cli-utils-make-temp-dir"],"revision_note":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/make.wordpress.org\/cli\/wp-json\/wp\/v2\/handbook\/18587","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/make.wordpress.org\/cli\/wp-json\/wp\/v2\/handbook"}],"about":[{"href":"https:\/\/make.wordpress.org\/cli\/wp-json\/wp\/v2\/types\/handbook"}],"version-history":[{"count":1,"href":"https:\/\/make.wordpress.org\/cli\/wp-json\/wp\/v2\/handbook\/18587\/revisions"}],"predecessor-version":[{"id":18590,"href":"https:\/\/make.wordpress.org\/cli\/wp-json\/wp\/v2\/handbook\/18587\/revisions\/18590"}],"up":[{"embeddable":true,"href":"https:\/\/make.wordpress.org\/cli\/wp-json\/wp\/v2\/handbook\/18132"}],"wp:attachment":[{"href":"https:\/\/make.wordpress.org\/cli\/wp-json\/wp\/v2\/media?parent=18587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}