IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/src/wp-includes/default-constants.php b/src/wp-includes/default-constants.php
a
|
b
|
|
154 | 154 | function wp_plugin_directory_constants() { |
155 | 155 | if ( ! defined( 'WP_CONTENT_URL' ) ) { |
156 | 156 | define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' ); // Full URL - WP_CONTENT_DIR is defined further up. |
| 157 | define( 'WP_DYNAMIC_CONTENT_URL', true ); // Flag to differentiate if WP_CONTENT_URL was explicitly set in wp-config.php or not |
157 | 158 | } |
158 | 159 | |
159 | 160 | /** |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
a
|
b
|
|
2388 | 2388 | } else { |
2389 | 2389 | $dir = $upload_path; |
2390 | 2390 | } |
2391 | | |
2392 | 2391 | $url = get_option( 'upload_url_path' ); |
2393 | 2392 | if ( ! $url ) { |
2394 | 2393 | if ( empty( $upload_path ) || ( 'wp-content/uploads' === $upload_path ) || ( $upload_path == $dir ) ) { |
2395 | | $url = WP_CONTENT_URL . '/uploads'; |
| 2394 | $url = content_url() . '/uploads'; |
2396 | 2395 | } else { |
2397 | 2396 | $url = trailingslashit( $siteurl ) . $upload_path; |
2398 | 2397 | } |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php
a
|
b
|
|
3487 | 3487 | * @return string Content URL link with optional path appended. |
3488 | 3488 | */ |
3489 | 3489 | function content_url( $path = '' ) { |
3490 | | $url = set_url_scheme( WP_CONTENT_URL ); |
| 3490 | if ( ms_is_switched() && defined( 'WP_DYNAMIC_CONTENT_URL' ) && WP_DYNAMIC_CONTENT_URL ) { |
| 3491 | $url = get_option( 'siteurl' ) . '/wp-content'; |
| 3492 | } else { |
| 3493 | $url = WP_CONTENT_URL; |
| 3494 | } |
| 3495 | $url = set_url_scheme( $url ); |
3491 | 3496 | |
3492 | 3497 | if ( $path && is_string( $path ) ) { |
3493 | 3498 | $url .= '/' . ltrim( $path, '/' ); |
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php
a
|
b
|
|
834 | 834 | restore_current_blog(); |
835 | 835 | } |
836 | 836 | |
837 | | public function test_switch_upload_dir() { |
| 837 | /** |
| 838 | * Test wp_upload_dir() output when WP_UPLOAD_URL is explicitly defined in wp-config.php |
| 839 | */ |
| 840 | public function test_defined_wp_content_url() { |
| 841 | /* |
| 842 | * Global constants can't be mocked in PHPUnit, so this can only run with the expected |
| 843 | * values already set in `wp-tests-config.php`. Unfortunately, that means it won't run in |
| 844 | * automated workflows, but it's still useful when testing locally. |
| 845 | * |
| 846 | * It may be possible to enable automated workflows by mocking `define()`, or by setting up |
| 847 | * addition automated flows that initialize the tests with different values for the constants. |
| 848 | * At the moment, though, neither of those seem to provide enough benefit to justify the time |
| 849 | * investment. |
| 850 | * |
| 851 | * @link https://theaveragedev.com/mocking-constants-in-tests/ |
| 852 | */ |
| 853 | if ( defined( 'WP_DYNAMIC_CONTENT_URL' ) && WP_DYNAMIC_CONTENT_URL ) { |
| 854 | $this->markTestSkipped( 'Test requires setting `WP_CONTENT_URL` constant explicitly in `wp-tests-config.php` to expected values.' ); |
| 855 | } |
| 856 | |
838 | 857 | $this->assertTrue( is_main_site() ); |
839 | 858 | |
840 | | $site = get_current_site(); |
841 | 859 | $date = date_format( date_create( 'now' ), 'Y/m' ); |
842 | 860 | |
843 | 861 | $info = wp_upload_dir(); |
844 | | $this->assertSame( 'http://' . $site->domain . '/wp-content/uploads/' . $date, $info['url'] ); |
| 862 | $this->assertSame( WP_CONTENT_URL . '/uploads/' . $date, $info['url'] ); |
845 | 863 | $this->assertSame( ABSPATH . 'wp-content/uploads/' . $date, $info['path'] ); |
846 | 864 | $this->assertSame( '/' . $date, $info['subdir'] ); |
847 | 865 | $this->assertFalse( $info['error'] ); |
848 | 866 | |
| 867 | $date = date_format( date_create( 'now' ), 'Y/m' ); |
| 868 | $this->assertFalse( defined( 'WP_DYNAMIC_CONTENT_URL' ) ); |
| 869 | |
849 | 870 | $blog_id = self::factory()->blog->create(); |
850 | 871 | |
851 | 872 | switch_to_blog( $blog_id ); |
852 | 873 | $info = wp_upload_dir(); |
853 | | $this->assertSame( 'http://' . $site->domain . '/wp-content/uploads/sites/' . get_current_blog_id() . '/' . $date, $info['url'] ); |
| 874 | $this->assertSame( WP_CONTENT_URL . '/uploads/sites/' . get_current_blog_id() . '/' . $date, $info['url'] ); |
854 | 875 | $this->assertSame( ABSPATH . 'wp-content/uploads/sites/' . get_current_blog_id() . '/' . $date, $info['path'] ); |
855 | 876 | $this->assertSame( '/' . $date, $info['subdir'] ); |
856 | 877 | $this->assertFalse( $info['error'] ); |
857 | 878 | restore_current_blog(); |
858 | 879 | |
| 880 | } |
| 881 | |
| 882 | /** |
| 883 | * Test wp_upload_dir() output when WP_UPLOAD_URL is defined dynamically in default-constants.php |
| 884 | */ |
| 885 | public function test_dynamic_wp_content_url() { |
| 886 | /* |
| 887 | * Global constants can't be mocked in PHPUnit, so this can only run with the expected |
| 888 | * values already set in `wp-tests-config.php`. Unfortunately, that means it won't run in |
| 889 | * automated workflows, but it's still useful when testing locally. |
| 890 | * |
| 891 | * It may be possible to enable automated workflows by mocking `define()`, or by setting up |
| 892 | * addition automated flows that initialize the tests with different values for the constants. |
| 893 | * At the moment, though, neither of those seem to provide enough benefit to justify the time |
| 894 | * investment. |
| 895 | * |
| 896 | * @link https://theaveragedev.com/mocking-constants-in-tests/ |
| 897 | */ |
| 898 | if ( ! defined( 'WP_DYNAMIC_CONTENT_URL' ) || ! WP_DYNAMIC_CONTENT_URL ) { |
| 899 | $this->markTestSkipped( 'Test requires not setting `WP_CONTENT_URL` constant explicitly in `wp-tests-config.php`.' ); |
| 900 | } |
| 901 | |
| 902 | $this->assertTrue( is_main_site() ); |
| 903 | |
| 904 | $site = get_current_site(); |
| 905 | $date = date_format( date_create( 'now' ), 'Y/m' ); |
| 906 | |
859 | 907 | $info = wp_upload_dir(); |
860 | 908 | $this->assertSame( 'http://' . $site->domain . '/wp-content/uploads/' . $date, $info['url'] ); |
861 | 909 | $this->assertSame( ABSPATH . 'wp-content/uploads/' . $date, $info['path'] ); |
862 | 910 | $this->assertSame( '/' . $date, $info['subdir'] ); |
863 | 911 | $this->assertFalse( $info['error'] ); |
| 912 | |
| 913 | $blog_ids = array( |
| 914 | 'subdirectory' => array( |
| 915 | 'domain' => WP_TESTS_DOMAIN, |
| 916 | 'path' => '/foo/', |
| 917 | ), |
| 918 | 'subdomain' => array( |
| 919 | 'domain' => 'foo' . WP_TESTS_DOMAIN, |
| 920 | 'path' => '/', |
| 921 | ), |
| 922 | 'domain' => array( |
| 923 | 'domain' => 'wordpress.org', |
| 924 | 'path' => '/', |
| 925 | ) |
| 926 | ); |
| 927 | |
| 928 | foreach( $blog_ids as $blog_id ) { |
| 929 | $blog_id = self::factory()->blog->create( $blog_id ); |
| 930 | |
| 931 | switch_to_blog( $blog_id ); |
| 932 | $site = get_site( $blog_id ); |
| 933 | $info = wp_upload_dir(); |
| 934 | $this->assertSame( 'http://' . $site->domain . $site->path . 'wp-content/uploads/sites/' . get_current_blog_id() . '/' . $date, $info['url'] ); |
| 935 | $this->assertSame( ABSPATH . 'wp-content/uploads/sites/' . get_current_blog_id() . '/' . $date, $info['path'] ); |
| 936 | $this->assertSame( '/' . $date, $info['subdir'] ); |
| 937 | $this->assertFalse( $info['error'] ); |
| 938 | restore_current_blog(); |
| 939 | } |
864 | 940 | } |
865 | 941 | |
866 | 942 | /** |