Skip to content

Actions and filters

Post views: 11 hooks.

Every hook here has a description in the source.

4 actions7 filters

filter

davo_post_view_analytics

Filter the analytics data before it is returned.

Parameters of davo_post_view_analytics
ParameterTypeDescription
$analyticsarray<string, mixed>Analytics payload.
$post_idintPost ID.
$daysintPeriod in days.
add_filter
add_filter( 'davo_post_view_analytics', 'my_filter_callback', 10, 3 );

/**
 * @param array<string, mixed> $analytics
 * @param int $post_id
 * @param int $days
 */
function my_filter_callback( $analytics, $post_id, $days ) {
	// Change $analytics as needed, then return it.
	return $analytics;
}

src/domains/post-views/repository.php:328

filter

davo_post_view_counts

Filter the view counts before they are returned.

Parameters of davo_post_view_counts
ParameterTypeDescription
$countsarray<string, mixed>Normalized counts data.
$post_idintPost ID.
add_filter
add_filter( 'davo_post_view_counts', 'my_filter_callback', 10, 2 );

/**
 * @param array<string, mixed> $counts
 * @param int $post_id
 */
function my_filter_callback( $counts, $post_id ) {
	// Change $counts as needed, then return it.
	return $counts;
}

src/domains/post-views/repository.php:234

action

davo_post_view_tracked

Fires after a view is successfully recorded.

Parameters of davo_post_view_tracked
ParameterTypeDescription
$post_idintPost ID.
$user_idintUser ID (0 = guest).
$visitor_hashstringVisitor identity hash.
$is_uniqueboolWhether this is the visitor's first view.
add_action
add_action( 'davo_post_view_tracked', 'my_action_callback', 10, 4 );

/**
 * @param int $post_id
 * @param int $user_id
 * @param string $visitor_hash
 * @param bool $is_unique
 */
function my_action_callback( $post_id, $user_id, $visitor_hash, $is_unique ) {
	// Your code here.
}

src/domains/post-views/repository.php:206

action

davo_post_views_aggregated

Fires after the batch aggregation job completes.

Parameters of davo_post_views_aggregated
ParameterTypeDescription
$processedintNumber of view records processed.
$postsintNumber of distinct posts updated.
$post_idsint[]IDs of the posts whose counts were just recounted in this batch — listeners that mirror total_views elsewhere (e.g. the Questions domain's trending-score meta) use this to resync only what actually changed, instead of a full custom-table scan.
add_action
add_action( 'davo_post_views_aggregated', 'my_action_callback', 10, 3 );

/**
 * @param int $processed
 * @param int $posts
 * @param int[] $post_ids
 */
function my_action_callback( $processed, $posts, $post_ids ) {
	// Your code here.
}

src/domains/post-views/repository.php:411

filter

davo_post_views_dedup_window

Filters the window, in seconds, in which repeat views of a post by the same visitor are not counted again. Defaults to 1800 (30 minutes).

Parameters of davo_post_views_dedup_window
ParameterTypeDescription
$windowintWindow in seconds.
$post_idintThe viewed post's ID.
$user_idintThe viewer's user ID.

Returns int

add_filter
add_filter( 'davo_post_views_dedup_window', 'my_filter_callback', 10, 3 );

/**
 * @param int $window
 * @param int $post_id
 * @param int $user_id
 */
function my_filter_callback( $window, $post_id, $user_id ) {
	// Change $window as needed, then return it.
	return $window;
}

src/domains/post-views/repository.php:128

action

davo_post_views_deleted_for_post

Fires after all view data for a post has been permanently deleted.

Parameters of davo_post_views_deleted_for_post
ParameterTypeDescription
$post_idintPost ID.
add_action
add_action( 'davo_post_views_deleted_for_post', 'my_action_callback', 10, 1 );

/**
 * @param int $post_id
 */
function my_action_callback( $post_id ) {
	// Your code here.
}

src/domains/post-views/repository.php:544

action

davo_post_views_imported

Fires after a migration import wrote view counts for posts.

Domains that mirror a post's total views elsewhere (post meta, the search index's popularity score) resync from it. Writing the counts directly skips the live view-tracking hooks that normally keep those mirrors current.

Parameters of davo_post_views_imported
ParameterTypeDescription
$post_idsint[]Destination post IDs whose counts were just imported.
add_action
add_action( 'davo_post_views_imported', 'my_action_callback', 10, 1 );

/**
 * @param int[] $post_ids
 */
function my_action_callback( $post_ids ) {
	// Your code here.
}

src/domains/post-views/migration-provider.php:265

filter

davo_post_views_is_bot

Filter whether a user agent is classified as a bot.

Parameters of davo_post_views_is_bot
ParameterTypeDescription
$is_botboolCurrent classification result.
$user_agentstringUser-Agent string.
add_filter
add_filter( 'davo_post_views_is_bot', 'my_filter_callback', 10, 2 );

/**
 * @param bool $is_bot
 * @param string $user_agent
 */
function my_filter_callback( $is_bot, $user_agent ) {
	// Change $is_bot as needed, then return it.
	return $is_bot;
}

src/domains/post-views/repository.php:751

filter

davo_post_views_is_duplicate

Filter whether the current view should be counted despite deduplication. Return true to force-count, false to force-skip.

Parameters of davo_post_views_is_duplicate
ParameterTypeDescription
$is_duplicateboolWhether a duplicate was detected.
$post_idintPost being viewed.
$user_idintCurrent user (0 = guest).
$visitor_hashstringVisitor identity hash.
add_filter
add_filter( 'davo_post_views_is_duplicate', 'my_filter_callback', 10, 4 );

/**
 * @param bool $is_duplicate
 * @param int $post_id
 * @param int $user_id
 * @param string $visitor_hash
 */
function my_filter_callback( $is_duplicate, $post_id, $user_id, $visitor_hash ) {
	// Change $is_duplicate as needed, then return it.
	return $is_duplicate;
}

src/domains/post-views/repository.php:146

filter

davo_post_views_log_retention_days

Filters how many days post view logs are kept before the daily housekeeping removes them. Defaults to 90.

Parameters of davo_post_views_log_retention_days
ParameterTypeDescription
$daysintRetention in days.

Returns int

add_filter
add_filter( 'davo_post_views_log_retention_days', 'my_filter_callback', 10, 1 );

/**
 * @param int $days
 */
function my_filter_callback( $days ) {
	// Change $days as needed, then return it.
	return $days;
}

src/domains/post-views/initializer.php:180

filter

davo_post_views_supported_post_types

Filter the post types that are tracked for views.

Parameters of davo_post_views_supported_post_types
ParameterTypeDescription
$post_typesstring[]Array of post type slugs.
add_filter
add_filter( 'davo_post_views_supported_post_types', 'my_filter_callback', 10, 1 );

/**
 * @param string[] $post_types
 */
function my_filter_callback( $post_types ) {
	// Change $post_types as needed, then return it.
	return $post_types;
}

src/domains/post-views/repository.php:58

Note. Generated from the plugin source. Descriptions and parameters are the ones written in the code. The starter code uses the parameter names from those comments, or generic names where there are none, so check them against your use.

See it on your own site.

Davo is a WordPress theme and plugin by Exorex.

  • Runs on your own WordPress
  • Guided setup wizard
  • AI is off until you switch it on
  • Read the licence on the marketplace first