本文整理汇总了PHP中SitePress::get_current_language方法的典型用法代码示例。如果您正苦于以下问题:PHP SitePress::get_current_language方法的具体用法?PHP SitePress::get_current_language怎么用?PHP SitePress::get_current_language使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SitePress
的用法示例。
在下文中一共展示了SitePress::get_current_language方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: AND
/**
* @param string $slug
* @param string|bool $language
*
* @return string
*/
function get_translated_slug($slug, $language = false)
{
if ($slug) {
$current_language = $this->sitepress->get_current_language();
$language = $language ? $language : $current_language;
if (!isset($this->translated_slugs[$slug][$language])) {
$slugs_translations = $this->wpdb->get_results($this->wpdb->prepare("SELECT t.value, t.language\r\n\t\t\t\t\t\t\t\t\t\tFROM {$this->wpdb->prefix}icl_strings s\r\n\t\t\t\t\t\t\t\t\t\tJOIN {$this->wpdb->prefix}icl_string_translations t ON t.string_id = s.id\r\n\t\t\t\t\t\t\t\t\t\tWHERE s.name = %s\r\n\t\t\t\t\t\t\t\t\t\t AND (s.context = %s OR s.context = %s)\r\n\t\t\t\t\t\t\t\t\t\t\tAND t.status = %d\r\n\t\t\t\t\t\t\t\t\t\t\tAND t.value <> ''", 'URL slug: ' . $slug, 'default', 'WordPress', ICL_TM_COMPLETE));
foreach ($slugs_translations as $translation) {
$this->translated_slugs[$slug][$translation->language] = $translation->value;
}
// Add empty values for languages not found.
foreach ($this->sitepress->get_active_languages() as $lang) {
if (!isset($this->translated_slugs[$slug][$lang['code']])) {
$this->translated_slugs[$slug][$lang['code']] = '';
}
}
}
if ($this->translated_slugs[$slug][$language]) {
$has_translation = true;
$slug = $this->translated_slugs[$slug][$language];
} else {
$has_translation = false;
}
if ($has_translation) {
return $slug;
}
} else {
$has_translation = true;
}
return $has_translation ? $slug : $this->st_fallback($slug, $language);
}
示例2: AND
/**
* @param string $slug
* @param string $post_type
* @param string|bool $language
*
* @return string
*/
function get_translated_slug($slug, $post_type, $language = false)
{
if ($post_type) {
$language = $language ? $language : $this->sitepress->get_current_language();
if (!isset($this->translated_slugs[$post_type][$language])) {
$slug_original = $this->wpdb->get_row($this->wpdb->prepare("SELECT s.value, s.language\r\r\n\t\t\t\t\t\t\t\t\t\tFROM {$this->wpdb->prefix}icl_strings s\r\r\n\t\t\t\t\t\t\t\t\t\tWHERE s.name = %s\r\r\n\t\t\t\t\t\t\t\t\t\t AND (s.context = %s OR s.context = %s)", 'URL slug: ' . $post_type, 'default', 'WordPress'));
if ((bool) $slug_original === true) {
$this->translated_slugs[$post_type][$slug_original->language] = $slug_original->value;
$slugs_translations = $this->wpdb->get_results($this->wpdb->prepare("SELECT t.value, t.language\r\r\n\t\t\t\t\t\t\t\t\t\tFROM {$this->wpdb->prefix}icl_strings s\r\r\n\t\t\t\t\t\t\t\t\t\tJOIN {$this->wpdb->prefix}icl_string_translations t ON t.string_id = s.id\r\r\n\t\t\t\t\t\t\t\t\t\tWHERE s.name = %s\r\r\n\t\t\t\t\t\t\t\t\t\t AND (s.context = %s OR s.context = %s)\r\r\n\t\t\t\t\t\t\t\t\t\t\tAND t.status = %d\r\r\n\t\t\t\t\t\t\t\t\t\t\tAND t.value <> ''", 'URL slug: ' . $post_type, 'default', 'WordPress', ICL_TM_COMPLETE));
foreach ($slugs_translations as $translation) {
$this->translated_slugs[$post_type][$translation->language] = $translation->value;
}
foreach ($this->sitepress->get_active_languages() as $lang) {
if (!isset($this->translated_slugs[$post_type][$lang['code']])) {
$this->translated_slugs[$post_type][$lang['code']] = $slug;
}
}
}
}
$slug = !empty($this->translated_slugs[$post_type][$language]) ? $this->translated_slugs[$post_type][$language] : $slug;
}
return $slug;
}
示例3: get_canonical_of_duplicate
/**
* @param WPML_Post_Element $post_element
*
* @return false|string
*/
private function get_canonical_of_duplicate($post_element)
{
$source_element = $post_element->get_source_element();
if ($source_element) {
$source_element_id = $source_element->get_id();
$source_language_code = $source_element->get_language_code();
$current_language = $this->sitepress->get_current_language();
$this->sitepress->switch_lang($source_language_code);
$new_link = get_permalink($source_element_id);
$this->sitepress->switch_lang($current_language);
} else {
$new_link = get_permalink($post_element->get_id());
}
return $new_link;
}
示例4: get_save_post_lang
/**
* @param integer $post_id
* @param SitePress $sitepress
* @return bool|mixed|null|string|void
*/
protected function get_save_post_lang($post_id, $sitepress)
{
$language_code = $this->get_element_lang_code($post_id);
$language_code = $language_code ? $language_code : $sitepress->get_current_language();
$language_code = $sitepress->is_active_language($language_code) ? $language_code : $sitepress->get_default_language();
return apply_filters('wpml_save_post_lang', $language_code);
}