Пример #1
2
/**
 * Fetch the post of the correct language.
 *
 * @since	2.1.0
 *
 * @param	$post_id	Post ID
 */
function tptn_object_id_cur_lang($post_id)
{
    $return_original_if_missing = false;
    /**
     * Filter to modify if the original language ID is returned.
     *
     * @since	2.2.3
     *
     * @param	bool	$return_original_if_missing
     * @param	int	$post_id	Post ID
     */
    $return_original_if_missing = apply_filters('tptn_wpml_return_original', $return_original_if_missing, $post_id);
    if (function_exists('pll_get_post')) {
        $post_id = pll_get_post($post_id);
    } elseif (function_exists('wpml_object_id_filter')) {
        $post_id = wpml_object_id_filter($post_id, 'any', $return_original_if_missing);
    } elseif (function_exists('icl_object_id')) {
        $post_id = icl_object_id($post_id, 'any', $return_original_if_missing);
    }
    /**
     * Filters object ID for current language (WPML).
     *
     * @since	2.1.0
     *
     * @param	int	$post_id	Post ID
     */
    return apply_filters('tptn_object_id_cur_lang', $post_id);
}
Пример #2
0
function block_shortcode($atts, $content = null)
{
    extract(shortcode_atts(array('id' => ''), $atts));
    // get Page ID by slug
    global $wpdb, $post;
    $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_name = '{$id}'");
    // Polylang support
    if (function_exists('pll_get_post') && pll_get_post($post_id)) {
        $lang_id = pll_get_post($post_id);
        if ($lang_id) {
            $post_id = $lang_id;
        }
    }
    // WPML Support
    if (function_exists('icl_object_id')) {
        $lang_id = icl_object_id($post_id, 'blocks', false, ICL_LANGUAGE_CODE);
        if ($lang_id) {
            $post_id = $lang_id;
        }
    }
    $permalink = get_permalink($post_id);
    if ($post_id) {
        $html = get_post_field('post_content', $post_id);
        // add edit link for admins
        if (current_user_can('edit_pages')) {
            $edit_link = get_edit_post_link($post_id);
            $html = '<div id="block-' . $id . '" class="ux_block"><a class="edit-link" href="' . $edit_link . '&preview_url=' . $post->ID . '">Edit Block</a>' . $html . '</div>';
        }
        $html = do_shortcode($html);
    } else {
        $html = '<p><mark>Block <b>"' . $id . '"</b> not found!</mark></p>';
    }
    return $html;
}
Пример #3
0
 public static function get_slug_pll($slug, $type)
 {
     $id = self::get_id_by_slug($slug, $type);
     $id = pll_get_post($id, pll_current_language());
     $data = get_post($id, ARRAY_A);
     return $data['post_name'];
 }
function footsy()
{
    global $popupBoxen;
    echo $popupBoxen;
    if (class_exists('PLL_Base')) {
        echo '<span id="pylangswitcher">';
        //  echo '<li><a id="notice-trans" href="#">notice! (08-30)</a></li>';
        // these are the publicly-available languages
        foreach (unserialize(PRODUCTION_LANGUAGES) as $lang) {
            if ($lang != pll_current_language()) {
                echo '<li><a href="' . get_permalink(pll_get_post(get_the_ID(), $lang)) . '">' . $lang . '</a></li>';
            }
        }
        // these are the ones in development
        if (userIsAdmin() || userIsTranslator() || userIsAssistant()) {
            foreach (unserialize(DEVELOPMENT_LANGUAGES) as $lang) {
                if ($lang != pll_current_language()) {
                    echo '<li><a href="' . get_permalink(pll_get_post(get_the_ID(), $lang)) . '">' . $lang . '</a></li>';
                }
            }
        }
        // old method:  echo pll_the_languages(array('echo'=>0,'display_names_as' => 'slug','hide_current' => 1));
        if (userIsAdmin() || userIsTranslator() || userIsAssistant()) {
            echo '<li><a href="' . admin_url('edit.php?post_type=page') . '">' . __t('Editor') . '</a></li>';
        }
        echo '</span>';
    }
}
Пример #5
0
 /**
  * Get product translation by object
  *
  * @param \WC_Product $product the product to use to retirve translation
  * @param string      $slug    the language slug
  *
  * @return \WC_Product product translation or same prodcut if translaion not found
  */
 public static function getProductTranslationByObject(\WC_Product $product, $slug = '')
 {
     $productTranslationID = pll_get_post($product->id, $slug);
     if ($productTranslationID) {
         $translated = wc_get_product($productTranslationID);
         $product = $translated ? $translated : $product;
     }
     return $product;
 }
Пример #6
0
 /**
  * Find the correct login redirect permalink
  *
  * @param string $to redirect url
  *
  * @return string redirect url
  */
 public function getLoginRedirectPermalink($to)
 {
     $ID = url_to_postid($to);
     $translatedID = pll_get_post($ID);
     if ($translatedID) {
         return get_permalink($translatedID);
     }
     return $to;
 }
/**
 * Replaces product listing IDs for different language
 * @param int $listing_id
 * @return int
 */
