[Solved] wp_temp_dir does not change the /tmp temporary default directory


sys_get_temp_dir is not a WordPress function, it’s a core PHP function. It cannot be modified or changed using WordPress constants. To modify this would require changes to the servers operating system by the root user.

Instead, WP_TEMP_DIR can be used to influence the value of get_temp_dir which is a WordPress function.

In the event that this function does not find a writable location, It may be overridden by the WP_TEMP_DIR constant in your wp-config.php file.

https://developer.wordpress.org/reference/functions/get_temp_dir/

WP_TEMP_DIR gives you the opportunity to set up a temporary folder WordPress can use if it cannot find a system folder to do it. Perhaps because you are on a server that has been misconfigured, or perhaps systemd has been configured with PrivateTmp=true preventing /tmp from being used.

get_temp_dir is used when generating files for download, or for setting constants for 3rd party libraries.

I’m not sure what the problem is that you hoped to solve by changing the returned value of sys_get_temp_dir, but WP_TEMP_DIR is not the solution you hoped it to be, and does not do what you thought it did. You should create a question asking how to solve your original problem.

3

solved wp_temp_dir does not change the /tmp temporary default directory