ap_delete_vote( integer $post_id, integer|boolean $user_id = false, string|array $type = 'vote', string $value = false )

Description #

Delete vote from database.

Parameters #

  • $post_id
    integer (Required) Post ID.
  • $user_id
    integer | boolean (Optional) User ID. Default value: false
  • $type
    string | array (Optional) Vote type. Default value: 'vote'
  • $value
    string (Optional) Vote value. Default value: false

Source #

File: includes/votes.php

function ap_delete_vote( $post_id, $user_id = false, $type = 'vote', $value = false ) {
	global $wpdb;

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

	$where = array(
		'vote_post_id' => $post_id,
		'vote_user_id' => $user_id,
		'vote_type'    => $type,
	);

	if ( false !== $value ) {
		$where['vote_value'] = $value;
	}

	$row = $wpdb->delete( $wpdb->ap_votes, $where ); // phpcs:ignore WordPress.DB

	if ( false !== $row ) {
		do_action( 'ap_delete_vote', $post_id, $user_id, $type, $value );
	}

	return $row;
}

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