Skip to content

Commit

Permalink
Use new class methods from WP Offload Media (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
Screenfeed authored and remyperona committed Oct 17, 2018
1 parent cc3eba7 commit 28a2a0b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,16 @@ public function is_s3_setup() {
*/
public function get_s3_info() {
global $as3cf;
return $as3cf ? $as3cf->get_attachment_s3_info( $this->id ) : false;

if ( ! $as3cf ) {
return false;
}

if ( method_exists( $as3cf, 'get_attachment_s3_info' ) ) {
return $as3cf->get_attachment_s3_info( $this->id );
}

return $as3cf->get_attachment_provider_info( $this->id );
}

/**
Expand Down Expand Up @@ -823,7 +832,11 @@ protected function get_file_from_s3( $file_path ) {
$s3_object['key'] = $directory . $this->filesystem->file_name( $file_path );

// Retrieve file from S3.
$as3cf->plugin_compat->copy_s3_file_to_server( $s3_object, $file_path );
if ( method_exists( $as3cf->plugin_compat, 'copy_s3_file_to_server' ) ) {
$as3cf->plugin_compat->copy_s3_file_to_server( $s3_object, $file_path );
} else {
$as3cf->plugin_compat->copy_provider_file_to_server( $s3_object, $file_path );
}

return $this->filesystem->exists( $file_path ) ? $file_path : false;
}
Expand Down Expand Up @@ -859,7 +872,11 @@ protected function maybe_send_attachment_to_s3( $metadata = null, $attachment_pa
return false;
}

$s3_data = $as3cf->upload_attachment_to_s3( $this->id, $metadata, $attachment_path, false, $remove_local_files );
if ( method_exists( $as3cf, 'upload_attachment_to_s3' ) ) {
$s3_data = $as3cf->upload_attachment_to_s3( $this->id, $metadata, $attachment_path, false, $remove_local_files );
} else {
$s3_data = $as3cf->upload_attachment( $this->id, $metadata, $attachment_path, false, $remove_local_files );
}

return ! is_wp_error( $s3_data );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,11 @@ public function maybe_copy_files_from_s3( $ids, $results, $optimization_level )
$s3_object['key'] = $directory . $this->filesystem->file_name( $file_path );

// Retrieve file from S3.
$as3cf->plugin_compat->copy_s3_file_to_server( $s3_object, $file_path );
if ( method_exists( $as3cf->plugin_compat, 'copy_s3_file_to_server' ) ) {
$as3cf->plugin_compat->copy_s3_file_to_server( $s3_object, $file_path );
} else {
$as3cf->plugin_compat->copy_provider_file_to_server( $s3_object, $file_path );
}

unset( $s3_data[ $id ], $ids[ $id ] );
}
Expand Down

0 comments on commit 28a2a0b

Please sign in to comment.