ap_vote_insert( integer $post_id, integer $user_id, string $type = 'vote', integer|false $rec_user_id, string $value = '', string|false $date = false )

Description #

Insert vote in ap_votes table.

Parameters #

  • $post_id
    integer (Required) Post ID.
  • $user_id
    integer (Required) ID of user casting voting.
  • $type
    string (Optional) Type of vote. Default value: 'vote'
  • $rec_user_id
    integer | false (Required) Id of user receiving vote.
  • $value
    string (Optional) Value of vote. Default value: ''
  • $date
    string | false (Optional) Date of vote, default is current time. Default value: false

Source #

File: includes/votes.php

function ap_vote_insert( $post_id, $user_id, $type = 'vote', $rec_user_id = 0, $value = '', $date = false ) {
	if ( false === $date ) {
		$date = current_time( 'mysql' );
	}

	if ( false === $user_id ) {
		$user_id = get_current_user_id();
	}

	global $wpdb;
	$args = array(
		'vote_post_id'  => $post_id,
		'vote_user_id'  => $user_id,
		'vote_rec_user' => $rec_user_id,
		'vote_type'     => $type,
		'vote_value'    => $value,
		'vote_date'     => $date,
	);

	$inserted = $wpdb->insert( $wpdb->ap_votes, $args, array( '%d', '%d', '%d', '%s', '%s', '%s' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery

	if ( $inserted ) {
		/**
		 * Action triggered after inserting a vote.
		 *
		 * @param array $args Vote arguments.
		 * @since  4.0.0
		 */
		do_action( 'ap_insert_vote', $args );

		return true;
	}

	return false;
}

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