function replace_product_listing_id($listing_id)
{
    if (function_exists('pll_get_post')) {
        $listing_id = pll_get_post($listing_id);
    }
    if (function_exists('icl_object_id')) {
        $listing_id = icl_object_id($listing_id, 'al_product', true);
    }
    return $listing_id;
}
Пример #8
0
 public static function pll_after_post_column($column, $post_id)
 {
     if (false === strpos($column, 'language_')) {
         return;
     }
     $language = Pll()->model->get_language(substr($column, 9));
     $translation_id = pll_get_post($post_id, $language->slug);
     if (get_post_meta($translation_id, Endpoints::TRAPP_META_TRANSLATED, true)) {
         echo '</span>';
     }
 }
Пример #9
0
 /**
  * Get an array with all available translations for a given post
  *
  * @param int $postID
  * @return array Indexed array with as key the language code, and as value the post id
  */
 public function getTranslatedPosts($postID)
 {
     $languages = pll_the_languages(array('raw' => 1));
     $result = array();
     foreach ($languages as $lang) {
         $lang = $lang['slug'];
         $transPostID = pll_get_post($postID, $lang);
         if (is_int($transPostID) && $transPostID !== $postID) {
             $result[$lang] = $transPostID;
         }
     }
     return $result;
 }
Пример #10
0
 /**
  * Translate product gallery
  *
  * @param array $IDS current attachment IDS
  *
  * @return array translated attachment IDS
  */
 public function translateGallery(array $IDS)
 {
     $translations = array();
     foreach ($IDS as $ID) {
         $tr = pll_get_post($ID);
         if ($tr) {
             $translations[] = $tr;
             continue;
         }
         $translations[] = $ID;
     }
     return $translations;
 }
 /**
  * Front-end display of widget.
  *
  * @see WP_Widget::widget()
  *
  * @param array $args
  * @param array $instance
  */
 public function widget($args, $instance)
 {
     // Prepare data for mustache template
     $page_id = absint($instance['page_id']);
     /**
      * Support for the Polylang plugin.
      * https://proteusthemes.zendesk.com/agent/tickets/5175
      * https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/#pll_get_post
      */
     if (function_exists('pll_get_post')) {
         $page_id = pll_get_post($page_id);
     }
     $instance['layout'] = sanitize_key($instance['layout']);
     $instance['read_more_text'] = empty($instance['read_more_text']) ? esc_html__('Read more', 'proteuswidgets') : sanitize_text_field($instance['read_more_text']);
     $thumbnail_size = 'inline' === $instance['layout'] ? 'pw-inline' : 'pw-page-box';
     // Get basic page info
     if ($page_id) {
         $page = (array) get_post($page_id);
     }
     // Prepare the excerpt text
     $excerpt = !empty($page['post_excerpt']) ? $page['post_excerpt'] : $page['post_content'];
     if ('inline' === $instance['layout'] && strlen($excerpt) > $this->excerpt_lengths['inline_excerpt']) {
         $strpos = strpos($excerpt, ' ', $this->excerpt_lengths['inline_excerpt']);
         $excerpt = false !== $strpos ? substr($excerpt, 0, $strpos) . ' &hellip;' : $excerpt;
     } elseif (strlen($excerpt) > $this->excerpt_lengths['block_excerpt']) {
         $strpos = strpos($excerpt, ' ', $this->excerpt_lengths['block_excerpt']);
         $excerpt = false !== $strpos ? substr($excerpt, 0, $strpos) . ' &hellip;' : $excerpt;
     }
     $page['post_excerpt'] = sanitize_text_field($excerpt);
     $page['link'] = get_permalink($page_id);
     $page['thumbnail'] = get_the_post_thumbnail($page_id, $thumbnail_size);
     if ('block' === $instance['layout']) {
         $attachment_image_id = get_post_thumbnail_id($page_id);
         $attachment_image_data = wp_get_attachment_image_src($attachment_image_id, 'pw-page-box');
         $page['image_url'] = $attachment_image_data[0];
         $page['image_width'] = $attachment_image_data[1];
         $page['image_height'] = $attachment_image_data[2];
         $page['srcset'] = PW_Functions::get_attachment_image_srcs($attachment_image_id, array('pw-page-box', 'full'));
     }
     // Mustache widget-featured-page template rendering
     echo $this->mustache->render(apply_filters('pw/widget_featured_page_view', 'widget-featured-page'), array('args' => $args, 'page' => $page, 'instance' => $instance, 'block' => 'block' === $instance['layout']));
 }
Пример #12
0
 /**
  * Translate the shop page name in the given shop url.
  *
  * @param string $url      complete url
  * @param string $language the current language
  *
  * @return string translated url
  */
 public function translateShopUrl($url, $language)
 {
     $result = $url;
     if (!is_post_type_archive('product')) {
         return $result;
     }
     $shopPageID = get_option('woocommerce_shop_page_id');
     $shopPage = get_post($shopPageID);
     if ($shopPage) {
         $shopPageTranslatedID = pll_get_post($shopPageID, $language);
         $shopPageTranslation = get_post($shopPageTranslatedID);
         if ($shopPageTranslation) {
             $result = str_replace($shopPage->post_name, $shopPageTranslation->post_name, $url);
         }
     }
     return $result;
 }
 function pll_woocommerce_get_page_id($id)
 {
     return pll_get_post($id);
     // translate the page to current language
 }
