PluginProbe
The WP Remote WordPress Plugin / trunk
The WP Remote WordPress Plugin vtrunk
6.72 6.69 6.65 6.62 6.48 6.47 4.87 4.97 5.05 5.09 5.16 5.22 5.24 5.25 5.38 5.41 5.42 5.45 5.47 5.53 5.56 5.65 5.68 5.72 5.73 All 53 releases
wpremote / wp_file_system.php

wp_file_system.php in The WP Remote WordPress Plugin trunk, at wp_file_system.php

93 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) exit;
4
5 if (!class_exists('WPRWPFileSystem')) :
6 class WPRWPFileSystem {
7 private static $instance = null;
8 private $filesystem = null;
9
10 const RESOURCE_TYPE_FILE = 'f';
11
12 private function __construct() {
13 $this->initFilesystem();
14 }
15
16 private function initFilesystem() {
17 if ($this->filesystem === null) {
18 require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
19 require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
20 $this->filesystem = new WP_Filesystem_Direct(null);
21 }
22 }
23
24 public static function getInstance() {
25 if (self::$instance === null) {
26 self::$instance = new self();
27 }
28 return self::$instance;
29 }
30
31 public function putContents($file, $contents, $perm = 0644) {
32 return $this->filesystem->put_contents($file, $contents, $perm);
33 }
34
35 public function getContents($file) {
36 return $this->filesystem->get_contents($file);
37 }
38
39 public function removeFile($path) {
40 return $this->filesystem->delete($path, false, self::RESOURCE_TYPE_FILE);
41 }
42
43 public function rmdir($path, $recursive = false) {
44 return $this->filesystem->delete($path, $recursive);
45 }
46
47 public function isWritable($path) {
48 return $this->filesystem->is_writable($path);
49 }
50
51 public function isDir($path) {
52 return $this->filesystem->is_dir($path);
53 }
54
55 public function exists($path) {
56 return $this->filesystem->exists($path);
57 }
58
59 public function move($source, $destination, $overwrite = false) {
60 return $this->filesystem->move($source, $destination, $overwrite);
61 }
62
63 public function getchmodOctal($path) {
64 return intval($this->getchmod($path), 8);
65 }
66
67 public function getchmod($path) {
68 return $this->filesystem->getchmod($path);
69 }
70
71 public function size($file) {
72 return $this->filesystem->size($file);
73 }
74
75 public function chmod($file, $mode = false, $recursive = false) {
76 return $this->filesystem->chmod($file, $mode, $recursive);
77 }
78
79 public function isReadable($file) {
80 return $this->filesystem->is_readable($file);
81 }
82
83 public function checkForErrors() {
84 if ($this->filesystem !== null && is_wp_error($this->filesystem->errors)) {
85 $wp_error = $this->filesystem->errors;
86 if (!empty($wp_error->errors)) {
87 return $wp_error->get_error_message();
88 }
89 }
90 return null;
91 }
92 }
93 endif;