@@ -26,7 +26,7 @@ class Filesystem {
26
26
*
27
27
* @var WP_Filesystem_*
28
28
*/
29
- protected $ wp_filesystem ;
29
+ protected static $ wp_filesystem ;
30
30
31
31
/**
32
32
* WP_Filesystem's methods
@@ -72,7 +72,7 @@ public function __construct( $base_dir ) {
72
72
73
73
$ this ->base_dir = trailingslashit ( wp_normalize_path ( $ base_dir ) );
74
74
75
- $ this -> init_wp_filesystem ();
75
+ self :: init_wp_filesystem ();
76
76
77
77
}
78
78
@@ -82,14 +82,18 @@ public function __construct( $base_dir ) {
82
82
* @since 1.0.0
83
83
* @return void
84
84
*/
85
- private function init_wp_filesystem () {
85
+ private static function init_wp_filesystem () {
86
+
87
+ if ( self ::$ wp_filesystem ) {
88
+ return ;
89
+ }
86
90
87
91
global $ wp_filesystem ;
88
92
89
93
require_once ABSPATH . '/wp-admin/includes/file.php ' ;
90
94
WP_Filesystem ();
91
95
92
- $ this -> wp_filesystem = $ wp_filesystem ;
96
+ self :: $ wp_filesystem = $ wp_filesystem ;
93
97
94
98
}
95
99
@@ -111,7 +115,7 @@ public function __call( $method_name, $arguments ) {
111
115
$ arguments [0 ] = $ this ->path ( $ arguments [0 ] );
112
116
}
113
117
114
- return call_user_func_array ( [ $ this -> wp_filesystem , $ method_name ], $ arguments );
118
+ return call_user_func_array ( [ self :: $ wp_filesystem , $ method_name ], $ arguments );
115
119
116
120
}
117
121
@@ -133,12 +137,12 @@ public function __call( $method_name, $arguments ) {
133
137
*/
134
138
public function mkdir ( $ path , $ chmod = false , $ chown = false , $ chgrp = false , $ recursive = false ) {
135
139
136
- if ( ! $ this -> wp_filesystem instanceof \WP_Filesystem_Direct ) {
140
+ if ( ! self :: $ wp_filesystem instanceof \WP_Filesystem_Direct ) {
137
141
if ( $ recursive ) {
138
142
throw new \Exception ( 'Current filesystem method does not support recursive directory creation. ' );
139
143
}
140
144
141
- $ this -> wp_filesystem ->mkdir ( $ path , $ chmod , $ chown , $ chgrp );
145
+ self :: $ wp_filesystem ->mkdir ( $ path , $ chmod , $ chown , $ chgrp );
142
146
}
143
147
144
148
// Safe mode fails with a trailing slash under certain PHP versions.
0 commit comments