ap_get_votes( array|integer $args = array() )
Description #
Return votes.
Parameters #
- $argsarray | integer (Optional) Arguments or vote_post_id. Default value: array()
Source #
File: includes/votes.php
function ap_get_votes( $args = array() ) {
if ( ! is_array( $args ) ) {
$args = array( 'vote_post_id' => (int) $args );
}
global $wpdb;
$where = "SELECT * FROM {$wpdb->ap_votes} WHERE 1=1";
// Single or multiple posts.
if ( isset( $args['vote_post_id'] ) && ! empty( $args['vote_post_id'] ) ) {
if ( is_array( $args['vote_post_id'] ) ) {
$in_str = sanitize_comma_delimited( $args['vote_post_id'] );
if ( ! empty( $in_str ) ) {
$where .= ' AND vote_post_id IN (' . $in_str . ')';
}
} else {
$where .= ' AND vote_post_id = ' . (int) $args['vote_post_id'];
}
}
// Single or multiple users.
if ( isset( $args['vote_user_id'] ) && ! empty( $args['vote_user_id'] ) ) {
if ( is_array( $args['vote_user_id'] ) ) {
$in_str = sanitize_comma_delimited( $args['vote_user_id'] );
if ( ! empty( $in_str ) ) {
$where .= ' AND vote_user_id IN (' . $in_str . ')';
}
} else {
$where .= ' AND vote_user_id = ' . (int) $args['vote_user_id'];
}
}
// Vote actors.
if ( isset( $args['vote_actor_id'] ) && ! empty( $args['vote_actor_id'] ) ) {
if ( is_array( $args['vote_actor_id'] ) ) {
$in_str = sanitize_comma_delimited( $args['vote_actor_id'] );
if ( ! empty( $in_str ) ) {
$where .= ' AND vote_actor_id IN (' . $in_str . ')';
}
} else {
$where .= ' AND vote_actor_id = ' . (int) $args['vote_actor_id'];
}
}
// Single or multiple vote types.
if ( isset( $args['vote_type'] ) && ! empty( $args['vote_type'] ) ) {
if ( is_array( $args['vote_type'] ) ) {
$vote_type_in = sanitize_comma_delimited( $args['vote_type'], 'str' );
if ( ! empty( $vote_type_in ) ) {
$where .= ' AND vote_type IN (' . $vote_type_in . ')';
}
} else {
$where .= $wpdb->prepare( ' AND vote_type = %s', $args['vote_type'] );
}
}
$results = $wpdb->get_results( $where ); // phpcs:ignore WordPress.DB
return ! is_array( $results ) ? array() : $results;
}
Expand full source code Collapse full source code View on GitHub: includes/votes.php:205
Add your comment