本文整理汇总了PHP中pll_languages_list函数的典型用法代码示例。如果您正苦于以下问题:PHP pll_languages_list函数的具体用法?PHP pll_languages_list怎么用?PHP pll_languages_list使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pll_languages_list函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLanguages
/**
* Get all in polylang configured languages
* @return \PLL_Language[] list of languages
*/
public static function getLanguages()
{
if (function_exists('pll_languages_list')) {
return pll_languages_list(array('fields' => array()));
}
return array();
}
示例2: __construct
/**
* @inheritDoc
*
* @param string $language
*/
public function __construct($language, $feedUri = null)
{
if (!function_exists('pll_languages_list')) {
throw new Exception\RuntimeException(sprintf('function pll_languages_list not found'));
}
if (!empty($language) && !in_array($language, pll_languages_list())) {
throw new Exception\UnexpectedValueException(sprintf('Language not found'));
}
$this->language = $language;
return parent::__construct($feedUri);
}
示例3: duplicateVariations
/**
* Translate Variation for given variable product
*
* @param integer $ID product variable ID
* @param \WP_Post $post Product Post
* @param boolean $update true if update , false otherwise
*
* @return boolean
*/
public function duplicateVariations($ID, \WP_Post $post, $update)
{
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return false;
}
global $pagenow;
if (!in_array($pagenow, array('post.php', 'post-new.php'))) {
return false;
}
$product = wc_get_product($ID);
if (!$product) {
return false;
}
$from = null;
if (pll_get_post_language($ID) == pll_default_language()) {
$from = $product;
} else {
if (isset($_GET['from_post'])) {
/*
* This check will make sure that variation , will be
* created for brand new products which are not saved yet by user
*/
$from = Utilities::getProductTranslationByID(esc_attr($_GET['from_post']), pll_default_language());
} else {
$from = Utilities::getProductTranslationByObject($product, pll_default_language());
}
}
if (!$from instanceof \WC_Product_Variable) {
return false;
}
$langs = pll_languages_list();
foreach ($langs as $lang) {
$variation = new Variation($from, Utilities::getProductTranslationByObject($product, $lang));
remove_action('save_post', array($this, __FUNCTION__), 10);
$variation->duplicate();
add_action('save_post', array($this, __FUNCTION__), 10, 3);
}
}
示例4: correctMyAccountOrderQuery
/**
* Correct My account order query
*
* Will correct the query to display orders from all languages
*
* @param array $query
*
* @return array
*/
public function correctMyAccountOrderQuery(array $query)
{
$query['lang'] = implode(',', pll_languages_list());
return $query;
}
示例5: ajax_get_current_status
public function ajax_get_current_status()
{
$lgtm =& $GLOBALS['wp_lingotek']->model;
$pllm = $GLOBALS['polylang']->model;
$languages = pll_languages_list(array('fields' => 'locale'));
$object_ids = $_POST['check_ids'];
if ($object_ids === null) {
return;
}
$terms = isset($_POST['terms_translations']);
//The main array consists of
//ids and nonces. Each id has a source language, languages with statuses, and a workbench link
$content_metadata = array();
foreach ($object_ids as $object_id) {
$id = $object_id;
$type = $terms ? 'term' : 'post';
if (isset($_POST['taxonomy'])) {
$taxonomy = $_POST['taxonomy'];
if (strpos($_POST['taxonomy'], '&')) {
$taxonomy = strstr($_POST['taxonomy'], '&', true);
}
} else {
$taxonomy = get_post_type($id);
}
$content_metadata[$id] = array('existing_trans' => false, 'source' => false, 'doc_id' => null, 'source_id' => null, 'source_status' => null);
$document = $lgtm->get_group($type, $object_id);
if ($document && !isset($document->source) && count($document->desc_array) >= 3) {
$content_metadata[$id]['existing_trans'] = true;
}
if ($document && isset($document->source) && isset($document->document_id) && isset($document->status) && isset($document->translations)) {
if ($document->source !== (int) $object_id) {
$document = $lgtm->get_group($type, $document->source);
}
$source_id = $document->source !== null ? $document->source : $object_id;
$source_language = $terms ? pll_get_term_language($document->source, 'locale') : pll_get_post_language($document->source, 'locale');
$existing_translations = $pllm->get_translations($type, $source_id);
if (count($existing_translations) > 1) {
$content_metadata[$id]['existing_trans'] = true;
}
$content_metadata[$id]['source'] = $source_language;
$content_metadata[$id]['doc_id'] = $document->document_id;
$content_metadata[$id]['source_id'] = $document->source;
$content_metadata[$id]['source_status'] = $document->status;
$target_status = $document->status == 'edited' || $document->status == null ? 'edited' : 'current';
$content_metadata[$id][$source_language]['status'] = $document->source == $object_id ? $document->status : $target_status;
if (is_array($document->translations)) {
foreach ($document->translations as $locale => $translation_status) {
$content_metadata[$id][$locale]['status'] = $translation_status;
$workbench_link = Lingotek_Actions::workbench_link($document->document_id, $locale);
$content_metadata[$id][$locale]['workbench_link'] = $workbench_link;
}
}
//fills in missing languages, makes life easier for the updater
foreach ($languages as $language) {
foreach ($content_metadata as $group => $status) {
$language_obj = $pllm->get_language($source_language);
$target_lang_obj = $pllm->get_language($language);
$profile = Lingotek_Model::get_profile($taxonomy, $language_obj, $group);
if ($profile['profile'] != 'disabled' && $status['source'] != false) {
if (!isset($status[$language])) {
$content_metadata[$group][$language]['status'] = "none";
if ($document->is_disabled_target($pllm->get_language($source_language), $pllm->get_language($language)) || isset($document->desc_array[$target_lang_obj->slug]) && !isset($document->source)) {
$content_metadata[$group][$language]['status'] = 'disabled';
}
}
}
}
}
}
$language = $type == 'post' ? pll_get_post_language($id) : pll_get_term_language($id);
$language = $pllm->get_language($language);
if ($language) {
$profile = Lingotek_Model::get_profile($taxonomy, $language, $id);
if ($profile['profile'] == 'disabled' && $content_metadata[$id]['source'] == false) {
$content_metadata[$id]['source'] = 'disabled';
}
}
}
//get the nonces associated with the different actions
$content_metadata['request_nonce'] = $this->lingotek_get_matching_nonce('lingotek-request');
$content_metadata['download_nonce'] = $this->lingotek_get_matching_nonce('lingotek-download');
$content_metadata['upload_nonce'] = $this->lingotek_get_matching_nonce('lingotek-upload');
$content_metadata['status_nonce'] = $this->lingotek_get_matching_nonce('lingotek-status');
wp_send_json($content_metadata);
}
示例6: agent_description_options
/**
* agent_description_options()
*
* Correctly update agent description
* for all registered languages to
* be available in our listing editor.
*
* @access public
* @param array $agent_options
* @param integer $user_id
* @uses pll_languages_list()
*
* @since 1.0.0
*/
public function agent_description_options($agent_options, $user_id)
{
// Set descriptions in all languages
foreach (pll_languages_list() as $lang) {
$agent_options['_agent_description_' . $lang] = trim($_POST['description_' . $lang]);
}
return $agent_options;
}
示例7: sync_default_attributes
/**
* 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]);
}
}
}
}
示例8: add_action
add_action('admin_notices', function () {
echo '<div class="error">
<p>' . sprintf(__("<strong>Leyka warning!</strong> Polylang plugin doesn't have any languages installed. Leyka may work strangely due to that. Please go to the <a href='%s'>languages settings page</a> and add at least one language.", 'leyka'), site_url('/wp-admin/options-general.php?page=mlang')) . '</p>
</div>';
});
$locale = get_locale();
if (!$locale) {
$locale = 'en_US';
}
load_textdomain('leyka', LEYKA_PLUGIN_DIR . "lang/leyka-{$locale}.mo");
do_action('leyka_init_actions');
} else {
// $locale = is_admin() ? pll_default_language('locale') : pll_current_language('locale');
if (is_admin() && !did_action('leyka_init_actions')) {
do_action('leyka_init_actions');
if (count(pll_languages_list()) > 1) {
// Register user-defined strings:
foreach (leyka_options()->get_options_names() as $option) {
$option_data = leyka_options()->get_info_of($option);
if ($option_data['type'] == 'text') {
pll_register_string($option_data['title'], $option_data['value'], 'leyka');
} elseif ($option_data['type'] == 'textarea' || $option_data['type'] == 'html' || $option_data['type'] == 'rich_html') {
pll_register_string($option_data['title'], leyka_options()->opt($option), 'leyka', true);
}
}
}
}
add_action('leyka_default_success_page_created', function ($page_id) {
// echo '<pre>' . print_r($page_id, 1) . '</pre>';
// die('<pre>' . print_r(pll_default_language(), 1) . '</pre>');
// ... get localized strings from PL and update success page params
示例9: getDefaultAttributesTranslation
/**
* Get variations default attributes translation.
*
* Get the translation of the default attributes of product passed by id, in
* a given language, if one is passed, otherwise in all available languages.
*
* @param int $product_id (required) Product id.
* @param string $lang (optional) Language slug.
*
* @return array Indexed array, with language slug as key, of attributes
* pairs [attribute] => attribute slug
*/
public static function getDefaultAttributesTranslation($product_id, $lang = '')
{
$product = wc_get_product($product_id);
$translated_attributes = array();
if ($product && 'variable' === $product->product_type) {
$default_attributes = $product->get_variation_default_attributes();
$terms = array();
// Array of terms: if the term is taxonomy each value is a term object, otherwise an array (term slug => term value)
$langs = array();
foreach ($default_attributes as $key => $value) {
$term = get_term_by('name', $value, $key);
if ($term && pll_is_translated_taxonomy($term->taxonomy)) {
$terms[] = $term;
} else {
$terms[] = array($key => $value);
}
}
// For each product translation, get the translated default attributes
if (empty($lang)) {
$langs = pll_languages_list();
} else {
$langs[] = $lang;
// get translation for a specific language
}
foreach ($langs as $lang) {
$translated_terms = array();
foreach ($terms as $term) {
if (is_object($term)) {
$translated_term_id = pll_get_term($term->term_id, $lang);
$translated_term = get_term_by('id', $translated_term_id, $term->taxonomy);
$translated_terms[$translated_term->taxonomy] = $translated_term->slug;
} else {
$translated_terms[key($term)] = $term[key($term)];
}
}
$translated_attributes[$lang] = $translated_terms;
}
}
return $translated_attributes;
}
示例10: pll_register_string
pll_register_string('URL Suporte', 'suporte', 'timtec');
pll_register_string('URL Cadastro', 'cadastro', 'timtec');
//pll_register_string('URL Contato', 'contato', 'timtec');
//pll_register_string('URL Conselho', 'conselho', 'timtec');
pll_register_string('URL Manuais', 'manuais', 'timtec');
pll_register_string('URL Desenvolva', 'desenvolva-o-software', 'timtec');
pll_register_string('URL Download', 'download', 'timtec');
//pll_register_string('URL Faq', 'faq', 'timtec');
pll_register_string('URL Mural', 'mural', 'timtec');
pll_register_string('URL Conheça', 'conheca-timtec', 'timtec');
pll_register_string('URL MOOCS', 'o-que-sao-moocs', 'timtec');
pll_register_string('URL Explore', 'explore-a-plataforma', 'timtec');
// pll_register_string('URL Conheça a Rede', 'conheca-a-rede-tim-tec', 'timtec');
add_action('generate_rewrite_rules', function ($wp_rewrite) {
$new_rules = [];
foreach (pll_languages_list() as $lcode) {
// $str_courses = pll_translate_string('cursos', $lcode);
// $new_rules["^$lcode/$str_courses/?$"] = "index.php?template=courses";
// $str_conselho = pll_translate_string('conselho', $lcode);
// $new_rules["^$lcode/$str_conselho/?$"] = "index.php?template=conselho";
//
// $str_software = pll_translate_string('software', $lcode);
// $new_rules["^$lcode/$str_software/?$"] = "index.php?template=software";
//
// $str_redes = pll_translate_string('redes', $lcode);
// $new_rules["^$lcode/$str_redes/?$"] = "index.php?template=redes";
//
$str_noticias = pll_translate_string('noticias', $lcode);
$new_rules["^{$lcode}/{$str_noticias}/?\$"] = "index.php?post_type=post";
//
// $str_suporte = pll_translate_string('suporte', $lcode);
示例11: eme_detect_lang
function eme_detect_lang() {
$language="";
if (function_exists('qtrans_getLanguage')) {
// if permalinks are on, $_GET doesn't contain lang as a parameter
// so we get it like this to be sure
$language=qtrans_getLanguage();
} elseif (function_exists('ppqtrans_getLanguage')) {
$language=ppqtrans_getLanguage();
} elseif (function_exists('qtranxf_getLanguage')) {
$language=qtranxf_getLanguage();
} elseif (function_exists('pll_current_language') && function_exists('pll_languages_list')) {
$languages=pll_languages_list();
if (is_array($languages)) {
foreach ($languages as $tmp_lang) {
if (preg_match("/^$tmp_lang\/|\/$tmp_lang\//",$_SERVER['REQUEST_URI']))
$language=$tmp_lang;
}
}
if (empty($language))
$language=pll_current_language('slug');
} elseif (defined('ICL_LANGUAGE_CODE')) {
// Both polylang and wpml define this constant, so check polylang first (above)
// if permalinks are on, $_GET doesn't contain lang as a parameter
// so we get it like this to be sure
$language=ICL_LANGUAGE_CODE;
} elseif (isset($_GET['lang'])) {
$language=eme_strip_tags($_GET['lang']);
} else {
$language="";
}
return $language;
}
示例12: create_blog_term
/**
* Function to create network-wide term in a given site.
*
* This function will switch the given blog_id, create the term and then switch back to the current blog.
*
* @since 1.0.0
* @param string $blog_id the id of the blog in which to set the therm.
*/
protected function create_blog_term($blog_id, $term_name = null, $term_slug = null, $term_description = 'Network-wide -- DO NOT DELETE')
{
if (!isset($term_name)) {
$term_name = $this->term_name;
}
if (!isset($term_slug)) {
$term_slug = $this->term_slug;
}
$current_blog_id = get_current_blog_id();
switch_to_blog($blog_id);
//let's get the languages used on that site
$translations = pll_languages_list(array('hide_empty' => 0, 'fields' => 'slug'));
$language_name = pll_languages_list(array('hide_empty' => 0, 'fields' => 'name'));
//if we found some languages, let's cache them
for ($idx = 0; $idx < sizeof($language_name); $idx++) {
$this->set_language($translations[$idx], $language_name[$idx]);
}
//else we assume we are dealing with the default language
if (empty($translations)) {
$translations = array($this->default_lang);
error_log("Warning (Network-wide-posts) No Polylang languages set in blog: " . $blog_id . ", assuming default language (" . $this->default_lang . ")");
}
$term_ids = array();
//term id storage array
foreach ($translations as $lang) {
$term_slug = $this->term_slug . "-" . $lang;
$term_name = $this->term_name . " (" . $lang . ")";
if ($this->default_lang == $lang) {
$term_slug = $this->term_slug;
$term_name = $this->term_name;
}
$args = array('description' => $term_description, 'slug' => $term_slug);
switch (true) {
case self::AUTOMATIC_TAG === $this->term_type:
$taxonomy = 'post_tag';
$term = get_term_by('slug', $args['slug'], $taxonomy);
if (!$term) {
//create tag
$term = wp_insert_term($term_name, $taxonomy, $args);
if (is_array($term)) {
$term_id = $term['term_id'];
} else {
$term_id = -1;
}
} else {
$term_id = $term->term_id;
}
//associate the new term with the correct language
pll_set_term_language($term_id, $lang);
//let's keep a cache for quicker loading.
$term_ids[$lang] = $term_id;
$this->set_blog_term_id($blog_id, $term_ids);
break;
case self::AUTOMATIC_CAT === $this->term_type:
$taxonomy = 'category';
$term_ids = array();
$term = get_term_by('slug', $args['slug'], $taxonomy);
if (!$term) {
//create tag
$term = wp_insert_term($term_name, $taxonomy, $args);
if (is_array($term)) {
$term_id = $term['term_id'];
} else {
$term_id = -1;
}
} else {
$term_id = $term->term_id;
}
pll_set_term_language($term_id, $lang['slug']);
$term_ids[$lang['slug']] = $term_id;
$this->set_blog_term_id($blog_id, $term_id);
break;
case self::SELECTED_TAX === $this->term_type:
default:
//TODO, nothing?
break;
}
}
//switch back to current blog
//switch_to_blog($current_blog_id); //back to where we started
restore_current_blog();
}
示例13: add_taxonomy
/**
* ...
*/
public function add_taxonomy($taxonomy, $translated_slugs)
{
$taxonomy_object = get_taxonomy($taxonomy);
// Sanity check
if (is_null($taxonomy_object)) {
return;
}
$languages = pll_languages_list(array('fields' => 'slug'));
$translated_struct = array();
foreach ($languages as $lang) {
// Add non specified slug translation to taxonomy default.
if (!array_key_exists($lang, $translated_slugs)) {
$translated_slugs[$lang] = $taxonomy_object->rewrite['slug'];
}
// Trim "/".
$translated_slugs[$lang] = trim($translated_slugs[$lang], '/');
// Generate "struct" with "slug" as WordPress would do.
$translated_struct[$lang] = $translated_slugs[$lang] . "/%{$taxonomy_object->name}%";
}
$this->taxonomies[$taxonomy] = new PLL_TRS_Taxonomy($taxonomy_object, $translated_slugs, $translated_struct);
}
开发者ID:chesio,项目名称:wp-polylang-translate-rewrite-slugs,代码行数:24,代码来源:polylang-translate-rewrite-slugs.php
示例14: filterStockByLanguage
/**
* Filter stock by language.
*
* Filter the stock table according to choosen language
*
* @param string $query stock query
*
* @return string final stock query
*/
public function filterStockByLanguage($query)
{
$lang = ($current = pll_current_language()) ? array($current) : pll_languages_list();
$join = PLL()->model->post->join_clause(Utilities::polylangVersionCheck('2.0') ? 'posts' : 'post');
$where = PLL()->model->post->where_clause($lang, 'post');
return str_replace('WHERE 1=1', "{$join} WHERE 1=1 {$where}", $query);
}
示例15: dashboard_listings
/**
* dashboard_listings()
*
* Make sure dashboard add-on
* shows all languages.
*
* @uses get_terms()
* @uses pll_languages_list()
*
* @since 1.0.0
*/
public function dashboard_listings($args)
{
$args['tax_query'] = array('relation' => 'OR', array('taxonomy' => 'language', 'terms' => get_terms('language', array('fields' => 'ids')), 'operator' => 'NOT IN'), array('taxonomy' => 'language', 'field' => 'slug', 'terms' => pll_languages_list()));
return $args;
}