WP_Automatic_Updater::is_allowed_dir( string $dir )

Checks whether access to a given directory is allowed.


Description

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.


Parameters

$dir

(Required) The directory to check.


Return

(bool) True if access to the directory is allowed, false otherwise.


Source

File: wp-admin/includes/class-wp-automatic-updater.php

	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;
	}

Changelog

Changelog
Version Description
6.2.0 Introduced.