Пример #14
0
 * The Header template for our theme
 *
 * Displays all of the <head> section and everything up till <div id="main">
 *
 * @package WordPress
 * @subpackage Metropolis
 */
define("URL", get_template_directory_uri());
define("RAIZ", get_bloginfo("url"));
$idioma = pll_current_language();
$lifestyle = get_post(pll_get_post(6, $idioma), "OBJECT");
$neighborhood = get_post(pll_get_post(9, $idioma), "OBJECT");
$overview = get_post(pll_get_post(11, $idioma), "OBJECT");
$team = get_post(pll_get_post(13, $idioma), "OBJECT");
$press = get_post(pll_get_post(15, $idioma), "OBJECT");
$contact = get_post(pll_get_post(17, $idioma), "OBJECT");
global $activa;
?>
<!doctype html>
<!--[if IE 9]>      <html class="no-js ie9"> <![endif]-->
<!--[if gt IE 10]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    
    <title>Exclusive Condominium Residences in Downtown Los Angeles | Metropolis</title>
   <meta name="description" content="Upscale, beautiful modern condominium residences with gorgeous panoramic views in Downtown Los Angeles" />
   <meta name="keywords" content="Exclusive real estate in LA, Luxury real estate los angeles, Apartments Downtown, Los Angeles, Modern Real Estate Developments, Sophisticated Los Angeles condominiums, Upscale condo community, Southern California premium real estate" />

    <link rel="stylesheet" href="<?php 
echo URL;
 /**
  *	listing_images_default()
  *	
  *	Callback function to set the default
  *	gallery with translated images if
  *	these are available.
  *	
  *	@access	public
  *	@param	array	$field_args
  *	@param	object	$field
  *	@uses	pll_get_post_language()
  *	@uses	pll_default_language()
  *	@uses	pll_get_post()
  *	@uses	get_post_meta()
  *	@return	array
  *	
  *	@since 1.0.0
  */
 public function listing_images_default($field_args, $field)
 {
     // Get post language
     $post_lang = pll_get_post_language($field->object_id);
     // Get from post early
     $from_post = isset($_REQUEST['from_post']) ? $_REQUEST['from_post'] : false;
     // If from_post is not available anymore, use current post ID
     if (!$from_post) {
         $from_post = $field->object_id;
     }
     // Get post ID of default language
     $origial = pll_get_post($from_post, pll_default_language());
     // Get original gallery
     $gallery = get_post_meta($origial, '_gallery', true);
     if (empty($gallery)) {
         return;
     }
     // Set up translated gallery
     $gallery_lang = array();
     foreach ($gallery as $id => $url) {
         // Get ID of image translation
         $id_lang = pll_get_post($id, $post_lang);
         if ($id_lang) {
             // When available, set new ID
             $gallery_lang[$id_lang] = $url;
         }
     }
     // If there are image translations, set new gallery default
     if (!empty($gallery_lang)) {
         return $gallery_lang;
     }
 }
/**
 * Get the page ID of a page if set, with PolyLang compat.
 * @param  string $page e.g. job_dashboard, submit_job_form, jobs
 * @return int
 */
function job_manager_get_page_id($page)
{
    $page_id = get_option('job_manager_' . $page . '_page_id', false);
    if ($page_id) {
        return absint(function_exists('pll_get_post') ? pll_get_post($page_id) : $page_id);
    } else {
        return 0;
    }
}
Пример #17
0
/**
 * Return a variable (if exists)
 *
 * @param mixed $var The variable name, can also be a modifier for specific types
 * @param string|array|object $type (optional) Super globals, url/url-relative, constants, globals, options, transients, cache, user data, Pod field values, dates
 * @param mixed $default (optional) The default value to set if variable doesn't exist
 * @param bool $strict (optional) Only allow values (must not be empty)
 * @param array $params (optional) Set 'casting'=>true to cast value from $default, 'allowed'=>$allowed to restrict a value to what's allowed
 *
 * @return mixed The variable (if exists), or default value
 * @since 2.3.10
 */
