function bogo_get_post_translations($post_id = 0)
{
    $post = get_post($post_id);
    if (!$post) {
        return false;
    }
    if ('auto-draft' == $post->post_status) {
        if (!empty($_REQUEST['original_post'])) {
            $original = get_post_meta($_REQUEST['original_post'], '_original_post', true);
            if (empty($original)) {
                $original = (int) $_REQUEST['original_post'];
            }
        } else {
            return false;
        }
    } else {
        $original = get_post_meta($post->ID, '_original_post', true);
    }
    if (empty($original)) {
        $original = $post->ID;
    }
    $args = array('bogo_suppress_locale_query' => true, 'posts_per_page' => -1, 'post_status' => 'any', 'post_type' => $post->post_type, 'meta_key' => '_original_post', 'meta_value' => $original);
    $q = new WP_Query();
    $posts = $q->query($args);
    $translations = array();
    $original_post_status = get_post_status($original);
    if ($original != $post->ID && $original_post_status && 'trash' != $original_post_status) {
        $locale = bogo_get_post_locale($original);
        $translations[$locale] = get_post($original);
    }
    foreach ($posts as $p) {
        if ($p->ID == $post->ID) {
            continue;
        }
        $locale = bogo_get_post_locale($p->ID);
        if (!bogo_is_available_locale($locale)) {
            continue;
        }
        if (!isset($translations[$locale])) {
            $translations[$locale] = $p;
        }
    }
    return array_filter($translations);
}
function bogo_unique_post_slug($slug, $post_id, $status, $type, $parent, $original)
{
    global $wp_rewrite;
    if (!bogo_is_localizable_post_type($type)) {
        return $slug;
    }
    $feeds = is_array($wp_rewrite->feeds) ? $wp_rewrite->feeds : array();
    if (in_array($original, $feeds)) {
        return $slug;
    }
    $locale = bogo_get_post_locale($post_id);
    if (empty($locale)) {
        return $slug;
    }
    $args = array('posts_per_page' => 1, 'post__not_in' => array($post_id), 'post_type' => $type, 'name' => $original, 'lang' => $locale);
    $hierarchical = in_array($type, get_post_types(array('hierarchical' => true)));
    if ($hierarchical) {
        if (preg_match("@^({$wp_rewrite->pagination_base})?\\d+\$@", $original)) {
            return $slug;
        }
        $args['post_parent'] = $parent;
    }
    $q = new WP_Query();
    $posts = $q->query($args);
    if (empty($posts)) {
        $slug = $original;
    }
    return $slug;
}
function bogo_adjacent_post_where($where, $in_same_term, $excluded_terms)
{
    global $wpdb;
    $post = get_post();
    if ($post && bogo_is_localizable_post_type(get_post_type($post))) {
        $locale = bogo_get_post_locale($post->ID);
        $where .= " AND (1=0";
        $where .= $wpdb->prepare(" OR postmeta_bogo.meta_value LIKE %s", $locale);
        if (bogo_is_default_locale($locale)) {
            $where .= " OR postmeta_bogo.meta_id IS NULL";
        }
        $where .= ")";
    }
    return $where;
}
function bogo_get_local_post($post_id)
{
    global $wpdb;
    if (is_admin() || empty($post_id)) {
        return $post_id;
    }
    $post_type = get_post_type($post_id);
    if (!post_type_exists($post_type) || !bogo_is_localizable_post_type($post_type)) {
        return $post_id;
    }
    $locale = get_locale();
    if (bogo_get_post_locale($post_id) == $locale) {
        return $post_id;
    }
    $original = get_post_meta($post_id, '_original_post', true);
    if (empty($original)) {
        $original = $post_id;
    }
    $q = "SELECT ID FROM {$wpdb->posts} AS posts";
    $q .= " LEFT JOIN {$wpdb->postmeta} AS pm1";
    $q .= " ON posts.ID = pm1.post_id AND pm1.meta_key = '_original_post'";
    $q .= " LEFT JOIN {$wpdb->postmeta} AS pm2";
    $q .= " ON posts.ID = pm2.post_id AND pm2.meta_key = '_locale'";
    $q .= " WHERE 1=1";
    $q .= $wpdb->prepare(" AND post_type = %s", $post_type);
    $q .= $wpdb->prepare(" AND (ID = %d OR pm1.meta_value = %d)", $original, $original);
    $q .= " AND (1=0";
    $q .= $wpdb->prepare(" OR pm2.meta_value LIKE %s", $locale);
    $q .= bogo_is_default_locale($locale) ? " OR pm2.meta_id IS NULL" : "";
    $q .= ")";
    $translation = absint($wpdb->get_var($q));
    if ($translation) {
        return $translation;
    }
    return $post_id;
}