WP-CLI commands

Simple History comes with some useful WP-CLI commands. With them you can for example view and search the events log.

Commands overview

The current WP-CLI commands for interacting with the events log are as follows:

  • wp simple-history list to list events.
  • wp simple-history event list to list events (alias of first command)
  • wp simple-history event get to get details about a single event.
  • wp simple-history event add to add an entry manually.
  • wp simple-history event search to search events.
  • wp simple-history db stats to get stats.
  • wp simple-history db clear to clear the events database.

See below for an explanation of each command.

WP-CLI event list command

List the latest events.

WP-CLI event get command

Get information about a specific log entry.

WP-CLI event add command

Add a custom entry manually. This can be used to document important changes by creating custom log entries for team actions, content updates, or system changes that aren’t automatically tracked.

To add events using a GUI you can use the premium add-on.

WP-CLI search command

The search command searches the log for any word. In the example below we search for all events that contain the word “WooCommerce”:

WP-CLI db commands

The new “stats” and “clear” commands are used to interact with the database.

❯ wp simple-history db
usage: wp simple-history db clear
or: wp simple-history db stats [--format=]Code language: plaintext (plaintext)

The “stats” command gives you some short information about the sizes, in mb and in row count, of the databases that Simple History uses:

❯ wp simple-history db stats
+-----------------------------------+------------+----------+
| table_name                        | size_in_mb | num_rows |
+-----------------------------------+------------+----------+
| wp_stable_simple_history          | 0.34       | 1143     |
| wp_stable_simple_history_contexts | 6.20       | 12151    |
+-----------------------------------+------------+----------+

WP-CLI get command

The get command retrieves detailed information about a single event:

❯ wp simple-history get 1072
+-----------------------------+-------------------------------------------------------------+
| Field                       | Value                                                       |
+-----------------------------+-------------------------------------------------------------+
| ID                          | 1072                                                        |
| date                        | 2024-02-26 07:13:19                                         |
| initiator                   | WordPress                                                   |
| message                     | WordPress auto-updated to 6.4.3 from 6.4.2                  |
| via                         | null                                                        |
| logger                      | SimpleCoreUpdatesLogger                                     |
| level                       | notice                                                      |
| count                       | 1                                                           |
| _message_key                | core_auto_updated                                           |
| _message                    | WordPress auto-updated to {new_version} from {prev_version} |
| _initiator                  | wp                                                          |
| context_prev_version        | 6.4.2                                                       |
| context_new_version         | 6.4.3                                                       |
| context__message_key        | core_auto_updated                                           |
| context__wp_cron_running    | true                                                        |
| context__server_remote_addr | 127.0.0.1                                                   |
+-----------------------------+-------------------------------------------------------------+

Code language: plaintext (plaintext)

The clear command removes all items from the database:

❯ wp simple-history db clear
Are you sure you want to clear all logged items? [y/n] y
Success: Removed 1145 rows.Code language: plaintext (plaintext)