function pods_v($var = null, $type = 'get', $default = null, $strict = false, $params = array())
{
    $defaults = array('casting' => false, 'allowed' => null);
    $params = (object) array_merge($defaults, (array) $params);
    $output = null;
    if (null === $type || '' === $type) {
        // Invalid $type
    } elseif (is_array($type)) {
        if (isset($type[$var])) {
            $output = $type[$var];
        }
    } elseif (is_object($type)) {
        if (isset($type->{$var})) {
            $output = $type->{$var};
        }
    } else {
        $type = strtolower((string) $type);
        switch ($type) {
            case 'get':
                if (isset($_GET[$var])) {
                    $output = pods_unslash($_GET[$var]);
                }
                break;
            case 'post':
                if (isset($_POST[$var])) {
                    $output = pods_unslash($_POST[$var]);
                }
                break;
            case 'request':
                if (isset($_REQUEST[$var])) {
                    $output = pods_unslash($_REQUEST[$var]);
                }
                break;
            case 'url':
            case 'uri':
                $url = parse_url(pods_current_url());
                $uri = trim($url['path'], '/');
                $uri = array_filter(explode('/', $uri));
                if ('first' == $var) {
                    $var = 0;
                } elseif ('last' == $var) {
                    $var = -1;
                }
                if (is_numeric($var)) {
                    $output = $var < 0 ? pods_v(count($uri) + $var, $uri) : pods_v($var, $uri);
                }
                break;
            case 'url-relative':
                $url_raw = pods_current_url();
                $prefix = get_site_url();
                if (substr($url_raw, 0, strlen($prefix)) == $prefix) {
                    $url_raw = substr($url_raw, strlen($prefix) + 1, strlen($url_raw));
                }
                $url = parse_url($url_raw);
                $uri = trim($url['path'], '/');
                $uri = array_filter(explode('/', $uri));
                if ('first' == $var) {
                    $var = 0;
                } elseif ('last' == $var) {
                    $var = -1;
                }
                if (is_numeric($var)) {
                    $output = $var < 0 ? pods_v(count($uri) + $var, $uri) : pods_v($var, $uri);
                }
                break;
            case 'template-url':
                $output = get_template_directory_uri();
                break;
            case 'stylesheet-url':
                $output = get_stylesheet_directory_uri();
                break;
            case 'site-url':
                $blog_id = $scheme = null;
                $path = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $blog_id = $var[0];
                    } elseif (isset($var[1])) {
                        $path = $var[1];
                    } elseif (isset($var[2])) {
                        $scheme = $var[2];
                    }
                } else {
                    $blog_id = $var;
                }
                $output = get_site_url($blog_id, $path, $scheme);
                break;
            case 'home-url':
                $blog_id = $scheme = null;
                $path = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $blog_id = $var[0];
                    } elseif (isset($var[1])) {
                        $path = $var[1];
                    } elseif (isset($var[2])) {
                        $scheme = $var[2];
                    }
                } else {
                    $blog_id = $var;
                }
                $output = get_home_url($blog_id, $path, $scheme);
                break;
            case 'admin-url':
                $blog_id = $scheme = null;
                $path = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $blog_id = $var[0];
                    } elseif (isset($var[1])) {
                        $path = $var[1];
                    } elseif (isset($var[2])) {
                        $scheme = $var[2];
                    }
                } else {
                    $blog_id = $var;
                }
                $output = get_admin_url($blog_id, $path, $scheme);
                break;
            case 'includes-url':
                $output = includes_url($var);
                break;
            case 'content-url':
                $output = content_url($var);
                break;
            case 'plugins-url':
                $path = $plugin = '';
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $plugin = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = plugins_url($path, $plugin);
                break;
            case 'network-site-url':
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = network_site_url($path, $scheme);
                break;
            case 'network-home-url':
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = network_home_url($path, $scheme);
                break;
            case 'network-admin-url':
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = network_admin_url($path, $scheme);
                break;
            case 'user-admin-url':
                $path = '';
                $scheme = null;
                if (is_array($var)) {
                    if (isset($var[0])) {
                        $path = $var[0];
                    } elseif (isset($var[1])) {
                        $scheme = $var[1];
                    }
                } else {
                    $path = $var;
                }
                $output = user_admin_url($path, $scheme);
                break;
            case 'prefix':
                global $wpdb;
                $output = $wpdb->prefix;
                break;
            case 'server':
                if (!pods_strict()) {
                    if (isset($_SERVER[$var])) {
                        $output = pods_unslash($_SERVER[$var]);
                    } elseif (isset($_SERVER[strtoupper($var)])) {
                        $output = pods_unslash($_SERVER[strtoupper($var)]);
                    }
                }
                break;
            case 'session':
                if (isset($_SESSION[$var])) {
                    $output = $_SESSION[$var];
                }
                break;
            case 'global':
            case 'globals':
                if (isset($GLOBALS[$var])) {
                    $output = $GLOBALS[$var];
                }
                break;
            case 'cookie':
                if (isset($_COOKIE[$var])) {
                    $output = pods_unslash($_COOKIE[$var]);
                }
                break;
            case 'constant':
                if (defined($var)) {
                    $output = constant($var);
                }
                break;
            case 'user':
                if (is_user_logged_in()) {
                    $user = get_userdata(get_current_user_id());
                    if (isset($user->{$var})) {
                        $value = $user->{$var};
                    } elseif ('role' == $var) {
                        $value = '';
                        if (!empty($user->roles)) {
                            $value = array_shift($user->roles);
                        }
                    } else {
                        $value = get_user_meta($user->ID, $var);
                    }
                    if (is_array($value) && !empty($value)) {
                        $output = $value;
                    } elseif (!is_array($value) && 0 < strlen($value)) {
                        $output = $value;
                    }
                }
                break;
            case 'option':
                $output = get_option($var, $default);
                break;
            case 'site-option':
                $output = get_site_option($var, $default);
                break;
            case 'transient':
                $output = get_transient($var);
                break;
            case 'site-transient':
                $output = get_site_transient($var);
                break;
            case 'cache':
                if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
                    $group = 'default';
                    $force = false;
                    if (!is_array($var)) {
                        $var = explode('|', $var);
                    }
                    if (isset($var[0])) {
                        if (isset($var[1])) {
                            $group = $var[1];
                        }
                        if (isset($var[2])) {
                            $force = $var[2];
                        }
                        $var = $var[0];
                        $output = wp_cache_get($var, $group, $force);
                    }
                }
                break;
            case 'pods-transient':
                $callback = null;
                if (!is_array($var)) {
                    $var = explode('|', $var);
                }
                if (isset($var[0])) {
                    if (isset($var[1])) {
                        $callback = $var[1];
                    }
                    $var = $var[0];
                    $output = pods_transient_get($var, $callback);
                }
                break;
            case 'pods-site-transient':
                $callback = null;
                if (!is_array($var)) {
                    $var = explode('|', $var);
                }
                if (isset($var[0])) {
                    if (isset($var[1])) {
                        $callback = $var[1];
                    }
                    $var = $var[0];
                    $output = pods_site_transient_get($var, $callback);
                }
                break;
            case 'pods-cache':
                if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
                    $group = 'default';
                    $callback = null;
                    if (!is_array($var)) {
                        $var = explode('|', $var);
                    }
                    if (isset($var[0])) {
                        if (isset($var[1])) {
                            $group = $var[1];
                        }
                        if (isset($var[2])) {
                            $callback = $var[2];
                        }
                        $var = $var[0];
                        $output = pods_cache_get($var, $group, $callback);
                    }
                }
                break;
            case 'pods-option-cache':
                $group = 'default';
                $callback = null;
                if (!is_array($var)) {
                    $var = explode('|', $var);
                }
                if (isset($var[0])) {
                    if (isset($var[1])) {
                        $group = $var[1];
                    }
                    if (isset($var[2])) {
                        $callback = $var[2];
                    }
                    $var = $var[0];
                    $output = pods_option_cache_get($var, $group, $callback);
                }
                break;
            case 'date':
                $var = explode('|', $var);
                if (!empty($var)) {
                    $output = date_i18n($var[0], isset($var[1]) ? strtotime($var[1]) : false);
                }
                break;
            case 'pods':
            case 'pods_display':
                /**
                 * @var $pods Pods
                 */
                global $pods;
                if (is_object($pods) && 'Pods' == get_class($pods)) {
                    if ('pods' === $type) {
                        $output = $pods->field($var);
                        if (is_array($output)) {
                            $options = array('field' => $var, 'fields' => $pods->fields);
                            $output = pods_serial_comma($output, $options);
                        }
                    } elseif ('pods_display' === $type) {
                        $output = $pods->display($var);
                    }
                }
                break;
            case 'post_id':
                if (empty($var)) {
                    if (!empty($default)) {
                        $post_id = $default;
                    } else {
                        // If no $var and no $default then use current post ID
                        $post_id = get_the_ID();
                    }
                } else {
                    $post_id = $var;
                }
                if (did_action('wpml_loaded')) {
                    /* Only call filter if WPML is installed */
                    $post_type = get_post_type($post_id);
                    $post_id = apply_filters('wpml_object_id', $post_id, $post_type, true);
                } elseif (function_exists('pll_get_post')) {
                    $polylang_id = pll_get_post($post_id);
                    if (!empty($polylang_id)) {
                        $post_id = $polylang_id;
                    }
                }
                // Add other translation plugin specific code here
                /**
                 * Filter to override post_id
                 *
                 * Generally used with language translation plugins in order to return the post id of a
                 * translated post
                 *
                 * @param  int $post_id The post ID of current post
                 * @param  mixed $default The default value to set if variable doesn't exist
                 * @param  mixed $var The variable name, can also be a modifier for specific types
                 * @param  bool $strict Only allow values (must not be empty)
                 * @param  array $params Set 'casting'=>true to cast value from $default, 'allowed'=>$allowed to restrict a value to what's allowed
                 *
                 * @since 2.6.6
                 */
                $output = apply_filters('pods_var_post_id', $post_id, $default, $var, $strict, $params);
                break;
            default:
                $output = apply_filters('pods_var_' . $type, $default, $var, $strict, $params);
        }
    }
    if (null !== $default) {
        // Set default
        if (null === $output) {
            $output = $default;
        }
        // Casting
        if (true === $params->casting) {
            $output = pods_cast($output, $default);
        }
    }
    // Strict defaults for empty values
    if (true === $strict) {
        if (empty($output)) {
            $output = $default;
        }
    }
    // Allowed values
    if (null !== $params->allowed) {
        if (is_array($params->allowed)) {
            // Not in array and is not the same array
            if (!in_array($output, $params->allowed) && (!is_array($output) || $output !== $params->allowed)) {
                $output = $default;
            }
        } elseif ($output !== $params->allowed) {
            // Value doesn't match
            $output = $default;
        }
    }
    return $output;
}
Пример #18
0
 public static function translated_page_id_from_slug($slug)
 {
     $footer = get_page_by_path('footer');
     return pll_get_post($footer->ID);
 }
 /**
  * Define the sarch page url for the current language
  *
  * @param $default_search_page_id
  * @param $default_search_page_url
  *
  * @return string
  */
 function set_search_page_url($default_search_page_url, $default_search_page_id)
 {
     global $polylang;
     $current_language_code = $this->get_current_language_code();
     // Get search page in current language
     $default_search_page_id_translated = pll_get_post($default_search_page_id, $current_language_code);
     if (!$default_search_page_id_translated) {
         // Create a new search page for the translation
         $default_search_page = WPSolrSearchSolrClient::create_default_search_page();
         // Retrieve current search page translations
         $translations = $polylang->model->get_translations('post', $default_search_page_id);
         // Add current translation to translations
         $translations[$current_language_code] = $default_search_page->ID;
         // Save translations
         pll_save_post_translations($translations);
     }
     $result = $default_search_page_id === $default_search_page_id_translated ? $default_search_page_url : get_permalink($default_search_page_id_translated);
     return $result;
 }
