diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
index 1796ddeded..8f04b10e43 100644
a
|
b
|
function get_attached_file( $attachment_id, $unfiltered = false ) { |
321 | 321 | $file = get_post_meta( $attachment_id, '_wp_attached_file', true ); |
322 | 322 | |
323 | 323 | // If the file is relative, prepend upload dir. |
324 | | if ( $file && 0 !== strpos( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) && ( ( $uploads = wp_get_upload_dir() ) && false === $uploads['error'] ) ) { |
325 | | $file = $uploads['basedir'] . "/$file"; |
| 324 | if ( ( $uploads = wp_get_upload_dir() ) && ! preg_match('|://|', $file) && false === $uploads['error'] ) { |
| 325 | $file = path_join($uploads['basedir'], $file); |
326 | 326 | } |
327 | 327 | |
328 | 328 | if ( $unfiltered ) { |
diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php
index c0b20bb2a7..4c49d76fea 100644
a
|
b
|
class Tests_Post extends WP_UnitTestCase { |
1354 | 1354 | $this->assertEquals( $changeset_data, json_decode( get_post( $post_id )->post_content, true ) ); |
1355 | 1355 | } |
1356 | 1356 | |
| 1357 | /** |
| 1358 | * Test Absolute URL path. |
| 1359 | * |
| 1360 | * @ticket 24824 |
| 1361 | */ |
| 1362 | public function test_get_attached_file() { |
| 1363 | |
| 1364 | $post = self::factory()->post->create_and_get( |
| 1365 | array( |
| 1366 | 'post_title' => 'example-page', |
| 1367 | 'post_type' => 'post', |
| 1368 | ) |
| 1369 | ); |
| 1370 | |
| 1371 | // Absolute URL path. |
| 1372 | $attachment = self::factory()->attachment->create_and_get( |
| 1373 | array( |
| 1374 | 'post_parent' => $post->ID, |
| 1375 | 'file' => 'https://example.com/index.html', |
| 1376 | ) |
| 1377 | ); |
| 1378 | $attachment_path = get_attached_file( $attachment->ID ); |
| 1379 | $this->assertEquals( $attachment_path, 'https://example.com/index.html' ); |
| 1380 | } |
1357 | 1381 | } |