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
$dirstringrequired- The directory to check.
Source
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
| Version | Description |
|---|---|
| 6.2.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.