@@ -50,23 +50,39 @@ public static function normalize(
5050 }
5151
5252 public static function isSecure (): bool {
53- return ( ! empty ( $ _SERVER ['HTTPS ' ] ) && $ _SERVER ['HTTPS ' ] !== 'off ' ) ||
54- $ _SERVER ['SERVER_PORT ' ] === 443 ;
53+ if ( isset ( $ _SERVER ['HTTPS ' ] ) && $ _SERVER ['HTTPS ' ] !== 'off ' ) {
54+ return true ;
55+ }
56+
57+ if ( isset ( $ _SERVER ['SERVER_PORT ' ] ) && $ _SERVER ['SERVER_PORT ' ] === 443 ) {
58+ return true ;
59+ }
60+
61+ return false ;
5562 }
5663
5764 /**
5865 * Returns the current full URL including querystring
5966 */
6067 public static function getCurrent (): string {
68+ if ( ! isset ( $ _SERVER ['HTTP_HOST ' ] ) ) {
69+ throw WsLog::ex ( 'HTTP_HOST not set ' );
70+ }
71+
6172 $ scheme = self ::isSecure () ? 'https ' : 'http ' ;
62- $ url = $ scheme . ':// ' . $ _SERVER ['HTTP_HOST ' ];
73+ $ url = $ scheme . ':// ' . sanitize_text_field ( wp_unslash ( $ _SERVER ['HTTP_HOST ' ] ) ) ;
6374
6475 // Only include port number if needed
65- if ( ! in_array ( $ _SERVER ['SERVER_PORT ' ], [ 80 , 443 ], true ) ) {
66- $ url .= ': ' . $ _SERVER ['SERVER_PORT ' ];
76+ if ( isset ( $ _SERVER ['SERVER_PORT ' ] )
77+ && ! in_array ( $ _SERVER ['SERVER_PORT ' ], [ 80 , 443 ], true ) ) {
78+ $ url .= ': ' . (int ) $ _SERVER ['SERVER_PORT ' ];
79+ }
80+
81+ if ( isset ( $ _SERVER ['REQUEST_URI ' ] ) ) {
82+ $ url = $ url . sanitize_url ( wp_unslash ( $ _SERVER ['REQUEST_URI ' ] ) );
6783 }
6884
69- return $ url . $ _SERVER [ ' REQUEST_URI ' ] ;
85+ return $ url ;
7086 }
7187
7288 /**
0 commit comments