Ejemplo n.º 1
0
 public static function create_writable_path($args = array())
 {
     if (is_string($args)) {
         $args = array('name' => $args);
     } else {
         if (!is_array($args)) {
             $args = array();
         }
     }
     $default_args = array('name' => 'temp-deleteme', 'private' => true, 'possible_paths' => array(), 'permissions' => 0755, 'rename' => false);
     $args = array_merge($default_args, $args);
     $writable_dir = ITFileUtility::find_writable_path(array('private' => $args['private'], 'possible_paths' => $args['possible_paths'], 'permissions' => $args['permissions']));
     if (is_wp_error($writable_dir)) {
         return $writable_dir;
     }
     $test_dir_name = $args['name'];
     $path = "{$writable_dir}/{$test_dir_name}";
     if (file_exists($path) && false === $args['rename']) {
         if (is_writable($path)) {
             return $path;
         } else {
             return new WP_Error('create_writable_path_failed', 'Requested path exists and cannot be written to');
         }
     }
     $count = 0;
     while (is_dir("{$writable_dir}/{$test_dir_name}")) {
         $count++;
         $test_dir_name = "{$args['name']}-{$count}";
     }
     $path = "{$writable_dir}/{$test_dir_name}";
     if (false === ITFileUtility::mkdir($path, $args['permissions'])) {
         return new WP_Error('create_path_failed', 'Unable to create a writable path');
     }
     if (!is_writable($path)) {
         return new WP_Error('create_writable_path_failed', 'Unable to create a writable path');
     }
     return $path;
 }