/**
  * The function `wp_mkdir_p` will create directories recursively
  *
  * @param string $absolute_path
  *
  * @return string|bool absolute path or false if we can't have a writable and readable directory
  */
 private function maybe_create_directory($absolute_path)
 {
     $result = true;
     if (!$this->filesystem->is_dir($absolute_path)) {
         $result = wp_mkdir_p($absolute_path);
     }
     if (!$this->filesystem->is_writable($absolute_path) || !$this->filesystem->is_readable($absolute_path)) {
         $result = $this->filesystem->chmod($absolute_path, 0755, true);
     }
     return $result ? $absolute_path : false;
 }
Exemple #2
0
 static function MoveDir($from, $to)
 {
     require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
     require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
     $wp_filesystem = new WP_Filesystem_Direct(null);
     $dirlist = $wp_filesystem->dirlist($from);
     $from = trailingslashit($from);
     $to = trailingslashit($to);
     foreach ((array) $dirlist as $filename => $fileinfo) {
         if ('f' == $fileinfo['type']) {
             if (!$wp_filesystem->move($from . $filename, $to . $filename, true)) {
                 return false;
             }
             $wp_filesystem->chmod($to . $filename, octdec(WPFB_PERM_FILE));
         } elseif ('d' == $fileinfo['type']) {
             if (!$wp_filesystem->mkdir($to . $filename, octdec(WPFB_PERM_DIR))) {
                 return false;
             }
             if (!self::MoveDir($from . $filename, $to . $filename)) {
                 return false;
             }
         }
     }
     // finally delete the from dir
     @rmdir($from);
     return true;
 }
 /**
  * Changes filesystem permissions
  *
  * @access public
  *
  * @param string $file      Path to the file.
  * @param int    $mode      Optional. The permissions as octal number, usually 0644 for files,
  *                          0755 for dirs. Default false.
  * @param bool   $recursive Optional. If set True changes file group recursively. Default false.
  * @return bool Returns true on success or false on failure.
  */
 public function chmod($file, $mode = false, $recursive = false)
 {
     if ($this->authorized()) {
         return parent::chmod($file, $mode, $recursive);
     } else {
         return false;
     }
 }