WordPress at a glance

get_temp_dir() WP 1.0

Determine a writable directory for temporary files.

Function's preference is the return value of sys_get_temp_dir(), followed by your PHP temporary upload directory, followed by WP_CONTENT_DIR, before finally defaulting to /tmp/

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.

  • Static. String. $temp
✈ 1 time = 0.00001s = speed of light | 50000 times = 0.03s = speed of light | PHP 7.1.11, WP 4.9.5

No Hooks.

Return

String. Writable temporary directory.

Usage

get_temp_dir();

Code of get temp dir: wp-includes/functions.php WP 5.2.2

<?php
function get_temp_dir() {
	static $temp = '';
	if ( defined( 'WP_TEMP_DIR' ) ) {
		return trailingslashit( WP_TEMP_DIR );
	}

	if ( $temp ) {
		return trailingslashit( $temp );
	}

	if ( function_exists( 'sys_get_temp_dir' ) ) {
		$temp = sys_get_temp_dir();
		if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) {
			return trailingslashit( $temp );
		}
	}

	$temp = ini_get( 'upload_tmp_dir' );
	if ( @is_dir( $temp ) && wp_is_writable( $temp ) ) {
		return trailingslashit( $temp );
	}

	$temp = WP_CONTENT_DIR . '/';
	if ( is_dir( $temp ) && wp_is_writable( $temp ) ) {
		return $temp;
	}

	return '/tmp/';
}

Related Functions

From tag: path (directory folder)

More from category: Helper Functions

No comments
    Hello, !     Log In . Register