PluginProbe ʕ •ᴥ•ʔ
Disable Admin Notices – Hide Dashboard Notifications / trunk
Disable Admin Notices – Hide Dashboard Notifications vtrunk
1.4.5 trunk 1.0.0 1.0.2 1.0.3 1.0.5 1.0.6 1.1.1 1.1.3 1.1.4 1.2.0 1.2.2 1.2.3 1.2.4 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4
disable-admin-notices / libs / factory / core / includes / class-factory-requests.php
disable-admin-notices / libs / factory / core / includes Last commit date
activation 1 year ago assets-managment 1 year ago components 1 year ago entities 1 year ago updates 5 months ago class-check-compatibility.php 1 year ago class-factory-migrations.php 6 months ago class-factory-notices.php 1 year ago class-factory-options.php 1 year ago class-factory-plugin-abstract.php 5 months ago class-factory-plugin-base.php 1 year ago class-factory-requests.php 1 year ago class-factory-requirements.php 5 months ago functions.php 1 year ago index.php 3 years ago
class-factory-requests.php
115 lines
1 <?php
2 // Exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /*
8 * @author Alex Kovalev <alex.kovalevv@gmail.com>, repo: https://github.com/alexkovalevv
9 * @author Webcraftic <wordpress.webraftic@gmail.com>, site: https://webcraftic.com
10 *
11 * @package factory-core
12 */
13
14 class Wbcr_Factory480_Request {
15
16 /**
17 * @param null $param
18 * @param bool|string $sanitize true/false or sanitize function name
19 * @param bool $default
20 * @param string $method_name
21 *
22 * @return array|bool|mixed
23 */
24 private function getBody( $param, $sanitize = false, $default = false, $method_name = 'REQUEST' ) {
25 if ( empty( $param ) ) {
26 return null;
27 }
28
29 $sanitize_function_name = 'sanitize_text_field';
30
31 switch ( strtoupper( $method_name ) ) {
32 case 'GET':
33 $method = $_GET;
34 break;
35 case 'POST':
36 $method = $_POST;
37 break;
38 case 'REQUEST':
39 $method = $_REQUEST;
40 break;
41 }
42
43 if ( is_string( $sanitize ) && $sanitize !== $sanitize_function_name ) {
44 $sanitize_function_name = $sanitize;
45 }
46
47 if ( isset( $method[ $param ] ) ) {
48 if ( is_array( $method[ $param ] ) ) {
49 return ! empty( $sanitize ) ? $this->recursiveArrayMap( $sanitize_function_name, $method[ $param ] ) : $method[ $param ];
50 } else {
51 return ! empty( $sanitize ) ? call_user_func( $sanitize_function_name, $method[ $param ] ) : $method[ $param ];
52 }
53 }
54
55 return $default;
56 }
57
58 /**
59 * Recursive sanitation for an array
60 *
61 * @param string $function_name
62 * @param $array
63 *
64 * @return mixed
65 */
66 public function recursiveArrayMap( $function_name, $array ) {
67 foreach ( $array as $key => &$value ) {
68 if ( is_array( $value ) ) {
69 $value = $this->recursiveArrayMap( $function_name, $value );
70 } else {
71 if ( ! function_exists( $function_name ) ) {
72 throw new Exception( 'Function ' . $function_name . 'is undefined.' );
73 }
74
75 $value = $function_name( $value );
76 }
77 }
78
79 return $array;
80 }
81
82 /**
83 * @param $param
84 * @param bool|string see method getBody
85 * @param bool $default
86 *
87 * @return mixed|null
88 */
89 public function request( $param, $default = false, $sanitize = false ) {
90 return $this->getBody( $param, $sanitize, $default );
91 }
92
93 /**
94 * @param null $param
95 * @param bool|string see method getBody
96 * @param bool $default
97 *
98 * @return mixed|null
99 */
100 public function get( $param, $default = false, $sanitize = false ) {
101 return $this->getBody( $param, $sanitize, $default, 'get' );
102 }
103
104 /**
105 * @param $param
106 * @param bool|string see method getBody
107 * @param bool $default
108 *
109 * @return mixed|null
110 */
111 public function post( $param, $default = false, $sanitize = false ) {
112 return $this->getBody( $param, $sanitize, $default, 'post' );
113 }
114 }
115