Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/wp-includes/embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,14 @@ function get_oembed_response_data_for_url( $url, $args ) {

if ( $path ) {
$qv['path'] = get_network()->path . $path . '/';
/*
* In a subdirectory configuration of multisite, the `/blog` prefix is used by
* default on the main site to avoid URL collisions. Remove it to correctly
* identify the main site.
*/
if ( str_starts_with( $qv['path'], '/blog/' ) ) {
$qv['path'] = preg_replace( '|^/blog|', '', $qv['path'] );
}
}
}

Expand Down
33 changes: 33 additions & 0 deletions tests/phpunit/tests/oembed/wpOembed.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,37 @@ public function test_wp_filter_pre_oembed_result_multisite_restores_state_if_no_
$this->assertFalse( $actual );
$this->assertSame( $current_blog_id, get_current_blog_id() );
}

/**
* @ticket 45052
* @group multisite
* @group ms-required
*
* @covers ::get_html
*/
public function test_wp_filter_pre_oembed_result_multisite_sub_main_pretty_permalink() {
$this->set_permalink_structure( '/blog/%postname%/' );

$post_id = self::factory()->post->create();
$permalink = get_permalink( $post_id );
$user_id = self::$user_id;
$blog_id = self::factory()->blog->create(
array(
'user_id' => $user_id,
)
);

switch_to_blog( $blog_id );

$this->set_permalink_structure( '/%postname%/' );

add_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );
$actual = $this->oembed->get_html( $permalink );
remove_filter( 'pre_oembed_result', array( $this, '_filter_pre_oembed_result' ) );

restore_current_blog();

$this->assertNotNull( $this->pre_oembed_result_filtered );
$this->assertEquals( $this->pre_oembed_result_filtered, $actual );
}
}
Loading