WordPress.org

Making WordPress.org

Changeset 9070


Ignore:
Timestamp:
07/24/2019 03:44:31 AM (2 years ago)
Author:
dd32
Message:

GlotPress: Add a handler to allow robots.txt to be served by WordPress on translate.wordpress.org.

See #4559.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-routes/inc/class-plugin.php

    r8553 r9070  
    4646        add_filter( 'cron_schedules', [ $this, 'register_cron_schedules' ] );
    4747        add_action( 'init', [ $this, 'register_cron_events' ] );
     48        add_action( 'init', [ $this, 'respect_robots_txt' ], 9 );
    4849        add_action( 'wporg_translate_update_existing_locales_cache', [ $this, 'update_existing_locales_cache' ] );
    4950        add_action( 'wporg_translate_update_translation_status_cache', [ $this, 'update_translation_status_cache' ] );
    5051        add_action( 'wporg_translate_update_contributors_count_cache', [ $this, 'update_contributors_count_cache' ] );
     52    }
     53
     54    /**
     55     * The GlotPress match-all route is prepended early before a lot of rules, including the robots.txt rules.
     56     *
     57     * gp_rewrite_rules() is called from gp_init() on init at priority 10, we need to insert before that.
     58     */
     59    function respect_robots_txt() {
     60        // ?robots=1 is here to trigger `is_robots()`, which prevents canonical.
     61        // ?gp_route=robots.txt is here, as GlotPress ultimately is the router for the request.
     62        add_rewrite_rule( '^robots\.txt$', 'index.php?robots=1&gp_route=robots.txt', 'top' );
    5163    }
    5264
     
    7991     * Adds:
    8092     *  - /
     93     *  - /robots.txt
    8194     *  - /locale/$locale
    8295     *  - /locale/$locale/$path
     
    156169            GP::$router->prepend( "/projects/wp-themes/$project/language-packs", array( __NAMESPACE__ . '\Routes\WP_Themes', 'get_theme_language_packs' ) );
    157170
     171            // Add Robots.txt support
     172            GP::$router->prepend( '/robots\.txt', 'do_robots' );
     173
    158174            if ( defined( 'TRANSLATE_MAINTENANCE_ACTIVE' ) ) {
    159175                GP::$router->prepend( '.*', array( __NAMESPACE__ . '\Routes\Maintenance', 'show_maintenance_message' ) );
Note: See TracChangeset for help on using the changeset viewer.