{ $htaccessContent = file_get_contents($htaccessFile); } if (empty($htaccessContent)) { return false; } //if isset expires header in htacces if (strpos($htaccessContent, 'mod_expires') !== false || strpos($htaccessContent, 'ExpiresActive') !== false || strpos($htaccessContent, 'ExpiresDefault') !== false || strpos($htaccessContent, 'ExpiresByType') !== false) { return false; } $htaccessContent = $expires . $htaccessContent; file_put_contents($htaccessFile, $htaccessContent); return true; } else { if (!is_super_admin()) { return false; } //open htaccess file if (is_writable($htaccessFile)) { $htaccessContent = file_get_contents($htaccessFile); } if (empty($htaccessContent)) { return false; } $htaccessContent = str_replace($expires, '', $htaccessContent); file_put_contents($htaccessFile, $htaccessContent); return true; } } /** * Remove query string from static resources * * @param string $content Content raw * * @return mixed */ public function removeQueryStrings($content) { if ($content !== '') { $blog_regexp = self::blogDomainRootUrlRegexp(); if (!$blog_regexp) { return $content; } $pattern = '~(href|src)=?([\'"])((' . $blog_regexp . ')?(/[^\'"/][^\'"]*\.([a-z-_]+)([\?#][^\'"]*)?))[\'"]~Ui'; $content = preg_replace_callback( $pattern, array($this, 'queryStringsReplaceCallback'), $content ); } return $content; } /** * Callback replace for js and css file * * @param string $matches Matches of query string * * @return string */ public function queryStringsReplaceCallback($matches) { list ($match, $attr, $quote, $url, , , $extension) = $matches; if ($extension === 'js' || $extension === 'css') { $url = preg_replace('/[&\?]+(ver=([a-z0-9-_\.]+|[0-9-]+))+[&\?]*([a-z0-9-_=]*)*/i', '', $url); } return $attr . '=' . $quote . $url . $quote; } /** * Returns domain url regexp * * @return string */ public static function blogDomainRootUrlRegexp() { $home_url = get_option('home'); $parse_url = parse_url($home_url); if ($parse_url && isset($parse_url['scheme']) && isset($parse_url['host'])) { $scheme = $parse_url['scheme']; $host = $parse_url['host']; $port = (isset($parse_url['port']) && $parse_url['port'] !== 80 ? ':' . (int)$parse_url['port'] : ''); $domain_url = sprintf('[%s:]*//%s%s', $scheme, $host, $port); return $domain_url; } return false; } /** * Parse module info. * Based on https://gist.github.com/sbmzhcn/6255314 * * @return array */ public static function parsePhpinfo() { ob_start(); //phpcs:ignore WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_phpinfo -- Get info modules of phpinfo phpinfo(INFO_MODULES); $s = ob_get_contents(); ob_end_clean(); $s = strip_tags($s, '