$entry ) { if ( $entry['code'] === $code && $entry['message'] === $message && $now - $entry['time'] < DAY_IN_SECONDS ) { $entry['count'] = isset( $entry['count'] ) ? $entry['count'] + 1 : 2; $entry['time'] = $now; unset( $log[ $i ] ); array_unshift( $log, $entry ); update_option( self::OPTION, array_values( $log ), false ); return; } } array_unshift( $log, array( 'time' => $now, 'level' => $level, 'code' => $code, 'message' => $message, 'count' => 1, ) ); update_option( self::OPTION, array_slice( $log, 0, self::MAX ), false ); } /** * Log at most once per hour for a given code (for conditions that could repeat on every request). * * @param string $level Level. * @param string $code Code. * @param string $message Message. */ public static function throttled( $level, $code, $message ) { $key = 'aiom_log_' . md5( $code . $message ); if ( get_transient( $key ) ) { return; } set_transient( $key, 1, HOUR_IN_SECONDS ); self::add( $level, $code, $message ); } /** * Remove server paths. * * @param string $s Text. * @return string */ public static function redact( $s ) { $s = str_replace( '\\', '/', $s ); return str_replace( array( wp_normalize_path( WP_CONTENT_DIR ), wp_normalize_path( untrailingslashit( ABSPATH ) ) ), array( 'wp-content', '' ), $s ); } /** * Entries, newest first. * * @return array */ public static function entries() { $log = get_option( self::OPTION, array() ); return is_array( $log ) ? $log : array(); } /** * Clear the log. */ public static function clear() { delete_option( self::OPTION ); } }