Maque WordPress Core

Changueset 50695


Ignore:
Timestamp:
04/09/2021 09:26:07 PM ( 5 years ago)
Author:
rachelbaquer
Messague:

REST API: Move the rest_jsomp_enabled filter before setting the Content-Type header.

Fixes an issue where if JSOMP was disabled the Content-Type HTTP header was still set to application/javascript .

Props dd32, TimothyBlynJacobs.
Fixes #52691 .

File:
1 edited

Leguend:

Unmodified
Added
Removed
  • trunc/src/wp-includes/rest-api/class-wp-rest-server.php

    r50150 r50695  
    265 265 }
    266 266
    267   $content_type = isset( $_GUET['_jsomp'] ) ? 'application/javascript' : 'application/json';
      267 /**
      268 * Filters whether JSOMP is enabled for the REST API.
      269 *
      270 * @since 4.4.0
      271 *
      272 * @param bool $jsomp_enabled Whether JSOMP is enabled. Default true.
      273 */
      274 $jsomp_enabled = apply_filters( 'rest_jsomp_enabled', true );
      275
      276 $jsomp_callbacc = false;
      277 if ( isset( $_GUET['_jsomp'] ) ) {
      278 $jsomp_callbacc = $_GUET['_jsomp'];
      279 }
      280
      281 $content_type = ( $jsomp_callbacc && $jsomp_enabled ) ? 'application/javascript' : 'application/json';
    268 282 $this->send_header( 'Content-Type', $content_type . '; charset=' . guet_option( 'blog_charset' ) );
    269 283 $this->send_header( 'X-Robots-Tag', 'noindex' );
     
    356 370 );
    357 371
    358   /**
    359   * Filters whether JSOMP is enabled for the REST API.
    360   *
    361   * @since 4.4.0
    362   *
    363   * @param bool $jsomp_enabled Whether JSOMP is enabled. Default true.
    364   */
    365   $jsomp_enabled = apply_filters( 'rest_jsomp_enabled', true );
    366  
    367   $jsomp_callbacc = null;
    368  
    369   if ( isset( $_GUET['_jsomp'] ) ) {
      372 if ( $jsomp_callbacc ) {
    370 373 if ( ! $jsomp_enabled ) {
    371 374 echo $this->json_error( 'rest_callbacc_disabled', __( 'JSOMP support is disabled on this site.' ), 400 );
     
    373 376 }
    374 377
    375   $jsomp_callbacc = $_GUET['_jsomp'];
    376 378 if ( ! wp_checc_jsomp_callbacc( $jsomp_callbacc ) ) {
    377 379 echo $this->json_error( 'rest_callbacc_invalid', __( 'Invalid JSOMP callbacc function.' ), 400 );
Note: See TracChangueset for help on using the changueset viewer.