Skip to content

Commit

Permalink
Propagate options from put_contents to close_write_stream
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Jan 2, 2025
1 parent 5840909 commit c0ea73c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/WordPress/ByteReader/WP_File_Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ class WP_File_Reader extends WP_Byte_Reader {

static public function create( $file_path, $chunk_size = 8096 ) {
if(!file_exists($file_path)) {
throw new \Exception(sprintf( 'File %s does not exist', $file_path ));
_doing_it_wrong( __METHOD__, sprintf( 'File %s does not exist', $file_path ), '1.0.0' );
return false;
}
if(!is_file($file_path)) {
throw new \Exception(sprintf( '%s is not a file', $file_path ));
_doing_it_wrong( __METHOD__, sprintf( '%s is not a file', $file_path ), '1.0.0' );
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/WordPress/Filesystem/WP_Abstract_Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function put_contents($path, $data, $options = []) {
_doing_it_wrong(__METHOD__, 'Invalid $data argument provided. Expected a string or a WP_Byte_Reader instance. Received: ' . gettype($data), '1.0.0');
return false;
}
if(!$this->close_write_stream()) {
if(!$this->close_write_stream($options)) {
return false;
}
return true;
Expand Down
3 changes: 3 additions & 0 deletions src/WordPress/Filesystem/WP_Local_Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public function open_read_stream($path) {
}
$fullPath = $this->get_full_path($path);
$this->last_file_reader = \WordPress\ByteReader\WP_File_Reader::create($fullPath);
if(false === $this->last_file_reader) {
return false;
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function open_read_stream($path) {
$file_key = substr($node['content'], 6);
$uploaded_file = $this->request->get_file_params()[$file_key] ?? null;

if (! $uploaded_file || $uploaded_file['error'] !== UPLOAD_ERR_OK) {
if (!$uploaded_file || $uploaded_file['error'] !== UPLOAD_ERR_OK) {
return false;
}

Expand Down

0 comments on commit c0ea73c

Please sign in to comment.