Make WordPress Core


Ignore:
Timestamp:
12/04/2015 11:35:54 PM (9 years ago)
Author:
wonderboymusic
Message:

REST API: Core typically sends nocache headers on all auth'ed responses, as in wp, admin-ajax, etc. Because the REST API infrastructure is hooked in pre-wp, we should be setting this ourselves.

Adds unit tests.

Props joehoyle.
Fixes #34832.

File:
1 edited

Legend:

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

    r35758 r35773  
    236236        $this->send_header( 'Access-Control-Expose-Headers', 'X-WP-Total, X-WP-TotalPages' );
    237237        $this->send_header( 'Access-Control-Allow-Headers', 'Authorization' );
     238
     239        /**
     240         * Send nocache headers on authenticated requests.
     241         *
     242         * @since 4.4.0
     243         *
     244         * @param bool $rest_send_nocache_headers Whether to send no-cache headers.
     245         */
     246        $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );
     247        if ( $send_no_cache_headers ) {
     248            foreach ( wp_get_nocache_headers() as $header => $header_value ) {
     249                $this->send_header( $header, $header_value );
     250            }
     251        }
    238252
    239253        /**
Note: See TracChangeset for help on using the changeset viewer.