Loading inc/class-s3-uploads.php +19 −0 Original line number Diff line number Diff line Loading @@ -87,4 +87,23 @@ class S3_Uploads { return $editors; } /** * Copy the file from /tmp to an s3 dir so handle_sideload doesn't fail due to * trying to do a rename() on the file cross streams. This is somewhat of a hack * to work around the core issue https://core.trac.wordpress.org/ticket/29257 * * @param array File array * @return array */ public function filter_sideload_move_temp_file_to_s3( array $file ) { $upload_dir = wp_upload_dir(); $new_path = $upload_dir['basedir'] . '/tmp/' . basename( $file['tmp_name'] ); copy( $file['tmp_name'], $new_path ); unlink( $file['tmp_name'] ); $file['tmp_name'] = $new_path; return $file; } } No newline at end of file s3-uploads.php +2 −0 Original line number Diff line number Diff line Loading @@ -25,4 +25,6 @@ add_action( 'plugins_loaded', function() { add_filter( 'upload_dir', array( $instance, 'filter_upload_dir' ) ); add_filter( 'wp_image_editors', array( $instance, 'filter_editors' ), 9 ); remove_filter( 'admin_notices', 'wpthumb_errors' ); add_action( 'wp_handle_sideload_prefilter', array( $instance, 'filter_sideload_move_temp_file_to_s3' ) ); }); Loading
inc/class-s3-uploads.php +19 −0 Original line number Diff line number Diff line Loading @@ -87,4 +87,23 @@ class S3_Uploads { return $editors; } /** * Copy the file from /tmp to an s3 dir so handle_sideload doesn't fail due to * trying to do a rename() on the file cross streams. This is somewhat of a hack * to work around the core issue https://core.trac.wordpress.org/ticket/29257 * * @param array File array * @return array */ public function filter_sideload_move_temp_file_to_s3( array $file ) { $upload_dir = wp_upload_dir(); $new_path = $upload_dir['basedir'] . '/tmp/' . basename( $file['tmp_name'] ); copy( $file['tmp_name'], $new_path ); unlink( $file['tmp_name'] ); $file['tmp_name'] = $new_path; return $file; } } No newline at end of file
s3-uploads.php +2 −0 Original line number Diff line number Diff line Loading @@ -25,4 +25,6 @@ add_action( 'plugins_loaded', function() { add_filter( 'upload_dir', array( $instance, 'filter_upload_dir' ) ); add_filter( 'wp_image_editors', array( $instance, 'filter_editors' ), 9 ); remove_filter( 'admin_notices', 'wpthumb_errors' ); add_action( 'wp_handle_sideload_prefilter', array( $instance, 'filter_sideload_move_temp_file_to_s3' ) ); });