Making WordPress.org

Changeset 12554


Ignore:
Timestamp:
04/21/2023 09:40:40 AM (3 years ago)
Author:
akirk
Message:

Translate: add CORS header for the playground

File:
1 edited

Legend:

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

    r12436 r12554  
    4646                add_filter( 'pre_handle_404', array( $this, 'short_circuit_handle_404' ) );
    4747                add_action( 'init', array( $this, 'bump_assets_versions' ), 20 );
     48                add_action( 'init', array( $this, 'add_cors_header' ) );
    4849                add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ) );
    4950                add_filter( 'body_class', array( $this, 'wporg_add_make_site_body_class' ) );
     
    464465                WP_CLI::add_command( 'wporg-translate show-stats', __NAMESPACE__ . '\CLI\Stats_Print' );
    465466
     467        }
     468
     469        /**
     470         * Allow the Playground to access translate.wordpress.org.
     471         */
     472        public static function add_cors_header() {
     473                if ( headers_sent() ) {
     474                        return;
     475                }
     476                if ( isset( $_SERVER['HTTP_ORIGIN'] ) ) {
     477                        switch ( $_SERVER['HTTP_ORIGIN'] ) {
     478                                case 'https://playground.wordpress.net':
     479                                        header( 'Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN'] );
     480                        }
     481                }
     482                header( 'Vary: origin' );
    466483        }
    467484
Note: See TracChangeset for help on using the changeset viewer.