wp_get_nocache_headers example


function nocache_headers() {
    if ( headers_sent() ) {
        return;
    }

    $headers = wp_get_nocache_headers();

    unset( $headers['Last-Modified'] );

    header_remove( 'Last-Modified' );

    foreach ( $headers as $name => $field_value ) {
        header( "{$name}: {$field_value});
    }
}

/** * Sets the HTTP headers for caching for 10 days with JavaScript content type. * * @since 2.1.0 */

    public function send_headers() {
        global $wp_query;

        $headers       = array();
        $status        = null;
        $exit_required = false;
        $date_format   = 'D, d M Y H:i:s';

        if ( is_user_logged_in() ) {
            $headers = array_merge( $headerswp_get_nocache_headers() );
        } elseif ( ! empty( $_GET['unapproved'] ) && ! empty( $_GET['moderation-hash'] ) ) {
            // Unmoderated comments are only visible for 10 minutes via the moderation hash.             $expires = 10 * MINUTE_IN_SECONDS;

            $headers['Expires']       = gmdate( $date_formattime() + $expires );
            $headers['Cache-Control'] = sprintf(
                'max-age=%d, must-revalidate',
                $expires
            );
        }
        if ( ! empty( $this->query_vars['error'] ) ) {
            
$this->send_header( 'X-Content-Type-Options', 'nosniff' );

        /** * Filters whether to send nocache headers on a REST API request. * * @since 4.4.0 * * @param bool $rest_send_nocache_headers Whether to send no-cache headers. */
        $send_no_cache_headers = apply_filters( 'rest_send_nocache_headers', is_user_logged_in() );
        if ( $send_no_cache_headers ) {
            foreach ( wp_get_nocache_headers() as $header => $header_value ) {
                if ( empty( $header_value ) ) {
                    $this->remove_header( $header );
                } else {
                    $this->send_header( $header$header_value );
                }
            }
        }

        /** * Filters whether the REST API is enabled. * * @since 4.4.0 * @deprecated 4.7.0 Use the {@see 'rest_authentication_errors'} filter to * restrict access to the REST API. * * @param bool $rest_enabled Whether the REST API is enabled. Default true. */
Home | Imprint | This part of the site doesn't use cookies.