コード例 #1
0
 /**
  * ensure_file_exists_and_is_writable
  * ensures that a file exists and is writable, will attempt to create file if it does not exist.
  * Also ensures all the parent folders exist, and if not tries to create them.
  * @param string $full_file_path
  * @throws EE_Error if filesystem credentials are required
  * @return bool
  */
 public static function ensure_file_exists_and_is_writable($full_file_path = '')
 {
     // load WP_Filesystem and set file permissions
     $wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
     $full_file_path = EEH_File::standardise_directory_separators($full_file_path);
     $parent_folder = EEH_File::get_parent_folder($full_file_path);
     if (!EEH_File::exists($full_file_path)) {
         if (!EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
             return false;
         }
         if (!$wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
             if (defined('WP_DEBUG') && WP_DEBUG) {
                 $msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
                 $msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
                 throw new EE_Error($msg);
             }
             return false;
         }
     }
     if (!EEH_File::verify_is_writable($full_file_path, 'file')) {
         return false;
     }
     return true;
 }
コード例 #2
0
 /**
  * @group 9059
  */
 public function test_get_parent_folder__folder()
 {
     $this->assertEquals('/var/something/', EEH_File::get_parent_folder('/var/something/somewhere/'));
 }