@@ -154,6 +154,13 @@ public function register_stream_wrapper() {
154
154
stream_context_set_option ( stream_context_get_default (), 's3 ' , 'seekable ' , true );
155
155
}
156
156
157
+ /**
158
+ * Get the s3:// path for the bucket.
159
+ */
160
+ public function get_s3_path () {
161
+ return 's3:// ' . $ this ->bucket ;
162
+ }
163
+
157
164
/**
158
165
* Overwrite the default wp_upload_dir.
159
166
*
@@ -163,19 +170,20 @@ public function register_stream_wrapper() {
163
170
public function filter_upload_dir ( array $ dirs ) : array {
164
171
165
172
$ this ->original_upload_dir = $ dirs ;
173
+ $ s3_path = $ this ->get_s3_path ();
166
174
167
- $ dirs ['path ' ] = str_replace ( WP_CONTENT_DIR , ' s3:// ' . $ this -> bucket , $ dirs ['path ' ] );
168
- $ dirs ['basedir ' ] = str_replace ( WP_CONTENT_DIR , ' s3:// ' . $ this -> bucket , $ dirs ['basedir ' ] );
175
+ $ dirs ['path ' ] = str_replace ( WP_CONTENT_DIR , $ s3_path , $ dirs ['path ' ] );
176
+ $ dirs ['basedir ' ] = str_replace ( WP_CONTENT_DIR , $ s3_path , $ dirs ['basedir ' ] );
169
177
170
178
if ( ! defined ( 'S3_UPLOADS_DISABLE_REPLACE_UPLOAD_URL ' ) || ! S3_UPLOADS_DISABLE_REPLACE_UPLOAD_URL ) {
171
179
172
180
if ( defined ( 'S3_UPLOADS_USE_LOCAL ' ) && S3_UPLOADS_USE_LOCAL ) {
173
- $ dirs ['url ' ] = str_replace ( ' s3:// ' . $ this -> bucket , $ dirs ['baseurl ' ] . '/s3/ ' . $ this ->bucket , $ dirs ['path ' ] );
174
- $ dirs ['baseurl ' ] = str_replace ( ' s3:// ' . $ this -> bucket , $ dirs ['baseurl ' ] . '/s3/ ' . $ this ->bucket , $ dirs ['basedir ' ] );
181
+ $ dirs ['url ' ] = str_replace ( $ s3_path , $ dirs ['baseurl ' ] . '/s3/ ' . $ this ->bucket , $ dirs ['path ' ] );
182
+ $ dirs ['baseurl ' ] = str_replace ( $ s3_path , $ dirs ['baseurl ' ] . '/s3/ ' . $ this ->bucket , $ dirs ['basedir ' ] );
175
183
176
184
} else {
177
- $ dirs ['url ' ] = str_replace ( ' s3:// ' . $ this -> bucket , $ this ->get_s3_url (), $ dirs ['path ' ] );
178
- $ dirs ['baseurl ' ] = str_replace ( ' s3:// ' . $ this -> bucket , $ this ->get_s3_url (), $ dirs ['basedir ' ] );
185
+ $ dirs ['url ' ] = str_replace ( $ s3_path , $ this ->get_s3_url (), $ dirs ['path ' ] );
186
+ $ dirs ['baseurl ' ] = str_replace ( $ s3_path , $ this ->get_s3_url (), $ dirs ['basedir ' ] );
179
187
}
180
188
}
181
189
0 commit comments