@@ -58,7 +58,6 @@ class Filesystem {
58
58
'mtime ' ,
59
59
'size ' ,
60
60
'touch ' ,
61
- 'mkdir ' ,
62
61
'rmdir ' ,
63
62
'dirlist ' ,
64
63
];
@@ -116,6 +115,59 @@ public function __call( $method_name, $arguments ) {
116
115
117
116
}
118
117
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
+
119
171
/**
120
172
* Changes the path to URL
121
173
*
0 commit comments