ap_insert_reputation( string $event, integer $ref_id, integer|boolean $user_id = false )

Description #

Insert reputation.

Parameters #

  • $event
    string (Required) Event type.
  • $ref_id
    integer (Required) Reference ID (post or comment ID).
  • $user_id
    integer | 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;
}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment