Skip to content

Commit 362d27f

Browse files
committed
Merge branch 'release/1.1.0'
2 parents d7515b7 + 55614e5 commit 362d27f

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4-
## [next]
4+
## 1.1.0 - 29.01.2020
55

6-
Fixed:
7-
* Invalid method name causing warning
6+
### Added:
7+
* mkdir support for recursive dir creation when using Direct method.
8+
9+
### Fixed:
10+
* Invalid method name causing warning.
811

912
## 1.0.0 - 28.01.2020
1013

src/Filesystem.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class Filesystem {
5858
'mtime',
5959
'size',
6060
'touch',
61-
'mkdir',
6261
'rmdir',
6362
'dirlist',
6463
];
@@ -116,6 +115,59 @@ public function __call( $method_name, $arguments ) {
116115

117116
}
118117

118+
/**
119+
* Creates a directory.
120+
*
121+
* @throws \Exception If recursive parameter used width filesystem method other than direct.
122+
* @since 1.1.0
123+
*
124+
* @param string $path Path for new directory.
125+
* @param int|false $chmod Optional. The permissions as octal number (or false to skip chmod).
126+
* Default false.
127+
* @param string|int $chown Optional. A user name or number (or false to skip chown).
128+
* Default false.
129+
* @param string|int $chgrp Optional. A group name or number (or false to skip chgrp).
130+
* Default false.
131+
* @param bool $recursive Whether to act recursively.
132+
* @return bool True on success, false on failure.
133+
*/
134+
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false, $recursive = false ) {
135+
136+
if ( ! $this->wp_filesystem instanceof \WP_Filesystem_Direct ) {
137+
if ( $recursive ) {
138+
throw new \Exception( 'Current filesystem method does not support recursive directory creation.' );
139+
}
140+
141+
$this->wp_filesystem->mkdir( $path, $chmod, $chown, $chgrp );
142+
}
143+
144+
// Safe mode fails with a trailing slash under certain PHP versions.
145+
$path = untrailingslashit( $path );
146+
if ( empty( $path ) ) {
147+
return false;
148+
}
149+
150+
if ( ! $chmod ) {
151+
$chmod = FS_CHMOD_DIR;
152+
}
153+
154+
// phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
155+
if ( ! @mkdir( $this->path( $path ), $chmod, true ) ) {
156+
return false;
157+
}
158+
159+
if ( $chown ) {
160+
$this->chown( $path, $chown );
161+
}
162+
163+
if ( $chgrp ) {
164+
$this->chgrp( $path, $chgrp );
165+
}
166+
167+
return true;
168+
169+
}
170+
119171
/**
120172
* Changes the path to URL
121173
*

0 commit comments

Comments
 (0)