wpsc_get_accept_header()
Returns a string containing a sanitized version of the Accept header. For now, this can only respond with text/html or application/json - used to differentiate between pages which may or may not be cacheable.
Hooks from the function
Returns
null. Nothing (null).
Usage
wpsc_get_accept_header();
wpsc_get_accept_header() wpsc get accept header code WPSCache 3.1.0
function wpsc_get_accept_header() {
static $accept = 'N/A';
if ( $accept === 'N/A' ) {
$accept_headers = apply_filters( 'wpsc_accept_headers', array( 'application/json', 'application/activity+json', 'application/ld+json' ) );
$accept_headers = array_map( 'strtolower', $accept_headers );
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash -- $accept is checked and set below.
$accept = isset( $_SERVER['HTTP_ACCEPT'] ) ? strtolower( filter_var( $_SERVER['HTTP_ACCEPT'] ) ) : '';
foreach ( $accept_headers as $header ) {
if ( str_contains( $accept, $header ) ) {
$accept = 'application/json';
}
}
if ( $accept !== 'application/json' ) {
$accept = 'text/html';
}
wp_cache_debug( 'ACCEPT: ' . $accept );
}
return $accept;
}