Build an audit log system in Wordpress

Track changes and user actions in your WordPress site by building an audit log system with Operational.

What is an audit log system in WordPress

An audit log system records changes and actions that occur on your site. It helps you track who did what and when.

For example, you can see when a post was edited and by which author.

What is Operational

Operational is an open source platform to capture events from your app. You can send audit events from WordPress to Operational. This lets you store and view logs in one place.

Setting up Operational

  1. Go to https://app.operational.co and sign up for an account.
  2. Create a new project and copy your API key.
  3. Install the Operational Wordpress plugin or configure API access for PHP.
  4. Get your API key from the settings page and keep it safe somewhere.

Tracking audit events in PHP

(Examples are shown using cURL)

<?php
require 'vendor/autoload.php';

$apiKey = 'YOUR_API_KEY';

$payload = [
    'name' => 'user updated post',
    'avatar' => '✍️',
    'content' => 'John Smith edited post titled “My first blog post”.'
];

$ch = curl_init('https://api.operational.co/v1/events');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Authorization: Bearer ' . $apiKey,
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);

// Now the audit event is sent to Operational
<?php
// Track user login
$payload = [
    'name' => 'user login',
    'avatar' => '🔑',
    'content' => 'Alice logged in to the WordPress dashboard.'
];
// send with curl as before...
<?php
// Track role change
$payload = [
    'name' => 'role changed',
    'avatar' => '🔄',
    'content' => 'Bob was upgraded from subscriber to editor.'
];
// send with curl as before...

This code shows how to send different audit events from WordPress to Operational.

Conclusion

An audit log system helps you monitor actions and changes on your site. Operational makes it easy to collect and view these events.

Learn more at https://operational.co. Try the playground for ready code snippets: https://operational.co/playground