Action hooks

Action hooks are used to execute a task when something else is happening.

DaReactions adds several action hooks since version 4.0.0

da_r_after_create_reaction

Top ↑

This hook is called just after a newly created Reaction is added to the database (i.e. when an administrator creates a new Reaction from the Reaction Manager page).

Source:

do_action( 'da_r_after_create_reaction', $reaction_id, $reaction );

Params:

$reaction_idThe ID of the reaction in database
$reactionThe reaction object

Usage:

function admin_has_created_reaction( $reaction_id, $reaction ) {
	/// ... do something.
}
add_action( 'da_r_after_create_reaction', 'admin_has_created_reaction', 10, 2 );

da_r_after_delete_user_reaction

Top ↑

This hook is called just after a vote is deleted from database, this happens usually because the user are allowed to remove their own votes.

Source:

do_action( 'da_r_after_delete_user_reaction', $item_id, $item_type, $user_token );

Params:

$item_idThe ID of the item (i.e. the post ID)
$item_typeThe object type, such as ‘post’ or ‘comment’
$user_tokenThe unique identifier for the user

Usage:

function user_has_deleted_vote( $item_id, $item_type, $user_token ) {
	/// ... do something.
}
add_action( 'da_r_after_delete_user_reaction', 'user_has_deleted_vote', 10, 3 );

da_r_after_insert_user_reaction

Top ↑

This hook is called just after a vote is inserted into database.

Source:

do_action( 'da_r_after_insert_user_reaction', $item_id, $item_type, $reaction, $result );

Params:

$item_idThe ID of the item (i.e. the post ID)
$item_typeThe object type, such as ‘post’ or ‘comment’
$reactionThe reaction object
$resulttrue or Error

Usage:

function user_has_voted( $item_id, $item_type, $reaction, $result ) {
	/// ... do something.
}
add_action( 'da_r_after_insert_user_reaction', 'user_has_voted', 10, 4 );

da_r_after_update_reaction

Top ↑

This hook is called just after an existing Reaction is updated in the database (i.e. when an administrator edit the Reaction from the Reaction Manager page).

Source:

do_action( 'da_r_after_update_reaction', $reaction_id, $reaction, $current_reaction );

Params:

$reaction_idThe ID of the reaction in the database
$reactionThe reaction object
$previous_reactionThe previous reaction object

Usage:

function admin_has_updated_reaction( $reaction_id, $reaction, $previous_reaction ) {
	/// ... do something.
}
add_action( 'da_r_after_update_reaction', 'admin_has_updated_reaction', 10, 3 );

da_r_before_create_reaction

Top ↑

This hook is called just before a newly created Reaction is added to the database (i.e. when an administrator creates a new Reaction from the Reaction Manager page).

Source:

do_action( 'da_r_before_create_reaction', $reaction );

Params:

$reactionThe reaction object

Usage:

function admin_is_creating_reaction( $reaction ) {
	/// ... do something.
}
add_action( 'da_r_before_create_reaction', 'admin_is_creating_reaction' );

da_r_before_delete_user_reaction

Top ↑

This hook is called just before a vote is deleted from database, usually because the user is removing their own votes.

Source:

do_action( 'da_r_before_delete_user_reaction', $item_id, $item_type, $user_token );

Params:

$item_idThe ID of the item (i.e. the post ID)
$item_typeThe object type, such as ‘post’ or ‘comment’
$user_tokenThe unique identifier for the user

Usage:

function user_is_deleting_vote( $item_id, $item_type, $user_token ) {
	/// ... do something.
}
add_action( 'da_r_before_delete_user_reaction', 'user_is_deleting_vote', 10, 3 );

da_r_before_insert_user_reaction

Top ↑

This hook is called just before a vote is inserted into database.

Source:

do_action( 'da_r_before_insert_user_reaction', $item_id, $item_type, $reaction );

Params:

$item_idThe ID of the item (i.e. the post ID)
$item_typeThe object type, such as ‘post’ or ‘comment’
$reactionThe reaction object

Usage:

function user_is_adding_vote( $item_id, $item_type, $reaction ) {
	/// ... do something.
}
add_action( 'da_r_before_insert_user_reaction', 'user_is_adding_vote', 10, 3 );

da_r_before_update_or_create_reaction

Top ↑

This hook is called when an administrator submit the form in the Reaction Manager page, the reaction object will be saved as new if doesn’t exist or will be updated if exists, based on ID.

Source:

do_action( 'da_r_before_update_or_create_reaction', $reaction_id, $reaction );

Params:

$reaction_idThe ID of the reaction, if exists
$reactionThe reaction object

Usage:

function admin_is_saving_reaction( $reaction_id, $reaction ) {
	/// ... do something.
}
add_action( 'da_r_before_update_or_create_reaction', 'admin_is_saving_reaction', 10, 2 );

da_r_before_update_reaction

Top ↑

This hook is called just after a vote is deleted from database, this happens usually because the user are allowed to remove their own votes.

Source:

do_action( 'da_r_after_delete_user_reaction', $item_id, $item_type, $user_token );

Params:

$item_idThe ID of the item (i.e. the post ID)
$item_typeThe object type, such as ‘post’ or ‘comment’
$user_tokenThe unique identifier for the user

Usage:

function user_has_deleted_vote( $item_id, $item_type, $user_token ) {
	/// ... do something.
}
add_action( 'da_r_after_delete_user_reaction', 'user_has_deleted_vote', 10, 3 );

Top ↑