function get_user_albums($author_id, $offset, $per_page, $order_by = 'media_id desc')
{
global $wpdb;
if (is_multisite()) {
$order_by = 'blog_id' . ($order_by ? ',' . $order_by : '');
}
$sql = "SELECT * FROM {$this->table_name} ";
if (is_multisite()) {
$sub_sql = $wpdb->prepare("SELECT DISTINCT (album_id) FROM {$this->table_name} WHERE media_author = %d AND album_id IS NOT NULL AND media_type <> 'album' AND context <> 'group' AND blog_id = %d", $author_id, get_current_blog_id());
// @codingStandardsIgnoreLine
} else {
$sub_sql = $wpdb->prepare("SELECT DISTINCT (album_id) FROM {$this->table_name} WHERE media_author = %d AND album_id IS NOT NULL AND media_type <> 'album' AND context <> 'group'", $author_id);
// @codingStandardsIgnoreLine
}
// @codingStandardsIgnoreStart
$where = $wpdb->prepare(" WHERE (id IN( {$sub_sql} ) OR (media_author = %d ))\n\t\t\t AND media_type = 'album'\n\t\t\t AND (context = 'profile' or context is NULL) ", $author_id);
// @codingStandardsIgnoreEnd
if (is_multisite()) {
$where .= $wpdb->prepare(" AND {$this->table_name}.blog_id = %d ", get_current_blog_id());
// @codingStandardsIgnoreStart
}
$where = apply_filters('rtmedia-get-album-where-query', $where, $this->table_name);
$order_by = esc_sql($order_by);
$qorder_by = " ORDER BY {$this->table_name}.{$order_by} ";
$sql .= $where . $qorder_by;
if (false !== $offset) {
if (!is_integer($offset)) {
$offset = 0;
}
if (intval($offset) < 0) {
$offset = 0;
}
if (!is_integer($per_page)) {
$per_page = 1;
}
if (intval($per_page) < 1) {
$per_page = 1;
}
$sql .= ' LIMIT ' . $offset . ',' . $per_page;
}
$results = $wpdb->get_results($sql);
// @codingStandardsIgnoreStart
return $results;
}