PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 5.3.1
Defender Security – Malware Scanner, Login Security & Firewall v5.3.1
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / framework / helper / class-http.php

class-http.php in Defender Security – Malware Scanner, Login Security & Firewall 5.3.1, at framework/helper/class-http.php

73 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles all HTTP requests in this plugin.
4 *
5 * @package Calotes\Helper
6 */
7
8 namespace Calotes\Helper;
9
10 /**
11 * Validates and sanitizes HTTP request data.
12 */
13 class HTTP {
14
15
16 /**
17 * Strips the protocol from a URL.
18 *
19 * @param string $url The URL to strip the protocol from.
20 *
21 * @return string The URL without the protocol.
22 */
23 public static function strips_protocol( $url ) {
24 $parts = wp_parse_url( $url );
25
26 $host = $parts['host'] . ( isset( $parts['path'] ) ? $parts['path'] : null );
27
28 return rtrim( $host, '/' );
29 }
30
31 /**
32 * Retrieves a value from the $_GET super global array based on the provided key.
33 *
34 * @param mixed $key The key to search for in the $_GET array.
35 * @param mixed $default_name The default value to return if key is not found.
36 * @param bool $strict Flag to determine if strict comparison should be used.
37 *
38 * @return mixed The retrieved value after applying sanitization if needed.
39 */
40 public static function get( $key, $default_name = null, bool $strict = false ) {
41 $value = defender_get_data_from_request( $key, 'g' ) ?? $default_name;
42 if ( true === $strict && empty( $value ) ) {
43 $value = $default_name;
44 }
45 if ( is_array( $value ) ) {
46 $value = defender_sanitize_data( $value );
47 } elseif ( is_string( $value ) ) {
48 $value = sanitize_textarea_field( $value );
49 }
50
51 return $value;
52 }
53
54 /**
55 * Retrieves a value from the $_POST super global array based on the provided key.
56 *
57 * @param mixed $key The key to search for in the $_POST array.
58 * @param mixed $default_name The default value to return if key is not found.
59 *
60 * @return mixed The retrieved value after applying sanitization if needed.
61 */
62 public static function post( $key, $default_name = null ) {
63 $value = defender_get_data_from_request( $key, 'p' ) ?? $default_name;
64 if ( is_array( $value ) ) {
65 $value = defender_sanitize_data( $value );
66 } elseif ( is_string( $value ) ) {
67 $value = sanitize_textarea_field( $value );
68 }
69
70 return $value;
71 }
72 }
73