Skip to content

Commit 9075399

Browse files
committed
wp filesystem cache
1 parent c2a50be commit 9075399

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

CHANGELOG.md

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

4+
## [Next] -
5+
6+
### Changed:
7+
- WP Filesystem is not cached scroll all Filesystem instances for better performance.
8+
49
## 1.1.1 - 05.02.2020
510

611
### Fixed:

src/Filesystem.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Filesystem {
2626
*
2727
* @var WP_Filesystem_*
2828
*/
29-
protected $wp_filesystem;
29+
protected static $wp_filesystem;
3030

3131
/**
3232
* WP_Filesystem's methods
@@ -72,7 +72,7 @@ public function __construct( $base_dir ) {
7272

7373
$this->base_dir = trailingslashit( wp_normalize_path( $base_dir ) );
7474

75-
$this->init_wp_filesystem();
75+
self::init_wp_filesystem();
7676

7777
}
7878

@@ -82,14 +82,18 @@ public function __construct( $base_dir ) {
8282
* @since 1.0.0
8383
* @return void
8484
*/
85-
private function init_wp_filesystem() {
85+
private static function init_wp_filesystem() {
86+
87+
if ( self::$wp_filesystem ) {
88+
return;
89+
}
8690

8791
global $wp_filesystem;
8892

8993
require_once ABSPATH . '/wp-admin/includes/file.php';
9094
WP_Filesystem();
9195

92-
$this->wp_filesystem = $wp_filesystem;
96+
self::$wp_filesystem = $wp_filesystem;
9397

9498
}
9599

@@ -111,7 +115,7 @@ public function __call( $method_name, $arguments ) {
111115
$arguments[0] = $this->path( $arguments[0] );
112116
}
113117

114-
return call_user_func_array( [ $this->wp_filesystem, $method_name ], $arguments );
118+
return call_user_func_array( [ self::$wp_filesystem, $method_name ], $arguments );
115119

116120
}
117121

@@ -133,12 +137,12 @@ public function __call( $method_name, $arguments ) {
133137
*/
134138
public function mkdir( $path, $chmod = false, $chown = false, $chgrp = false, $recursive = false ) {
135139

136-
if ( ! $this->wp_filesystem instanceof \WP_Filesystem_Direct ) {
140+
if ( ! self::$wp_filesystem instanceof \WP_Filesystem_Direct ) {
137141
if ( $recursive ) {
138142
throw new \Exception( 'Current filesystem method does not support recursive directory creation.' );
139143
}
140144

141-
$this->wp_filesystem->mkdir( $path, $chmod, $chown, $chgrp );
145+
self::$wp_filesystem->mkdir( $path, $chmod, $chown, $chgrp );
142146
}
143147

144148
// Safe mode fails with a trailing slash under certain PHP versions.

0 commit comments

Comments
 (0)