diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php
index bece4e7914..951020d387 100644
a
|
b
|
function do_feed_atom( $for_comments ) { |
1582 | 1582 | * Displays the default robots.txt file content. |
1583 | 1583 | * |
1584 | 1584 | * @since 2.1.0 |
| 1585 | * @since 5.3.0 Remove the "Disallow: /" output if search engine visiblity is |
| 1586 | * discouraged in favor of robots meta HTML tag in wp_no_robots(). |
1585 | 1587 | */ |
1586 | 1588 | function do_robots() { |
1587 | 1589 | header( 'Content-Type: text/plain; charset=utf-8' ); |
… |
… |
function do_robots() { |
1595 | 1597 | |
1596 | 1598 | $output = "User-agent: *\n"; |
1597 | 1599 | $public = get_option( 'blog_public' ); |
1598 | | if ( '0' == $public ) { |
1599 | | $output .= "Disallow: /\n"; |
1600 | | } else { |
1601 | | $site_url = parse_url( site_url() ); |
1602 | | $path = ( ! empty( $site_url['path'] ) ) ? $site_url['path'] : ''; |
1603 | | $output .= "Disallow: $path/wp-admin/\n"; |
1604 | | $output .= "Allow: $path/wp-admin/admin-ajax.php\n"; |
1605 | | } |
| 1600 | |
| 1601 | $site_url = parse_url( site_url() ); |
| 1602 | $path = ( ! empty( $site_url['path'] ) ) ? $site_url['path'] : ''; |
| 1603 | $output .= "Disallow: $path/wp-admin/\n"; |
| 1604 | $output .= "Allow: $path/wp-admin/admin-ajax.php\n"; |
1606 | 1605 | |
1607 | 1606 | /** |
1608 | 1607 | * Filters the robots.txt output. |
diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php
index d6bcc019b1..614853860f 100644
a
|
b
|
function noindex() { |
2986 | 2986 | * Display a noindex meta tag. |
2987 | 2987 | * |
2988 | 2988 | * Outputs a noindex meta tag that tells web robots not to index the page content. |
2989 | | * Typical usage is as a wp_head callback. add_action( 'wp_head', 'wp_no_robots' ); |
| 2989 | * Typical usage is as a {@see 'wp_head'} callback. add_action( 'wp_head', 'wp_no_robots' ); |
2990 | 2990 | * |
2991 | 2991 | * @since 3.3.0 |
| 2992 | * @since 5.3.0 Echo "noindex,nofollow" if search engine visibility is discouraged. |
2992 | 2993 | */ |
2993 | 2994 | function wp_no_robots() { |
2994 | | echo "<meta name='robots' content='noindex,follow' />\n"; |
| 2995 | if ( get_option( 'blog_public' ) ) { |
| 2996 | echo "<meta name='robots' content='noindex,follow' />\n"; |
| 2997 | return; |
| 2998 | } |
| 2999 | |
| 3000 | echo "<meta name='robots' content='noindex,nofollow' />\n"; |
2995 | 3001 | } |
2996 | 3002 | |
2997 | 3003 | /** |
diff --git a/tests/phpunit/tests/general/template.php b/tests/phpunit/tests/general/template.php
index daa77da5b9..fa6636170c 100644
a
|
b
|
class Tests_General_Template extends WP_UnitTestCase { |
612 | 612 | |
613 | 613 | $this->assertSame( $expected, $result ); |
614 | 614 | } |
| 615 | |
| 616 | /** |
| 617 | * @ticket 43590 |
| 618 | */ |
| 619 | function test_wp_no_robots() { |
| 620 | // Simulate private site (search engines discouraged). |
| 621 | update_option( 'blog_public', '0' ); |
| 622 | $actual_private = get_echo( 'wp_no_robots' ); |
| 623 | $this->assertSame( "<meta name='robots' content='noindex,nofollow' />\n", $actual_private ); |
| 624 | |
| 625 | // Simulate public site. |
| 626 | update_option( 'blog_public', '1' ); |
| 627 | $actual_public = get_echo( 'wp_no_robots' ); |
| 628 | $this->assertSame( "<meta name='robots' content='noindex,follow' />\n", $actual_public ); |
| 629 | } |
615 | 630 | } |