Automattic\WooCommerce\Internal\Utilities
FilesystemUtil::mkdir_p_not_indexable
Recursively creates a directory (if it doesn't exist) and adds an empty index.html and a .htaccess to prevent directory listing.
Метод класса: FilesystemUtil{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$result = FilesystemUtil::mkdir_p_not_indexable( $path, $allow_file_access ): void;
- $path(строка) (обязательный)
- Directory to create.
- $allow_file_access(true|false)
- Whether to allow file access while preventing directory listing.
По умолчанию:false (deny all access)
Список изменений
| С версии 9.3.0 | Введена. |
Код FilesystemUtil::mkdir_p_not_indexable() FilesystemUtil::mkdir p not indexable WC 10.8.1
public static function mkdir_p_not_indexable( string $path, bool $allow_file_access = false ): void {
$wp_fs = self::get_wp_filesystem();
if ( $wp_fs->is_dir( $path ) ) {
return;
}
if ( ! wp_mkdir_p( $path ) ) {
throw new \Exception( esc_html( sprintf( 'Could not create directory: %s.', wp_basename( $path ) ) ) );
}
$htaccess_content = $allow_file_access ? 'Options -Indexes' : 'deny from all';
$files = array(
'.htaccess' => $htaccess_content,
'index.html' => '',
);
foreach ( $files as $name => $content ) {
$wp_fs->put_contents( trailingslashit( $path ) . $name, $content );
}
}