Skip to content

Actions and filters

Likes: 10 hooks.

Every hook here has a description in the source.

3 actions7 filters

action

davo_like_added

Fires after a like is successfully added.

Parameters of davo_like_added
ParameterTypeDescription
$user_idintThe user who liked.
$target_idintThe liked target ID.
$target_typestringTarget type slug ('post', 'video', 'comment', etc.).
$object_typestring'post_type' or 'comment'.
$new_countintTotal likes after this action.
add_action
add_action( 'davo_like_added', 'my_action_callback', 10, 5 );

/**
 * @param int $user_id
 * @param int $target_id
 * @param string $target_type
 * @param string $object_type
 * @param int $new_count
 */
function my_action_callback( $user_id, $target_id, $target_type, $object_type, $new_count ) {
	// Your code here.
}

src/domains/likes/repository.php:389

action

davo_like_removed

Fires after a like is successfully removed.

Parameters of davo_like_removed
ParameterTypeDescription
$user_idintThe user who unliked.
$target_idintThe unliked target ID.
$target_typestringTarget type slug ('post', 'video', 'comment', etc.).
$object_typestring'post_type' or 'comment'.
$new_countintTotal likes after this action.
add_action
add_action( 'davo_like_removed', 'my_action_callback', 10, 5 );

/**
 * @param int $user_id
 * @param int $target_id
 * @param string $target_type
 * @param string $object_type
 * @param int $new_count
 */
function my_action_callback( $user_id, $target_id, $target_type, $object_type, $new_count ) {
	// Your code here.
}

src/domains/likes/repository.php:470

filter

davo_like_trending_decay

Filters the trending score decay value. Increase the exponent to penalise older posts more aggressively.

Parameters of davo_like_trending_decay
ParameterTypeDescription
$decayfloatComputed decay divisor.
$target_idintPost ID.
$target_typestringPost type slug.
add_filter
add_filter( 'davo_like_trending_decay', 'my_filter_callback', 10, 3 );

/**
 * @param float $decay
 * @param int $target_id
 * @param string $target_type
 */
function my_filter_callback( $decay, $target_id, $target_type ) {
	// Change $decay as needed, then return it.
	return $decay;
}

src/domains/likes/repository.php:533

filter

davo_like_trending_score

Filters the final trending score before it is stored.

Parameters of davo_like_trending_score
ParameterTypeDescription
$scorefloatComputed score.
$target_idintPost ID.
$target_typestringPost type slug.
$countintCurrent like count.
add_filter
add_filter( 'davo_like_trending_score', 'my_filter_callback', 10, 4 );

/**
 * @param float $score
 * @param int $target_id
 * @param string $target_type
 * @param int $count
 */
function my_filter_callback( $score, $target_id, $target_type, $count ) {
	// Change $score as needed, then return it.
	return $score;
}

src/domains/likes/repository.php:545

filter

davo_likes_most_liked

Filters the most-liked results before they are cached and returned.

Parameters of davo_likes_most_liked
ParameterTypeDescription
$resultlist<array<string, mixed>>The computed results.
$target_typestringPost type slug.
$countintRequested result count.
$periodintRolling window in days.
add_filter
add_filter( 'davo_likes_most_liked', 'my_filter_callback', 10, 4 );

/**
 * @param list<array<string, mixed>> $result
 * @param string $target_type
 * @param int $count
 * @param int $period
 */
function my_filter_callback( $result, $target_type, $count, $period ) {
	// Change $result as needed, then return it.
	return $result;
}

src/domains/likes/repository.php:211

filter

davo_likes_most_liked_comments

Filters the most-liked comments before they are cached and returned.

Parameters of davo_likes_most_liked_comments
ParameterTypeDescription
$resultlist<array<string, mixed>>The computed results.
$countintRequested result count.
$post_idint|nullScoped post ID or null.
add_filter
add_filter( 'davo_likes_most_liked_comments', 'my_filter_callback', 10, 3 );

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

src/domains/likes/repository.php:273

filter

davo_likes_resync_batch_size

Filters how many records each run of the like-count resync handles. Defaults to 200.

Parameters of davo_likes_resync_batch_size
ParameterTypeDescription
$sizeintBatch size.

Returns int

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

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

src/domains/likes/crons/resync.php:103

action

davo_likes_resync_complete

Fires after a resync cron run completes.

Parameters of davo_likes_resync_complete
ParameterTypeDescription
$resyncedintNumber of distinct targets resynced this run.
add_action
add_action( 'davo_likes_resync_complete', 'my_action_callback', 10, 1 );

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

src/domains/likes/crons/resync.php:121

filter

davo_likes_target_types

Filters the target types that support likes.

Parameters of davo_likes_target_types
ParameterTypeDescription
$target_typesstring[]Array of target-type slugs (post types + 'comment').
add_filter
add_filter( 'davo_likes_target_types', 'my_filter_callback', 10, 1 );

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

src/domains/likes/helpers.php:71

filter

davo_likes_trending

Filters the trending results before they are cached and returned.

Parameters of davo_likes_trending
ParameterTypeDescription
$resultlist<array<string, mixed>>The computed results.
$target_typestringPost type slug.
$countintRequested result count.
add_filter
add_filter( 'davo_likes_trending', 'my_filter_callback', 10, 3 );

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

src/domains/likes/repository.php:333

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