| 1 |
<?php |
| 2 |
// Exit if accessed directly. |
| 3 |
if ( ! defined( 'ABSPATH' ) ) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
/** |
| 8 |
* Apply HSTS Header. |
| 9 |
* |
| 10 |
* Applies the Strict-Transport-Security header if the 'ns_shield_hsts' option is enabled |
| 11 |
* and the current connection is secure (HTTPS). This header instructs browsers to only |
| 12 |
* access the site over HTTPS for a specified period. |
| 13 |
* |
| 14 |
* @return void |
| 15 |
*/ |
| 16 |
function ns_shield_apply_hsts_header() { |
| 17 |
// Apply HSTS only on secure connections. |
| 18 |
if ( is_ssl() && get_option( 'ns_shield_hsts' ) ) { |
| 19 |
header( 'Strict-Transport-Security: max-age=31536000; includeSubDomains; preload' ); |
| 20 |
} |
| 21 |
} |
| 22 |
add_action( 'send_headers', 'ns_shield_apply_hsts_header' ); |
| 23 |
|