| 1 |
<?php |
| 2 |
// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 3 |
if (!defined('ABSPATH') && !defined('MCDATAPATH')) exit; |
| 4 |
|
| 5 |
if (!trait_exists('WPRProtectFWRuleWPFunc_V676')) : |
| 6 |
trait WPRProtectFWRuleWPFunc_V676 { |
| 7 |
private function _rf_sanitizeUser() { |
| 8 |
$args = $this->processRuleFunctionParams( |
| 9 |
'sanitizeUser', |
| 10 |
func_num_args(), |
| 11 |
func_get_args(), |
| 12 |
2, |
| 13 |
['string', 'boolean'] |
| 14 |
); |
| 15 |
$username = $args[0]; |
| 16 |
$strict = $args[1]; |
| 17 |
|
| 18 |
if (!function_exists('sanitize_user') || !WPRProtectUtils_V676::haveMupluginsLoaded()) { |
| 19 |
throw new WPRProtectRuleError_V676( |
| 20 |
$this->addExState("sanitizeUser: Func sanitize_user doesn't exist.") |
| 21 |
); |
| 22 |
} |
| 23 |
|
| 24 |
return sanitize_user($username, $strict); |
| 25 |
} |
| 26 |
|
| 27 |
private function _rf_maybeSerialize() { |
| 28 |
$args = $this->processRuleFunctionParams( |
| 29 |
'maybeSerialize', |
| 30 |
func_num_args(), |
| 31 |
func_get_args(), |
| 32 |
1 |
| 33 |
); |
| 34 |
$data = $args[0]; |
| 35 |
|
| 36 |
if (!function_exists('maybe_serialize') || !WPRProtectUtils_V676::haveMupluginsLoaded()) { |
| 37 |
throw new WPRProtectRuleError_V676( |
| 38 |
$this->addExState("maybeSerialize: Func maybe_serialize doesn't exist.") |
| 39 |
); |
| 40 |
} |
| 41 |
|
| 42 |
return maybe_serialize($data); |
| 43 |
} |
| 44 |
|
| 45 |
private function _rf_isUserLoggedIn() { |
| 46 |
$args = $this->processRuleFunctionParams( |
| 47 |
'isUserLoggedIn', |
| 48 |
func_num_args(), |
| 49 |
func_get_args() |
| 50 |
); |
| 51 |
|
| 52 |
if (!function_exists('is_user_logged_in') || !WPRProtectUtils_V676::havePluginsLoaded()) { |
| 53 |
throw new WPRProtectRuleError_V676( |
| 54 |
$this->addExState("isUserLoggedIn: Func is_user_logged_in doesn't exist.") |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
return is_user_logged_in(); |
| 59 |
} |
| 60 |
|
| 61 |
private function _rf_getCurrentWPUser() { |
| 62 |
$this->processRuleFunctionParams( |
| 63 |
'getCurrentWPUser', |
| 64 |
func_num_args(), |
| 65 |
func_get_args() |
| 66 |
); |
| 67 |
|
| 68 |
if (!function_exists('wp_get_current_user') || !WPRProtectUtils_V676::havePluginsLoaded()) { |
| 69 |
throw new WPRProtectRuleError_V676( |
| 70 |
$this->addExState("getCurrentWPUser: Func wp_get_current_user doesn't exist.") |
| 71 |
); |
| 72 |
} |
| 73 |
|
| 74 |
return WPRProtectFWRuleEngine_V676::toAllowedType(wp_get_current_user()); |
| 75 |
} |
| 76 |
|
| 77 |
private function _rf_currentUserCan() { |
| 78 |
$args = $this->processRuleFunctionParams( |
| 79 |
'currentUserCan', |
| 80 |
func_num_args(), |
| 81 |
func_get_args(), |
| 82 |
1, |
| 83 |
['string'] |
| 84 |
); |
| 85 |
$capability = $args[0]; |
| 86 |
$arg1 = isset($args[1]) ? $args[1] : null; |
| 87 |
$arg2 = isset($args[2]) ? $args[2] : null; |
| 88 |
|
| 89 |
if (!function_exists('current_user_can') || !WPRProtectUtils_V676::havePluginsLoaded()) { |
| 90 |
throw new WPRProtectRuleError_V676( |
| 91 |
$this->addExState("currentUserCan: Required funcs doesn't exist.") |
| 92 |
); |
| 93 |
} |
| 94 |
|
| 95 |
if (isset($arg1)) { |
| 96 |
if (isset($arg2)) { |
| 97 |
return current_user_can($capability, $arg1, $arg2); |
| 98 |
} else { |
| 99 |
return current_user_can($capability, $arg1); |
| 100 |
} |
| 101 |
} else { |
| 102 |
return current_user_can($capability); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
private function _rf_getUserBy() { |
| 107 |
$args = $this->processRuleFunctionParams( |
| 108 |
'getUserBy', |
| 109 |
func_num_args(), |
| 110 |
func_get_args(), |
| 111 |
2, |
| 112 |
['string'] |
| 113 |
); |
| 114 |
$field = $args[0]; |
| 115 |
$value = $args[1]; |
| 116 |
|
| 117 |
if (!function_exists('get_user_by') || !WPRProtectUtils_V676::havePluginsLoaded()) { |
| 118 |
throw new WPRProtectRuleError_V676( |
| 119 |
$this->addExState("getUserBy: Func get_user_by doesn't exist") |
| 120 |
); |
| 121 |
} |
| 122 |
|
| 123 |
if ($field === 'ID' || $field === 'id') { |
| 124 |
if (!is_string($value) && !is_int($value)) { |
| 125 |
throw new WPRProtectRuleError_V676( |
| 126 |
$this->addExState("getUserBy: Value must be a valid string or an integer") |
| 127 |
); |
| 128 |
} |
| 129 |
} elseif (!is_string($value)) { |
| 130 |
throw new WPRProtectRuleError_V676( |
| 131 |
$this->addExState("getUserBy: Value must be a valid string") |
| 132 |
); |
| 133 |
} |
| 134 |
|
| 135 |
$user = get_user_by($field, $value); |
| 136 |
if (false === $user) { |
| 137 |
return null; |
| 138 |
} |
| 139 |
|
| 140 |
return WPRProtectFWRuleEngine_V676::toAllowedType($user); |
| 141 |
} |
| 142 |
|
| 143 |
private function _rf_getCurrentWPUserCapabilities() { |
| 144 |
$args = $this->processRuleFunctionParams( |
| 145 |
'getCurrentWPUserCapabilities', |
| 146 |
func_num_args(), |
| 147 |
func_get_args() |
| 148 |
); |
| 149 |
|
| 150 |
$user = $this->_rf_getCurrentWPUser(); |
| 151 |
|
| 152 |
if (!array_key_exists("allcaps", $user)) { |
| 153 |
throw new WPRProtectRuleError_V676( |
| 154 |
$this->addExState("getCurrentWPUserCapabilities: allcaps doesn't exist in user.") |
| 155 |
); |
| 156 |
} |
| 157 |
|
| 158 |
return WPRProtectFWRuleEngine_V676::toAllowedType($user["allcaps"]); |
| 159 |
} |
| 160 |
|
| 161 |
private function _rf_getUserCapabilities() { |
| 162 |
$args = $this->processRuleFunctionParams( |
| 163 |
'getUserCapabilities', |
| 164 |
func_num_args(), |
| 165 |
func_get_args(), |
| 166 |
1 |
| 167 |
); |
| 168 |
$user_id = $args[0]; |
| 169 |
|
| 170 |
$user = $this->_rf_getUserBy("id", $user_id); |
| 171 |
if (is_null($user)) { |
| 172 |
return array(); |
| 173 |
} |
| 174 |
|
| 175 |
if (!array_key_exists("allcaps", $user)) { |
| 176 |
throw new WPRProtectRuleError_V676( |
| 177 |
$this->addExState("getUserCapabilities: allcaps doesn't exist in user.") |
| 178 |
); |
| 179 |
} |
| 180 |
|
| 181 |
return WPRProtectFWRuleEngine_V676::toAllowedType($user["allcaps"]); |
| 182 |
} |
| 183 |
|
| 184 |
private function _rf_getDefaultUserRole() { |
| 185 |
$args = $this->processRuleFunctionParams( |
| 186 |
'getDefaultUserRole', |
| 187 |
func_num_args(), |
| 188 |
func_get_args() |
| 189 |
); |
| 190 |
|
| 191 |
return $this->_rf_getOption('default_role', null); |
| 192 |
} |
| 193 |
|
| 194 |
private function _rf_getOption() { |
| 195 |
$args = $this->processRuleFunctionParams( |
| 196 |
'getOption', |
| 197 |
func_num_args(), |
| 198 |
func_get_args(), |
| 199 |
1, |
| 200 |
['string'] |
| 201 |
); |
| 202 |
$option = $args[0]; |
| 203 |
$default_value = isset($args[1]) ? $args[1] : false; |
| 204 |
|
| 205 |
if (!function_exists('get_option') || !WPRProtectUtils_V676::haveMupluginsLoaded()) { |
| 206 |
throw new WPRProtectRuleError_V676( |
| 207 |
$this->addExState("getOption: Func get_option doesn't exist.") |
| 208 |
); |
| 209 |
} |
| 210 |
|
| 211 |
return WPRProtectFWRuleEngine_V676::toAllowedType(get_option($option, $default_value)); |
| 212 |
} |
| 213 |
|
| 214 |
private function _rf_checkPasswordResetKey() { |
| 215 |
$args = $this->processRuleFunctionParams( |
| 216 |
'checkPasswordResetKey', |
| 217 |
func_num_args(), |
| 218 |
func_get_args(), |
| 219 |
2, |
| 220 |
['string', 'string'] |
| 221 |
); |
| 222 |
$key = $args[0]; |
| 223 |
$login = $args[1]; |
| 224 |
|
| 225 |
if (!function_exists('check_password_reset_key') || !WPRProtectUtils_V676::havePluginsLoaded()) { |
| 226 |
throw new WPRProtectRuleError_V676( |
| 227 |
$this->addExState("checkPasswordResetKey: Func check_password_reset_key doesn't exist.") |
| 228 |
); |
| 229 |
} |
| 230 |
|
| 231 |
$user = check_password_reset_key($key, $login); |
| 232 |
|
| 233 |
if (is_a($user, "WP_User")) { |
| 234 |
return WPRProtectFWRuleEngine_V676::toAllowedType($user); |
| 235 |
} |
| 236 |
|
| 237 |
return null; |
| 238 |
} |
| 239 |
|
| 240 |
private function _rf_isActivationKeyValid() { |
| 241 |
$args = $this->processRuleFunctionParams( |
| 242 |
'isActivationKeyValid', |
| 243 |
func_num_args(), |
| 244 |
func_get_args(), |
| 245 |
2, |
| 246 |
['string', 'string'] |
| 247 |
); |
| 248 |
$key = $args[0]; |
| 249 |
$user_login = $args[1]; |
| 250 |
|
| 251 |
if (is_array($this->_rf_checkPasswordResetKey($key, $user_login))) { |
| 252 |
return true; |
| 253 |
} |
| 254 |
|
| 255 |
return false; |
| 256 |
} |
| 257 |
|
| 258 |
private function _rf_hasValidActivationKey() { |
| 259 |
$args = $this->processRuleFunctionParams( |
| 260 |
'hasValidActivationKey', |
| 261 |
func_num_args(), |
| 262 |
func_get_args(), |
| 263 |
2, |
| 264 |
['array', 'string'] |
| 265 |
); |
| 266 |
$params = $args[0]; |
| 267 |
$user_login = $args[1]; |
| 268 |
|
| 269 |
foreach ($params as $key => $value) { |
| 270 |
if (is_array($value) && $this->_rf_hasValidActivationKey($value, $user_login)) { |
| 271 |
return true; |
| 272 |
} elseif (is_string($value) && $this->_rf_isActivationKeyValid($value, $user_login)) { |
| 273 |
return true; |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
return false; |
| 278 |
} |
| 279 |
|
| 280 |
private function _rf_wpUnslash() { |
| 281 |
$args = $this->processRuleFunctionParams( |
| 282 |
'wpUnslash', |
| 283 |
func_num_args(), |
| 284 |
func_get_args(), |
| 285 |
1 |
| 286 |
); |
| 287 |
$value = $args[0]; |
| 288 |
|
| 289 |
if (!function_exists('wp_unslash') || !WPRProtectUtils_V676::haveMuPluginsLoaded()) { |
| 290 |
throw new WPRProtectRuleError_V676( |
| 291 |
$this->addExState("wpUnslash: Func wp_unslash doesn't exist.") |
| 292 |
); |
| 293 |
} |
| 294 |
|
| 295 |
if (!is_string($value) && !is_array($value)) { |
| 296 |
throw new WPRProtectRuleError_V676( |
| 297 |
$this->addExState("wpUnslash: Value must be a valid string or an array") |
| 298 |
); |
| 299 |
} |
| 300 |
|
| 301 |
return wp_unslash($value); |
| 302 |
} |
| 303 |
|
| 304 |
private function _rf_parseResetPassCookie() { |
| 305 |
$args = $this->processRuleFunctionParams( |
| 306 |
'parseResetPassCookie', |
| 307 |
func_num_args(), |
| 308 |
func_get_args() |
| 309 |
); |
| 310 |
|
| 311 |
if (!defined('COOKIEHASH')) { |
| 312 |
throw new WPRProtectRuleError_V676( |
| 313 |
$this->addExState("parseResetPassCookie: COOKIEHASH is not defined.") |
| 314 |
); |
| 315 |
} |
| 316 |
|
| 317 |
$cookie_name = 'wp-resetpass-' . COOKIEHASH; |
| 318 |
$cookies = $this->_rf_getCookiesV2(); |
| 319 |
if (isset($cookies[$cookie_name])) { |
| 320 |
$cookie = $cookies[$cookie_name]; |
| 321 |
} |
| 322 |
|
| 323 |
if (isset($cookie) && is_string($cookie)) { |
| 324 |
$rp_arr = $this->_rf_splitString(':', $this->_rf_wpUnslash($cookie), 2); |
| 325 |
|
| 326 |
if (is_array($rp_arr) && isset($rp_arr[0]) && is_string($rp_arr[0]) && |
| 327 |
isset($rp_arr[1]) && is_string($rp_arr[1])) { |
| 328 |
return array("login" => $rp_arr[0], "key" => $rp_arr[1]); |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
return array("login" => "", "key" => ""); |
| 333 |
} |
| 334 |
} |
| 335 |
endif; |