Пример #20
0
<?php

$args = ['posts_per_page' => 6, 'lang' => 'ru'];
$posts = get_posts($args);
global $_OURCARE_LANG;
// get news all link by current language
if (function_exists('pll_get_post')) {
    $id = pll_get_post(get_page_by_path('news')->ID);
} else {
    $id = get_page_by_path('news');
}
?>

<div class="news">
	<div class="container">

		<h2 class="news_header">
			<?php 
echo $_OURCARE_LANG['news_latest'];
?>
		</h2>

		<div class="news_list">
			
			<?php 
foreach ($posts as $post) {
    ?>
				<div class="new">
					<a href="<?php 
    echo get_permalink($post->ID);
    ?>
Пример #21
0
 /**
  * Retrieve the title for a post type archive.
  */
 public function archive_title($title, $post_type)
 {
     if (isset(static::$post_types[$post_type])) {
         $obj_inst = static::$post_types[$post_type];
         if ($obj_inst->obj_page) {
             $title = get_the_title(pll_get_post($obj_inst->obj_page));
         }
     }
     return $title;
 }
 public function pre_get_posts($query)
 {
     global $wpdb;
     $qv =& $query->query_vars;
     if ($query->is_main_query() || !empty($qv['lang']) || !empty($qv['post_type']) && !$this->model->is_translated_post_type($qv['post_type'])) {
         return;
     }
     $sign = create_function('$n', 'return $n > 0 ? 1 : ($n < 0 ? -1 : 0);');
     // /!\ always keep untranslated as is
     // term ids separated by a comma
     $arr = array();
     if (!empty($qv['cat'])) {
         foreach (explode(',', $qv['cat']) as $cat) {
             $arr[] = ($tr = $sign($cat) * pll_get_term(abs($cat))) ? $tr : $cat;
         }
         $qv['cat'] = implode(',', $arr);
     }
     // category_name
     $arr = array();
     if (!empty($qv['category_name'])) {
         foreach (explode(',', $qv['category_name']) as $slug) {
             $arr[] = ($cat = get_category_by_slug($slug)) && ($tr_id = pll_get_term($cat->term_id)) && !is_wp_error($tr = get_category($tr_id)) ? $tr->slug : $slug;
         }
         $qv['category_name'] = implode(',', $arr);
     }
     // array of term ids
     foreach (array('category__and', 'category__in', 'category__not_in', 'tag__and', 'tag__in', 'tag__not_in') as $key) {
         $arr = array();
         if (!empty($qv[$key])) {
             foreach ($qv[$key] as $cat) {
                 $arr[] = ($tr = pll_get_term($cat)) ? $tr : $cat;
             }
             $qv[$key] = $arr;
         }
     }
     // tag
     $arr = array();
     if (!empty($qv['tag'])) {
         $sep = strpos($qv['tag'], ',') !== false ? ',' : '+';
         // two possible separators for tag slugs
         foreach (explode($sep, $qv['tag']) as $slug) {
             $arr[] = ($tag = get_term_by('slug', $slug, 'post_tag')) && ($tr_id = pll_get_term($tag->term_id)) && !is_wp_error($tr = get_tag($tr_id)) ? $tr->slug : $slug;
         }
         $qv['tag'] = implode($sep, $arr);
     }
     // tag_id can only take one id
     if (!empty($qv['tag_id']) && ($tr_id = pll_get_term($qv['tag_id']))) {
         $qv['tag_id'] = $tr_id;
     }
     // array of tag slugs
     foreach (array('tag_slug__and', 'tag_slug__in') as $key) {
         $arr = array();
         if (!empty($qv[$key])) {
             foreach ($qv[$key] as $slug) {
                 $arr[] = ($tag = get_term_by('slug', $slug, 'post_tag')) && ($tr_id = pll_get_term($tag->term_id)) && !is_wp_error($tr = get_tag($tr_id)) ? $tr->slug : $slug;
             }
             $qv[$key] = $arr;
         }
     }
     // custom taxonomies
     // according to codex, this type of query is deprecated as of WP 3.1 but it does not appear in WP 3.5 source code
     foreach (array_intersect($this->model->get_translated_taxonomies(), get_taxonomies(array('_builtin' => false))) as $taxonomy) {
         $tax = get_taxonomy($taxonomy);
         $arr = array();
         if (!empty($qv[$tax->query_var])) {
             $sep = strpos($qv[$tax->query_var], ',') !== false ? ',' : '+';
             // two possible separators
             foreach (explode($sep, $qv[$tax->query_var]) as $slug) {
                 $arr[] = ($tag = get_term_by('slug', $slug, $taxonomy)) && ($tr_id = pll_get_term($tag->term_id)) && !is_wp_error($tr = get_term($tr_id, $taxonomy)) ? $tr->slug : $slug;
             }
             $qv[$tax->query_var] = implode($sep, $arr);
         }
     }
     // tax_query since WP 3.1
     if (!empty($qv['tax_query']) && is_array($qv['tax_query'])) {
         $qv['tax_query'] = $this->translate_tax_query_recursive($qv['tax_query']);
     }
     // p, page_id, post_parent can only take one id
     foreach (array('p', 'page_id', 'post_parent') as $key) {
         if (!empty($qv[$key]) && ($tr_id = pll_get_post($qv[$key]))) {
             $qv[$key] = $tr_id;
         }
     }
     // name, pagename can only take one slug
     foreach (array('name', 'pagename') as $key) {
         if (!empty($qv[$key])) {
             // no function to get post by name except get_posts itself
             $post_type = empty($qv['post_type']) ? 'post' : $qv['post_type'];
             $id = $wpdb->get_var($wpdb->prepare("SELECT ID from {$wpdb->posts} WHERE post_type=%s AND post_name=%s", $post_type, $qv[$key]));
             $qv[$key] = $id && ($tr_id = pll_get_post($id)) && ($tr = get_post($tr_id)) ? $tr->post_name : $qv[$key];
         }
     }
     // array of post ids
     // post_parent__in & post_parent__not_in since WP 3.6
     foreach (array('post__in', 'post__not_in', 'post_parent__in', 'post_parent__not_in') as $key) {
         $arr = array();
         if (!empty($qv[$key])) {
             // post__in used by the 2 functions below
             // useless to filter them as output is already in the right language and would result in performance loss
             foreach (debug_backtrace() as $trace) {
                 if (in_array($trace['function'], array('wp_nav_menu', 'gallery_shortcode'))) {
                     return;
                 }
             }
             foreach ($qv[$key] as $p) {
                 $arr[] = ($tr = pll_get_post($p)) ? $tr : $p;
             }
             $qv[$key] = $arr;
         }
     }
 }
Пример #23
0
				</div>
				<div class="widget-forecasts widget-windguru">
					<div id="wg_target_div_38193_76640673"></div>
				</div>
				<div class="widget-forecasts widget-spotfav">
					<iframe src='http://www.spotfav.com/widget/spot-snapshot/el-palmar/b/61679ADE64EF6CCFD0DA' frameborder='0' scrolling='no' width='300px' height='300px'></iframe>
				</div>
			</div><!-- .sidebar-forecasts -->

		</div><!-- .sidebar -->

		</article>

		<?php 
        if (function_exists("pll_get_post")) {
            $eldorado = pll_get_post(340);
        }
        ?>
		<article id="post-el-dorado">
		<?php 
        $the_post = get_post($eldorado);
        //the El Dorado page to merge with home page
        $the_title = $the_post->post_title;
        $the_excerpt = $the_post->post_excerpt;
        $the_content = apply_filters('the_content', $the_post->post_content);
        ?>
			<div class="eldorado__title">
				<h1><?php 
        echo $the_title;
        ?>
</h1>
 /**
  * Filter the navigation menu items being returned.
  *
  * @param  array   $items  An array of menu item post objects.
  * @param  object  $menu   The menu object.
  * @param  array   $args   An array of arguments used to retrieve menu item objects.
  * @return array   $items
  */
 public static function get_items($items, $menu, $args)
 {
     foreach ($items as &$item) {
         if ($item->type === static::$obj_archive) {
             $obj_type = get_post_type_object($item->object);
             if (!$obj_type) {
                 continue;
             }
             if ('post' === $obj_type->name) {
                 $page_id = get_option('page_for_posts');
                 if (!empty($page_id)) {
                     $item->title = get_the_title($page_id);
                 }
             } elseif (!empty($obj_type->labels->page_for_items_setting)) {
                 $options = get_option('boilerplate', []);
                 $setting = $obj_type->labels->page_for_items_setting;
                 if (!empty($options[$setting])) {
                     $item->title = get_the_title(pll_get_post($options[$setting]));
                 }
             }
             $item->url = get_post_type_archive_link($item->object);
             /**
              * @deprecated The _wp_menu_item_classes_by_context() function
              *             resets this property.
              */
             /*
             				if ( get_query_var( 'post_type' ) == $item->object ) {
             					$item->classes[] = 'current-menu-item';
             					$item->current = true;
             				}
             */
         }
     }
     return $items;
 }
Пример #25
0
 /**
  * Get product variation translation
  *
  * Returns the product variation object for a given language.
  *
  * @param int       $variation_id   (required) Id of the variation to translate
  * @param string    $lang           (optional) 2-letters code of the language
  *                                  like Polylang
  *                                  language slugs, defaults to current language
  *
  * @return \WP_Product_Variation    Product variation object for the given
  *                                  language, false on error or if doesn't exists.
  */
 public function get_variation_translation($variation_id, $lang = '')
 {
     $_variation = false;
     // Get parent product translation id for the given language
     $variation = wc_get_product($variation_id);
     $parent = $variation ? $variation->parent : null;
     $_product_id = $parent ? pll_get_post($parent->id, $lang) : null;
     // Get variation translation using the duplication metadata value
     $meta = get_post_meta($variation_id, Variation::DUPLICATE_KEY, true);
     if ($_product_id && $meta) {
         // Get posts (variations) with duplication metadata value
         $variation_post = get_posts(array('meta_key' => Variation::DUPLICATE_KEY, 'meta_value' => $meta, 'post_type' => 'product_variation', 'post_parent' => $_product_id));
         // Get variation translation
         if ($variation_post && count($variation_post) == 1) {
             $_variation = wc_get_product($variation_post[0]->ID);
         }
     }
     return $_variation;
 }
 public function set_home_url()
 {
     global $polylang;
     // home url for search form (can't use the page url if a static page is used as front page)
     $this->search_url = $polylang->links_model->home_url($this);
     // add a trailing slash as done by WP on homepage (otherwise could break the search form when the permalink structure does not include one)
     // only for pretty permalinks
     if (get_option('permalink_structure')) {
         $this->search_url = trailingslashit($this->search_url);
     }
     $options = get_option('polylang');
     // a static page is used as front page
     if (!$options['redirect_lang'] && 'page' == get_option('show_on_front') && ($page_on_front = get_option('page_on_front')) && ($id = pll_get_post($page_on_front, $this))) {
         $this->home_url = _get_page_link($id);
     } else {
         $this->home_url = $this->search_url;
     }
 }
Пример #27
0
									<i class="fa fa-columns"></i>
									<!-- Title -->
									<h4><?php 
echo $post->post_title;
?>
</h4></div>
								<div class="mask-bottom">
									<p><?php 
echo $post->post_excerpt;
?>
</p></div>
							</div></a>
						</div>
						<?php 
$post = null;
$post = get_post(pll_get_post(get_posts('name=customer-self-order')[0]->ID));
?>
						<div class="col-xs-3 animated fadeInDown visible" data-animation="fadeInDown">
							<a href="<?php 
echo site_url();
?>
/category/solutions<?php 
echo CAT_LANG_SUFFIX;
?>
/#post-<?php 
echo $post->ID;
?>
"><div class="s-feature-box text-center">
								<div class="mask-top">
									<!-- Icon -->
									<i class="fa fa-pencil-square-o"></i>
 function pll_tc_page_id( $fp_page_id ) {
   return is_int( pll_get_post( $fp_page_id ) ) ? pll_get_post( $fp_page_id ) : $fp_page_id;
 }
Пример #29
0
 /**
  * Sync default attributes between product translations
  *
  * @param int       $post_id    Post ID
  * @param \WP_Post  $post       Post Object
  * @param boolean   $update     true if updating the post, false otherwise
  */
 public function sync_default_attributes($post_id, $post, $update)
 {
     // Don't sync if not in the admin backend nor on autosave
     if (!is_admin() && defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     // Don't sync if Default Attribute syncronization is disabled
     $metas = Meta::getProductMetaToCopy();
     if (!in_array('_default_attributes', $metas)) {
         return;
     }
     //  To avoid Polylang overwriting default attribute meta
     add_filter('delete_post_metadata', array($this, 'skip_default_attributes_meta'), 10, 4);
     add_filter('add_post_metadata', array($this, 'skip_default_attributes_meta'), 10, 4);
     add_filter('update_post_metadata', array($this, 'skip_default_attributes_meta'), 10, 4);
     // Don't sync if not a Variable Product
     $product = wc_get_product($post_id);
     if ($product && 'simple' === $product->product_type && Utilities::maybe_variable_product($product)) {
         // Maybe is Variable Product
         // New translations of Variable Products are first created as simple
         // Only need to sync for the new translation from source product
         // The other product translation stay untouched
         $attributes_translation = Utilities::get_default_attributes_translation($_GET['from_post'], $_GET['new_lang']);
         if (!empty($attributes_translation) && isset($attributes_translation[$_GET['new_lang']])) {
             update_post_meta($product->id, '_default_attributes', $attributes_translation[$_GET['new_lang']]);
         }
     } elseif ($product && 'variable' === $product->product_type) {
         // Variable Product
         // For each product translation, get the translated (default) terms/attributes
         $attributes_translation = Utilities::get_default_attributes_translation($product->id);
         $langs = pll_languages_list();
         foreach ($langs as $lang) {
             $translation_id = pll_get_post($product->id, $lang);
             if ($translation_id != $product->id) {
                 update_post_meta($translation_id, '_default_attributes', $attributes_translation[$lang]);
             }
         }
     }
 }