Make WordPress Core

Changeset 59890


Ignore:
Timestamp:
02/28/2025 04:56:57 PM (3 months ago)
Author:
jorbin
Message:

Site Health: Add a robots.txt check to the server data.

Provide a bit of information about robots.txt to help people understand if the file is generated by WordPress.

Props zodiac1978, audrasjb, joostdevalk, jorbin.
Fixes #56595.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-debug-data.php

    r59853 r59890  
    505505        }
    506506
     507        // Check if a robots.txt file exists.
     508        if ( is_file( ABSPATH . 'robots.txt' ) ) {
     509            // If the file exists, turn debug info to true.
     510            $robotstxt_debug = true;
     511
     512            /* translators: %s: robots.txt */
     513            $robotstxt_string = sprintf( __( 'There is a static %s file in your installation folder. WordPress can not dynamicly serve one.' ), 'robots.txt' );
     514        } elseif ( got_url_rewrite() ) {
     515            // No robots.txt file available and rewrite rules in place, turn debug info to false.
     516            $robotstxt_debug = false;
     517
     518            /* translators: %s: robots.txt */
     519            $robotstxt_string = sprintf( __( 'Your site is using the dynamic %s file which is generated by WordPress.' ), 'robots.txt' );
     520        } else {
     521            // No robots.txt file, but without rewrite rules WP can't serve one.
     522            $robotstxt_debug = true;
     523
     524            /* translators: %s: robots.txt */
     525            $robotstxt_string = sprintf( __( 'WordPress can not dynamicly serve a %s file due to a lack of rewrite rule support' ), 'robots.txt' );
     526
     527        }
     528        $fields['static_robotstxt_file'] = array(
     529            'label' => __( 'robots.txt' ),
     530            'value' => $robotstxt_string,
     531            'debug' => $robotstxt_debug,
     532        );
     533
    507534        // Server time.
    508535        $date = new DateTime( 'now', new DateTimeZone( 'UTC' ) );
Note: See TracChangeset for help on using the changeset viewer.