$page), $args), $url); } /** * Name of a plugin table; the suite tables are shared by the whole network */ public static function table($name) { global $wpdb; return $wpdb->base_prefix . 'aowpcs_' . $name; } /** * Current time in UTC as a MySQL datetime (all plugin tables store UTC) */ public static function now() { return gmdate('Y-m-d H:i:s'); } public static function gmt_ago($seconds) { return gmdate('Y-m-d H:i:s', time() - (int) $seconds); } /** * Format a stored UTC datetime in the site's timezone and date format */ public static function format_time($gmt, $with_time = true) { if (empty($gmt) || $gmt === '0000-00-00 00:00:00') { return '—'; } $timestamp = strtotime($gmt . ' UTC'); $format = get_option('date_format') . ($with_time ? ' ' . get_option('time_format') : ''); return wp_date($format, $timestamp); } public static function time_ago($gmt) { if (empty($gmt)) { return '—'; } /* translators: %s: human readable time difference, for example "5 minutes" */ return sprintf(__('%s ago', 'all-in-one-wp-content-security'), human_time_diff(strtotime($gmt . ' UTC'), time())); } /** * Emergency recovery: define('AOWPCS_SAFE_MODE', true) in wp-config.php disables every * blocking and protective action of the plugin (monitoring and scanning keep working) */ public static function safe_mode() { return defined('AOWPCS_SAFE_MODE') && AOWPCS_SAFE_MODE; } /** * Network-aware option helpers */ public static function get_option($name, $default = false) { return is_multisite() ? get_site_option($name, $default) : get_option($name, $default); } public static function update_option($name, $value, $autoload = null) { if (is_multisite()) { return update_site_option($name, $value); } return update_option($name, $value, $autoload); } public static function delete_option($name) { return is_multisite() ? delete_site_option($name) : delete_option($name); } /** * Path relative to the WordPress root, for display (never reveals the absolute server path) */ public static function relative_path($path) { $path = wp_normalize_path($path); $root = wp_normalize_path(ABSPATH); if (strpos($path, $root) === 0) { return ltrim(substr($path, strlen($root)), '/'); } $parent = wp_normalize_path(dirname(ABSPATH)) . '/'; if (strpos($path, $parent) === 0) { return '../' . ltrim(substr($path, strlen($parent)), '/'); } return basename($path); } /** * Whether the site declares itself as a production site */ public static function is_production() { return wp_get_environment_type() === 'production'; } /** * Severity helpers */ public static function severities() { return array( 'critical' => __('Critical', 'all-in-one-wp-content-security'), 'high' => __('High', 'all-in-one-wp-content-security'), 'medium' => __('Medium', 'all-in-one-wp-content-security'), 'low' => __('Low', 'all-in-one-wp-content-security'), ); } public static function severity_rank($severity) { $ranks = array('critical' => 4, 'high' => 3, 'medium' => 2, 'low' => 1); return isset($ranks[$severity]) ? $ranks[$severity] : 0; } public static function categories() { return array( 'core' => __('WordPress core', 'all-in-one-wp-content-security'), 'php' => __('PHP', 'all-in-one-wp-content-security'), 'database' => __('Database', 'all-in-one-wp-content-security'), 'filesystem' => __('Filesystem', 'all-in-one-wp-content-security'), 'extensions' => __('Plugins & themes', 'all-in-one-wp-content-security'), 'integrity' => __('File integrity', 'all-in-one-wp-content-security'), 'server' => __('Web server', 'all-in-one-wp-content-security'), 'traffic' => __('Traffic', 'all-in-one-wp-content-security'), ); } public static function category_label($category) { $all = self::categories(); return isset($all[$category]) ? $all[$category] : $category; } /** * Random token, hex encoded */ public static function token($bytes = 16) { return bin2hex(random_bytes($bytes)); } /** * Secret key derived from the site salts (used to pseudonymise IP addresses) */ public static function secret() { return hash_hmac('sha256', 'aowpcs', wp_salt('auth')); } }