Skip to content

Custom Activity Types

John James Jacoby edited this page Sep 16, 2026 · 1 revision

Custom Activity Types

Extensions can add object types by defining a class that extends WP_User_Activity_Type and adding its class name to the default type list.

add_filter( 'wp_get_default_user_activity_types', function ( $types ) {
	$types[] = 'My_Project_Activity_Type';
	return $types;
} );

The class should define a stable $object_type, name, icon, action callbacks, and the WordPress hooks that detect each event. The bundled taxonomy activity class is a compact reference implementation.

Insert an entry directly

wp_insert_user_activity( array(
	'user_id'        => get_current_user_id(),
	'object_type'    => 'project',
	'object_subtype' => 'client-project',
	'object_name'    => 'Website redesign',
	'object_id'      => 42,
	'action'         => 'update',
) );

Register a formatter for the type and action so the administration log can render a useful sentence:

wp_user_activity_register_action_callback(
	'project',
	'update',
	'my_project_activity_message'
);

Bypass insertion

wp_pre_insert_user_activity can return a truthy value to prevent an entry. Use it for deliberate exclusions, automated migrations, or duplicate suppression; avoid broad filters that silently remove security-relevant events.

Clone this wiki locally