WP_Automatic_Updater::is_allowed_dir()publicWP 6.2.0

Checks whether access to a given directory is allowed.

This is used when detecting version control checkouts. Takes into account the PHP open_basedir restrictions, so that WordPress does not try to access directories it is not allowed to.

Method of the class: WP_Automatic_Updater{}

No Hooks.

Return

true|false. True if access to the directory is allowed, false otherwise.

Usage

$WP_Automatic_Updater = new WP_Automatic_Updater();
$WP_Automatic_Updater->is_allowed_dir( $dir );
$dir(string) (required)
The directory to check.

Changelog

Since 6.2.0 Introduced.

WP_Automatic_Updater::is_allowed_dir() code WP 6.6.2

public function is_allowed_dir( $dir ) {
	if ( is_string( $dir ) ) {
		$dir = trim( $dir );
	}

	if ( ! is_string( $dir ) || '' === $dir ) {
		_doing_it_wrong(
			__METHOD__,
			sprintf(
				/* translators: %s: The "$dir" argument. */
				__( 'The "%s" argument must be a non-empty string.' ),
				'$dir'
			),
			'6.2.0'
		);

		return false;
	}

	$open_basedir = ini_get( 'open_basedir' );

	if ( empty( $open_basedir ) ) {
		return true;
	}

	$open_basedir_list = explode( PATH_SEPARATOR, $open_basedir );

	foreach ( $open_basedir_list as $basedir ) {
		if ( '' !== trim( $basedir ) && str_starts_with( $dir, $basedir ) ) {
			return true;
		}
	}

	return false;
}