activation
5 months ago
assets-managment
5 months ago
components
5 months ago
entities
5 months ago
premium
5 months ago
updates
5 months ago
class-check-compatibility.php
6 months ago
class-factory-migrations.php
5 months ago
class-factory-notices.php
5 months ago
class-factory-options.php
4 months ago
class-factory-plugin-abstract.php
5 months ago
class-factory-plugin-base.php
5 months ago
class-factory-requests.php
5 months ago
class-factory-requirements.php
5 months ago
functions.php
5 months ago
index.php
6 months ago
class-factory-requests.php
113 lines
| 1 | <?php |
| 2 | // Exit if accessed directly |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | /* |
| 8 | * |
| 9 | * @package factory-core |
| 10 | */ |
| 11 | |
| 12 | class Wbcr_Factory600_Request { |
| 13 | |
| 14 | /** |
| 15 | * @param string|null $param |
| 16 | * @param bool|string $sanitize true/false or sanitize function name |
| 17 | * @param bool $default |
| 18 | * @param string $method_name |
| 19 | * |
| 20 | * @return array|bool|mixed |
| 21 | */ |
| 22 | private function getBody( $param, $sanitize = false, $default = false, $method_name = 'REQUEST' ) { |
| 23 | if ( empty( $param ) ) { |
| 24 | return null; |
| 25 | } |
| 26 | |
| 27 | $sanitize_function_name = 'sanitize_text_field'; |
| 28 | |
| 29 | switch ( strtoupper( $method_name ) ) { |
| 30 | case 'GET': |
| 31 | $method = $_GET; |
| 32 | break; |
| 33 | case 'POST': |
| 34 | $method = $_POST; |
| 35 | break; |
| 36 | case 'REQUEST': |
| 37 | $method = $_REQUEST; |
| 38 | break; |
| 39 | } |
| 40 | |
| 41 | if ( is_string( $sanitize ) && $sanitize !== $sanitize_function_name ) { |
| 42 | $sanitize_function_name = $sanitize; |
| 43 | } |
| 44 | |
| 45 | if ( isset( $method[ $param ] ) ) { |
| 46 | if ( is_array( $method[ $param ] ) ) { |
| 47 | return ! empty( $sanitize ) ? $this->recursiveArrayMap( $sanitize_function_name, $method[ $param ] ) : $method[ $param ]; |
| 48 | } else { |
| 49 | return ! empty( $sanitize ) ? call_user_func( $sanitize_function_name, $method[ $param ] ) : $method[ $param ]; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return $default; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Recursive sanitation for an array |
| 58 | * |
| 59 | * @param string $function_name |
| 60 | * @param $array |
| 61 | * |
| 62 | * @return mixed |
| 63 | */ |
| 64 | public function recursiveArrayMap( $function_name, $array ) { |
| 65 | foreach ( $array as $key => &$value ) { |
| 66 | if ( is_array( $value ) ) { |
| 67 | $value = $this->recursiveArrayMap( $function_name, $value ); |
| 68 | } else { |
| 69 | if ( ! function_exists( $function_name ) ) { |
| 70 | throw new Exception( 'Function ' . $function_name . 'is undefined.' ); |
| 71 | } |
| 72 | |
| 73 | $value = $function_name( $value ); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | return $array; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @param string|null $param |
| 82 | * @param mixed $default see method getBody |
| 83 | * @param bool $sanitize |
| 84 | * |
| 85 | * @return mixed|null |
| 86 | */ |
| 87 | public function request( $param, $default = false, $sanitize = false ) { |
| 88 | return $this->getBody( $param, $sanitize, $default ); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * @param string|null $param |
| 93 | * @param mixed $default see method getBody |
| 94 | * @param bool $sanitize |
| 95 | * |
| 96 | * @return mixed|null |
| 97 | */ |
| 98 | public function get( $param, $default = false, $sanitize = false ) { |
| 99 | return $this->getBody( $param, $sanitize, $default, 'get' ); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @param string|null $param |
| 104 | * @param mixed $default see method getBody |
| 105 | * @param bool $sanitize |
| 106 | * |
| 107 | * @return mixed|null |
| 108 | */ |
| 109 | public function post( $param, $default = false, $sanitize = false ) { |
| 110 | return $this->getBody( $param, $sanitize, $default, 'post' ); |
| 111 | } |
| 112 | } |
| 113 |