diff --git src/wp-includes/rewrite.php src/wp-includes/rewrite.php
index 705e5f2bc8..1a1f31847a 100644
|
|
function url_to_postid( $url ) { |
471 | 471 | */ |
472 | 472 | $url = apply_filters( 'url_to_postid', $url ); |
473 | 473 | |
| 474 | // Bail early when URL doesn't belong to this site. |
| 475 | $host = parse_url( home_url(), PHP_URL_HOST ); |
| 476 | if ( false === strpos( $url, $host ) ) { |
| 477 | //return 0; |
| 478 | } |
| 479 | |
474 | 480 | // First, check to see if there is a 'p=N' or 'page_id=N' to match against |
475 | 481 | if ( preg_match('#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values) ) { |
476 | 482 | $id = absint($values[2]); |
diff --git tests/phpunit/tests/rewrite.php tests/phpunit/tests/rewrite.php
index 5f7514915e..014a6c1e76 100644
|
|
class Tests_Rewrite extends WP_UnitTestCase { |
389 | 389 | $this->assertInternalType( 'array', $rewrite_rules ); |
390 | 390 | $this->assertNotEmpty( $rewrite_rules ); |
391 | 391 | } |
| 392 | |
| 393 | /** |
| 394 | * @ticket 39373 |
| 395 | */ |
| 396 | public function test_url_to_postid_should_bail_when_host_does_not_match() { |
| 397 | $this->set_permalink_structure( '/%postname%/' ); |
| 398 | |
| 399 | $post_id = self::factory()->post->create( array( 'post_name' => 'foo-bar-baz' ) ); |
| 400 | $permalink = get_permalink( $post_id ); |
| 401 | $url = str_replace( home_url(), 'http://some-other-domain.com/', get_permalink( $post_id ) ); |
| 402 | |
| 403 | $this->assertSame( $post_id, url_to_postid( $permalink ) ); |
| 404 | $this->assertSame( 0, url_to_postid( $url ) ); |
| 405 | } |
392 | 406 | } |