src/model/admin/class-rating.php
public function set_user_vote( $post_id, $votes, $vote, $ip ) {

		global $wpdb;

		$table_name = $wpdb->prefix . 'efg_custom_rating';

		$result = $wpdb->get_row(
			"
            SELECT id, vote 
            FROM   $table_name 
            WHERE  ip      = '$ip'
            AND    post_id = $post_id
        "
		);

		if ( ! isset( $result->id ) && ! isset( $result->vote ) ) {

			$wpdb->insert(
				$table_name,
				[
					'post_id' => $post_id,
					'ip' => $ip,
					'vote' => $vote,
				],
				[ '%d', '%s', '%d' ]
			);

			$votes[ $vote ]++;

		} else {

			if ( $result->vote != $vote ) {

				$wpdb->update(
					$table_name,
					[
						'post_id' => $post_id,
						'ip' => $ip,
						'vote' => $vote,
					],
					[ 'id' => $result->id ],
					[ '%d', '%s', '%d' ],
					[ '%d' ]
				);

				$votes[ $result->vote ]--;
				$votes[ $vote ]++;
			}
		}

		return $votes;
	}
public function set_user_vote( $post_id, $votes, $vote, $ip ) {

		global $wpdb;

		$table_name = $wpdb->prefix . 'efg_custom_rating';

		$result = $wpdb->get_row(
			"
            SELECT id, vote 
            FROM   $table_name 
            WHERE  ip      = '$ip'
            AND    post_id = $post_id
        "
		);

		if ( ! isset( $result->id ) && ! isset( $result->vote ) ) {

			$wpdb->insert(
				$table_name,
				[
					'post_id' => $post_id,
					'ip' => $ip,
					'vote' => $vote,
				],
				[ '%d', '%s', '%d' ]
			);

			$votes[ $vote ]++;

		} else {

			if ( $result->vote != $vote ) {

				$wpdb->update(
					$table_name,
					[
						'post_id' => $post_id,
						'ip' => $ip,
						'vote' => $vote,
					],
					[ 'id' => $result->id ],
					[ '%d', '%s', '%d' ],
					[ '%d' ]
				);

				$votes[ $result->vote ]--;
				$votes[ $vote ]++;
			}
		}

		return $votes;
	}
Add or update vote and associate to an IP address.

@since 1.0.1

@param string $post_id → post id.
@param array  $votes  → votes.
@param array  $vote   → vote.
@param array  $ip     → ip.

@return array → movie votes