2
2
3
3
namespace Dwnload \WpRestApi \RestApi ;
4
4
5
- use function Dwnload \WpRestApi \Helpers \filter_var_string ;
6
5
use WP_REST_Request ;
7
6
use WP_REST_Server ;
8
7
@@ -44,7 +43,7 @@ protected function getCacheKey(
44
43
}
45
44
}
46
45
47
- return filter_var_string (\apply_filters (RestDispatch::FILTER_API_KEY , $ request_uri , $ server , $ request ));
46
+ return $ this -> sanitize (\apply_filters (RestDispatch::FILTER_API_KEY , $ request_uri , $ server , $ request ));
48
47
}
49
48
50
49
/**
@@ -54,7 +53,7 @@ protected function getCacheKey(
54
53
*/
55
54
protected function getCacheGroup () : string
56
55
{
57
- return filter_var_string (\apply_filters (RestDispatch::FILTER_API_GROUP , RestDispatch::CACHE_GROUP ));
56
+ return $ this -> sanitize (\apply_filters (RestDispatch::FILTER_API_GROUP , RestDispatch::CACHE_GROUP ));
58
57
}
59
58
60
59
/**
@@ -68,11 +67,23 @@ protected function wpCacheFlush() : bool
68
67
return \wp_cache_flush ();
69
68
}
70
69
70
+ /**
71
+ * Empty all cache.
72
+ *
73
+ * @uses wp_cache_replace()
74
+ * @param string $key The key under which the value is stored.
75
+ * @return bool Returns TRUE on success or FALSE on failure.
76
+ */
77
+ protected function wpCacheReplace (string $ key ) : bool
78
+ {
79
+ return \wp_cache_replace ($ this ->cleanKey ($ key ), false , $ this ->getCacheGroup (), -1 );
80
+ }
81
+
71
82
/**
72
83
* Empty all cache.
73
84
*
74
85
* @uses wp_cache_delete()
75
- * @param string $key The key under which to store the value.
86
+ * @param string $key The key under which the value is stored .
76
87
* @return bool Returns TRUE on success or FALSE on failure.
77
88
*/
78
89
protected function wpCacheDeleteByKey (string $ key ) : bool
@@ -104,6 +115,16 @@ protected function cleanKey(string $key) : string
104
115
*/
105
116
protected function getRequestUri () : string
106
117
{
107
- return filter_var_string (wp_unslash ($ _SERVER ['REQUEST_URI ' ]));
118
+ return $ this ->sanitize (\wp_unslash ($ _SERVER ['REQUEST_URI ' ]));
119
+ }
120
+
121
+ /**
122
+ * Sanitize incoming variables as a string value.
123
+ * @param mixed $variable
124
+ * @return string|false
125
+ */
126
+ private function sanitize ($ variable )
127
+ {
128
+ return \filter_var ($ variable , FILTER_SANITIZE_STRING );
108
129
}
109
130
}
0 commit comments