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
- da_r_after_delete_user_reaction
- da_r_after_insert_user_reaction
- da_r_after_update_reaction
- da_r_before_create_reaction
- da_r_before_delete_user_reaction
- da_r_before_insert_user_reaction
- da_r_before_update_or_create_reaction
- da_r_before_update_reaction
da_r_after_create_reaction
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_id | The ID of the reaction in database |
$reaction | The 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
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_id | The ID of the item (i.e. the post ID) |
$item_type | The object type, such as ‘post’ or ‘comment’ |
$user_token | The 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
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_id | The ID of the item (i.e. the post ID) |
$item_type | The object type, such as ‘post’ or ‘comment’ |
$reaction | The reaction object |
$result | true 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
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_id | The ID of the reaction in the database |
$reaction | The reaction object |
$previous_reaction | The 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
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:
$reaction | The 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
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_id | The ID of the item (i.e. the post ID) |
$item_type | The object type, such as ‘post’ or ‘comment’ |
$user_token | The 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
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_id | The ID of the item (i.e. the post ID) |
$item_type | The object type, such as ‘post’ or ‘comment’ |
$reaction | The 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
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_id | The ID of the reaction, if exists |
$reaction | The 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
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_id | The ID of the item (i.e. the post ID) |
$item_type | The object type, such as ‘post’ or ‘comment’ |
$user_token | The 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 );