current_time( 'mysql' ), 'type' => $type, 'message' => $message, ); if ( ! empty( $context ) ) { $entry['context'] = $context; } // Prepend new entry. array_unshift( $logs, $entry ); // Trim to max entries. $logs = array_slice( $logs, 0, self::MAX_ENTRIES ); update_option( self::OPTION_KEY, $logs, false ); } /** * Get all log entries. * * @param int $limit Number of entries to retrieve. 0 for all. * @return array */ public static function get_logs( $limit = 0 ) { $logs = get_option( self::OPTION_KEY, array() ); if ( $limit > 0 ) { return array_slice( $logs, 0, $limit ); } return $logs; } /** * Clear all logs. */ public static function clear() { delete_option( self::OPTION_KEY ); } }