= self::bvInetPton($start_ip_range) && $bin_ip <= self::bvInetPton($end_ip_range)) { return true; } return false; } public static function isPrivateIP($ip) { $private_ip_ranges = array( array("10.0.0.0", "10.255.255.255"), array("172.16.0.0", "172.31.255.255"), array("192.168.0.0", "192.168.255.255"), array("127.0.0.1", "127.255.255.255"), array("::1","::1"), array("fc00::","fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff") ); $result = false; foreach ($private_ip_ranges as $ip_range) { $result = self::isIPInRange($ip_range[0], $ip_range[1], $ip); if($result) { return $result; } } return $result; } public static function rrmdir($dir) { if (WPRWPFileSystem::getInstance()->isDir($dir) === true) { WPRWPFileSystem::getInstance()->rmdir($dir, true); } } public static function getLength($val) { $length = 0; if (is_array($val)) { foreach ($val as $e) { $length += WPRProtectUtils_V636::getLength($e); } return $length; } else { return strlen((string) $val); } } public static function parseFile($fname) { $result = array(); if (file_exists($fname)) { $content = file_get_contents($fname); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents if (($content !== false) && is_string($content)) { $result = json_decode($content, true); if (!is_array($result)) { $result = array(); } } } return $result; } public static function fileRemovePattern($fname, $pattern, $regex_pattern = false) { if (WPRWPFileSystem::getInstance()->exists($fname) === false) { return; } $content = WPRWPFileSystem::getInstance()->getContents($fname); if ($content !== false) { if ($regex_pattern) { $modified_content = preg_replace($pattern, "", $content); } else { $modified_content = str_replace($pattern, "", $content); } if ($content !== $modified_content) { WPRWPFileSystem::getInstance()->putContents($fname, $modified_content, WPRWPFileSystem::getInstance()->getchmodOctal($fname)); } } } public static function havePluginsLoaded() { return (function_exists('did_action') && (did_action('plugins_loaded') > 0)); } public static function haveMupluginsLoaded() { return (function_exists('did_action') && (did_action('muplugins_loaded') > 0)); } public static function isWPVersionCompatible($required) { global $wp_version; // Strip off any -alpha, -RC, -beta, -src suffixes. list( $version ) = explode( '-', $wp_version ); return empty( $required ) || version_compare( $version, $required, '>=' ); } public static function preInitWPHook($hook_name, $function_name, $priority, $accepted_args) { global $wp_filter; // Check if $wp_filter is not initialized or not an array if (!isset($wp_filter) || !is_array($wp_filter)) { $wp_filter = array(); } // Check if the hook exists in $wp_filter if (!isset($wp_filter[$hook_name])) { $wp_filter[$hook_name] = array(); } // Check if the priority exists for the hook if (!isset($wp_filter[$hook_name][$priority])) { $wp_filter[$hook_name][$priority] = array(); } // Add the filter function information to the $wp_filter array $wp_filter[$hook_name][$priority][] = array( 'function' => $function_name, 'accepted_args' => $accepted_args, ); } public static function signMessage($message, $key, $algorithm = 'sha256') { if (!is_string($message) || !is_string($key)) { return false; } return hash_hmac($algorithm, $message, $key); } public static function verifyMessage($message, $signature, $key, $algorithm = 'sha256') { if (!is_string($message) || !is_string($signature) || !is_string($key)) { return false; } $calc_signature = self::signMessage($message, $key, $algorithm); return hash_equals($calc_signature, $signature); } public static function safeDecodeJSON($str, $associative = true, $depth = 512) { $decoded_data = @json_decode($str, $associative, $depth); if (isset($decoded_data)) { return $decoded_data; } } } endif;