ap_insert_reputation( string $event, integer $ref_id, integer|boolean $user_id = false )
Description #
Insert reputation.
Parameters #
- $eventstring (Required) Event type.
- $ref_idinteger (Required) Reference ID (post or comment ID).
- $user_idinteger | boolean (Optional) User ID. Default value: false
Source #
File: includes/reputation.php
function ap_insert_reputation( $event, $ref_id, $user_id = false ) {
// Don't do insert notification if defined.
if ( defined( 'AP_DISABLE_INSERT_REP' ) && AP_DISABLE_INSERT_REP ) {
return;
}
global $wpdb;
if ( false === $user_id ) {
$user_id = get_current_user_id();
}
if ( empty( $user_id ) || empty( $event ) ) {
return false;
}
$insert = $wpdb->insert( // phpcs:ignore WordPress.DB
$wpdb->ap_reputations,
array(
'rep_user_id' => $user_id,
'rep_event' => sanitize_text_field( $event ),
'rep_ref_id' => $ref_id,
'rep_date' => current_time( 'mysql', true ),
),
array( '%d', '%s', '%d', '%s' )
);
if ( false === $insert ) {
return false;
}
$new_id = $wpdb->insert_id;
// Update user meta.
ap_update_user_reputation_meta( $user_id );
/**
* Trigger action after inserting a reputation.
*/
do_action( 'ap_insert_reputation', $new_id, $user_id, $event, $ref_id );
return $new_id;
}
Expand full source code Collapse full source code View on GitHub: includes/reputation.php:29
Add your comment