Skip to content

Instantly share code, notes, and snippets.

@ocean90
Created September 4, 2012 15:18
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ocean90/3622298 to your computer and use it in GitHub Desktop.
Save ocean90/3622298 to your computer and use it in GitHub Desktop.
WordPress: Return the X-XSS-Protection = 0 header for post previews
/**
* Add a X-XSS-Protection = 0 header for post previews to allow
* Webkit browsers to render iframe and flash objects.
* @see: http://core.trac.wordpress.org/ticket/20148
*
* @param $headers array Already added header items.
* @param $object WP The query variables.
*
* @return array
*/
function send_no_xss_protection_header( $headers, $object ) {
if (
! empty( $object->query_vars['preview'] ) &&
! empty( $object->query_vars['p'] ) &&
wp_get_referer() &&
wp_get_referer() == sprintf( admin_url( 'post.php?post=%d&action=edit' ), $object->query_vars['p'] )
)
$headers['X-XSS-Protection'] = 0;
return $headers;
}
add_filter( 'wp_headers', 'send_no_xss_protection_header', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment