-
Notifications
You must be signed in to change notification settings - Fork 44
/
class-front-end.php
92 lines (75 loc) · 2.04 KB
/
class-front-end.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
defined( 'ABSPATH' ) or die( 'you do not have access to this page!' );
if ( ! class_exists( 'rsssl_front_end' ) ) {
class rsssl_front_end {
private static $_this;
public $wp_redirect;
public $ssl_enabled;
public function __construct() {
if ( isset( self::$_this ) ) {
wp_die( 'you cannot create a second instance.' );
}
self::$_this = $this;
$this->ssl_enabled = rsssl_get_option( 'ssl_enabled' );
$this->wp_redirect = rsssl_get_option( 'redirect', 'redirect' ) === 'wp_redirect';
add_action( 'rest_api_init', array( $this, 'wp_rest_api_force_ssl' ), ~PHP_INT_MAX );
}
public static function this() {
return self::$_this;
}
/**
* PHP redirect, when ssl is true.
*
* @since 2.2
*
* @access public
*
*/
public function force_ssl() {
if ( $this->ssl_enabled && $this->wp_redirect ) {
add_action( 'wp', array( $this, 'wp_redirect_to_ssl' ), 40, 3 );
}
}
/**
* Force SSL on wp rest api
*
* @since 2.5.14
*
* @access public
*
*/
public function wp_rest_api_force_ssl(): void {
//check for Command Line
if ( php_sapi_name() === 'cli' ) {
return;
}
if ( ! array_key_exists( 'HTTP_HOST', $_SERVER ) ) {
return;
}
if ( $this->ssl_enabled && ! is_ssl() && ! ( defined( 'rsssl_no_rest_api_redirect' ) && rsssl_no_rest_api_redirect ) ) {
$redirect_url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
wp_redirect( $redirect_url, 301 );
exit;
}
}
/**
* Redirect using wp redirect
*
* @since 2.5.0
*
* @access public
*
*/
public function wp_redirect_to_ssl(): void {
if ( ! array_key_exists( 'HTTP_HOST', $_SERVER ) ) {
return;
}
if ( ! is_ssl() && ! ( defined( 'rsssl_no_wp_redirect' ) && rsssl_no_wp_redirect ) ) {
$redirect_url = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$redirect_url = apply_filters( 'rsssl_wp_redirect_url', $redirect_url );
wp_redirect( $redirect_url, 301, 'WordPress - Really Simple Security' );
exit;
}
}
}
}