本文整理汇总了PHP中PLL函数的典型用法代码示例。如果您正苦于以下问题:PHP PLL函数的具体用法?PHP PLL怎么用?PHP PLL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PLL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: correctShopPage
/**
* Correct the shop page to display products from currrent language only.
*
* @param \WP $wp wordpress instance
*
* @return bool false if the current language is the same as default
* language or if the "pagename" var is empty
*/
public function correctShopPage(\WP $wp)
{
global $polylang;
$shopID = wc_get_page_id('shop');
$shopOnFront = 'page' === get_option('show_on_front') && in_array(get_option('page_on_front'), PLL()->model->post->get_translations($shopID));
$vars = array('pagename', 'page', 'name');
foreach ($vars as $var) {
if (isset($wp->query_vars[$var])) {
$shopOnFront = false;
break;
}
}
if (!$shopOnFront) {
if (!empty($wp->query_vars['pagename'])) {
$shopPage = get_post($shopID);
/* Explode by / for children page */
$page = explode('/', $wp->query_vars['pagename']);
if (isset($shopPage->post_name) && $shopPage->post_name == $page[count($page) - 1]) {
unset($wp->query_vars['page']);
unset($wp->query_vars['pagename']);
$wp->query_vars['post_type'] = 'product';
}
}
} else {
$wp->query_vars['post_type'] = 'product';
}
}
示例2: polylangMetaBoxRender
/**
* Registers the Polylang language meta box.
*
* @param object $post WP_Post post object.
* @param array $metabox Array of metabox arguments.
*
* @return void.
*/
public static function polylangMetaBoxRender($post, $metabox)
{
$post_id = $post->ID;
$post_type = $metabox['args']['post_type'];
if ($lg = PLL()->model->post->get_language($post_id)) {
$lang = $lg;
} elseif (!empty($_GET['new_lang'])) {
$lang = PLL()->model->get_language($_GET['new_lang']);
} else {
$lang = PLL()->pref_lang;
}
$text_domain = Plugin::TEXT_DOMAIN;
$languages = PLL()->model->get_languages_list();
$pll_dropdown = new PLL_Walker_Dropdown();
$dropdown = $pll_dropdown->walk($languages, array('name' => 'post_lang_choice', 'class' => 'tags-input', 'selected' => $lang ? $lang->slug : '', 'flag' => true));
$masterLink = '';
foreach ($languages as $language) {
$languagePost = PLL()->model->post->get_translation($post_id, $language);
if (!$languagePost) {
continue;
}
$languageMasterMeta = get_post_meta($languagePost, Events::TRAPP_META_MASTER, true);
if ($languageMasterMeta) {
$masterLink = sprintf('<a href="%s">%s</a>', get_edit_post_link($languagePost), $language->name);
break;
}
}
foreach ($languages as $key_language => $language) {
if ($language->term_id == $lang->term_id) {
unset($languages[$key_language]);
$languages = array_values($languages);
break;
}
}
wp_nonce_field('pll_language', '_pll_nonce');
// These shold really exist in some other methods.. whenever the structure has been very defined
$is_autopost = get_post_status($post) == 'auto-draft';
$is_master = get_post_meta($post->ID, Events::TRAPP_META_MASTER, true);
$has_trapp_key = get_post_meta($post->ID, Events::TRAPP_META_KEY, true);
$trapp_link_key = Events::TRAPP_META_LINK;
if ($is_autopost) {
include self::getView('admin/metabox-translations-post/language.php');
} else {
include self::getView('admin/metabox-translations-post/language-edit.php');
if (!$is_master) {
include self::getView('admin/metabox-translations-post/language-edit-translation.php');
}
include self::getView('admin/metabox-translations-post/translations.php');
if ($is_master || !$has_trapp_key) {
$deadline = get_post_meta($post->ID, Events::TRAPP_META_DEADLINE, true);
if (empty($deadline)) {
$deadline = date('Y-m-d', current_time('timestamp'));
}
include self::getView('admin/metabox-translations-post/trapp.php');
}
}
}
示例3: getProductTranslationsArrayByID
/**
* Get the translations IDS of the given product ID
*
* @global \Polylang $polylang
*
* @param integer $ID the product ID
* @param boolean $excludeDefault ture to exclude defualt language
*
* @return array associative array with language code as key and ID of translations
* as value.
*/
public static function getProductTranslationsArrayByID($ID, $excludeDefault = false)
{
global $polylang;
$IDS = PLL()->model->post->get_translations('post', $ID);
// $IDS = $polylang->model->get_translations('post', $ID);
if (true === $excludeDefault) {
unset($IDS[pll_default_language()]);
}
return $IDS;
}
示例4: getProductAttributesInLanguage
/**
* Get product attributes in right language
*
* @param array $args array of arguments for get_terms function in WooCommerce attributes html markup
*
* @return array
*/
public function getProductAttributesInLanguage($args)
{
$lang = '';
global $post;
if (isset($_GET['new_lang'])) {
$lang = esc_attr($_GET['new_lang']);
} elseif (!empty($post)) {
$lang = pll_get_post_language($post->ID);
} else {
$lang = PLL()->pref_lang;
}
$args['lang'] = $lang;
return $args;
}
示例5: wp_get_nav_menu_items
/**
* Splits the one item of backend in several items on frontend
* take care to menu_order as it is used later in wp_nav_menu
*
* @since 1.1.1
*
* @param array $items menu items
* @return array modified items
*/
public function wp_get_nav_menu_items($items)
{
if (doing_action('customize_register')) {
// needed since WP 4.3, doing_action available since WP 3.9
return $items;
}
// The customizer menus does not sort the items and we need them to be sorted before splitting the language switcher
usort($items, array($this, 'usort_menu_items'));
$new_items = array();
$offset = 0;
foreach ($items as $key => $item) {
if ($options = get_post_meta($item->ID, '_pll_menu_item', true)) {
$i = 0;
$switcher = new PLL_Switcher();
$args = array_merge(array('raw' => 1), $options);
$the_languages = $switcher->the_languages(PLL()->links, $args);
// parent item for dropdown
if (!empty($options['dropdown'])) {
$item->title = $options['show_flags'] && $options['show_names'] ? $this->curlang->flag . ' ' . esc_html($this->curlang->name) : ($options['show_flags'] ? $this->curlang->flag : esc_html($this->curlang->name));
$item->url = '';
$item->classes = array('pll-parent-menu-item');
$new_items[] = $item;
$offset++;
}
foreach ($the_languages as $lang) {
$lang_item = clone $item;
$lang_item->ID = $lang_item->ID . '-' . $lang['slug'];
// A unique ID
$lang_item->title = $options['show_flags'] && $options['show_names'] ? $lang['flag'] . '<span style="margin-left:0.3em;">' . esc_html($lang['name']) . '</span>' : ($options['show_flags'] ? $lang['flag'] : esc_html($lang['name']));
$lang_item->url = $lang['url'];
$lang_item->lang = $lang['locale'];
// Save this for use in nav_menu_link_attributes
$lang_item->classes = $lang['classes'];
$lang_item->menu_order += $offset + $i++;
if (!empty($options['dropdown'])) {
$lang_item->menu_item_parent = $item->db_id;
$lang_item->db_id = 0;
// to avoid recursion
}
$new_items[] = $lang_item;
}
$offset += $i - 1;
} else {
$item->menu_order += $offset;
$new_items[] = $item;
}
}
return $new_items;
}
示例6: define_constants
/**
* Defines two WPML constants once the language has been defined
* The compatibility with WPML is not perfect on admin side as the constants are defined
* in 'setup_theme' by Polylang ( based on user info ) and 'plugins_loaded' by WPML ( based on cookie )
*
* @since 0.9.5
*/
public function define_constants()
{
if (!empty(PLL()->curlang)) {
if (!defined('ICL_LANGUAGE_CODE')) {
define('ICL_LANGUAGE_CODE', PLL()->curlang->slug);
}
if (!defined('ICL_LANGUAGE_NAME')) {
define('ICL_LANGUAGE_NAME', PLL()->curlang->name);
}
} elseif (!PLL() instanceof PLL_Frontend) {
if (!defined('ICL_LANGUAGE_CODE')) {
define('ICL_LANGUAGE_CODE', 'all');
}
if (!defined('ICL_LANGUAGE_NAME')) {
define('ICL_LANGUAGE_NAME', '');
}
}
}
示例7: init
/**
* Finds the wpml-config.xml files to parse and setup filters
*
* @since 1.0
*/
public function init()
{
$this->xmls = array();
// Theme
if (file_exists($file = ($template = get_template_directory()) . '/wpml-config.xml') && false !== ($xml = simplexml_load_file($file))) {
$this->xmls[get_template()] = $xml;
}
// Child theme
if (($stylesheet = get_stylesheet_directory()) !== $template && file_exists($file = $stylesheet . '/wpml-config.xml') && false !== ($xml = simplexml_load_file($file))) {
$this->xmls[get_stylesheet()] = $xml;
}
// Plugins
// Don't forget sitewide active plugins thanks to Reactorshop http://wordpress.org/support/topic/polylang-and-yoast-seo-plugin/page/2?replies=38#post-4801829
$plugins = is_multisite() && ($sitewide_plugins = get_site_option('active_sitewide_plugins')) && is_array($sitewide_plugins) ? array_keys($sitewide_plugins) : array();
$plugins = array_merge($plugins, get_option('active_plugins'));
foreach ($plugins as $plugin) {
if (file_exists($file = WP_PLUGIN_DIR . '/' . dirname($plugin) . '/wpml-config.xml') && false !== ($xml = simplexml_load_file($file))) {
$this->xmls[dirname($plugin)] = $xml;
}
}
// Custom
if (file_exists($file = PLL_LOCAL_DIR . '/wpml-config.xml') && false !== ($xml = simplexml_load_file($file))) {
$this->xmls['Polylang'] = $xml;
}
if (!empty($this->xmls)) {
add_filter('pll_copy_post_metas', array($this, 'copy_post_metas'), 10, 2);
add_filter('pll_get_post_types', array($this, 'translate_types'), 10, 2);
add_filter('pll_get_taxonomies', array($this, 'translate_taxonomies'), 10, 2);
foreach ($this->xmls as $context => $xml) {
foreach ($xml->xpath('admin-texts/key') as $key) {
$attributes = $key->attributes();
$name = (string) $attributes['name'];
if (PLL() instanceof PLL_Frontend) {
$this->options[$name] = $key;
add_filter('option_' . $name, array($this, 'translate_strings'));
} else {
$this->register_string_recursive($context, get_option($name), $key);
}
}
}
}
}
示例8: wp_get_nav_menu_items
public function wp_get_nav_menu_items($items)
{
if (doing_action('customize_register')) {
// needed since WP 4.3, doing_action available since WP 3.9
return $items;
}
// the customizer menus does not sort the items and we need them to be sorted before splitting the language switcher
usort($items, array($this, 'usort_menu_items'));
$new_items = array();
$offset = 0;
foreach ($items as $key => $item) {
if ($options = get_post_meta($item->ID, '_pll_menu_item', true)) {
$i = 0;
$switcher = new PLL_Switcher();
$args = array_merge(array('raw' => 1), $options);
$the_languages = $switcher->the_languages(PLL()->links, $args);
foreach ($the_languages as $lang) {
$lang_item = clone $item;
$lang_item->ID = $lang_item->ID . '-' . $lang['slug'];
// a unique ID
$lang_item->title = $options['show_flags'] && $options['show_names'] ? $lang['flag'] . ' ' . esc_html($lang['name']) : ($options['show_flags'] ? $lang['flag'] : esc_html($lang['name']));
$lang_item->url = $lang['url'];
$lang_item->lang = $lang['locale'];
// save this for use in nav_menu_link_attributes
$lang_item->classes = $lang['classes'];
$lang_item->menu_order += $offset + $i++;
$new_items[] = $lang_item;
}
$offset += $i - 1;
} else {
$item->menu_order += $offset;
$new_items[] = $item;
}
}
return $new_items;
}
示例9: get_current_language
/**
* Get the current language by looking at the current HTTP_HOST
*
* @return null|PLL_Language
*/
public function get_current_language()
{
if ($this->languages_is_enabled()) {
return PLL()->model->get_language(pll_current_language());
}
return null;
}
示例10: jetpack_ogp
/**
* Jetpack
* Adds opengraph support for locale and translations
*
* @since 1.6
*
* @param array $tags opengraph tags to output
* @return array
*/
public function jetpack_ogp($tags)
{
if (did_action('pll_init')) {
foreach (PLL()->model->get_languages_list() as $language) {
if ($language->slug != PLL()->curlang->slug && PLL()->links->get_translation_url($language) && ($fb_locale = self::get_fb_locale($language))) {
$tags['og:locale:alternate'][] = $fb_locale;
}
if ($language->slug == PLL()->curlang->slug && ($fb_locale = self::get_fb_locale($language))) {
$tags['og:locale'] = $fb_locale;
}
}
}
return $tags;
}
示例11: mla_list_table_build_inline_data
/**
* Filter the data for inline (Quick and Bulk) editing
*
* Adds item-specific translations data for the JS quick and bulk edit functions.
*
* @since 2.11
*
* @param string $inline_data The HTML markup for inline data.
* @param object $item The current Media Library item.
*
* @return string updated HTML markup for inline data.
*/
public static function mla_list_table_build_inline_data($inline_data, $item)
{
global $polylang;
$item_id = $item->ID;
if (self::$polylang_1dot8_plus) {
$old_lang = PLL()->model->post->get_language($item_id);
$translations = PLL()->model->post->get_translations($item_id);
} else {
$old_lang = $polylang->model->get_post_language($item_id);
$translations = $polylang->model->get_translations('post', $item_id);
}
if (isset($old_lang->slug)) {
$old_lang = $old_lang->slug;
$translations[$old_lang] = $item_id;
} else {
$old_lang = '';
}
$translations = json_encode($translations);
$inline_data .= "\n\t<div class=\"lang\">{$old_lang}</div>";
$inline_data .= "\n\t<div class=\"old_lang\">{$old_lang}</div>";
$inline_data .= "\n\t<div class=\"inline_lang_choice\">{$old_lang}</div>";
$inline_data .= "\n\t<div class=\"inline_translations\">{$translations}</div>";
return $inline_data;
}
示例12: updateTrappRevision
/**
* Updates an exiting Trapp entry with a new revision.
*
* @return void.
*/
public function updateTrappRevision()
{
$service = new ServiceTranslation();
$service = $service->getById($this->trappId);
if (!empty($_POST['trapp_deadline'])) {
$deadline = esc_attr($_POST['trapp_deadline']);
update_post_meta($this->postId, self::TRAPP_META_DEADLINE, $deadline);
$deadline = new DateTime($deadline);
$service->setDeadline($deadline);
}
if (!empty($_POST['trapp_comment'])) {
$service->setComment(esc_attr($_POST['trapp_comment']));
}
if (isset($_POST['trapp_start'])) {
$service->setState('state-missing');
}
$newFields = [];
$arrayIgnore = [];
$serviceFields = $service->getFields();
$fieldGroups = Mappings::getFields(get_post_type($this->post));
foreach ($fieldGroups as $fieldGroup) {
foreach ($fieldGroup['fields'] as $field) {
$field['group'] = $fieldGroup['title'];
foreach ($serviceFields as $fieldId => $serviceField) {
if ($field['label'] == $serviceField->getLabel()) {
$value = Mappings::getValue($field['type'], $this->postId, $this->post, $field['args']);
if (!empty($value)) {
$serviceFields[$fieldId]->setValue($value);
}
continue 2;
} elseif ($field['type'] == 'post_meta_array') {
$value = Mappings::getValue($field['type'], $this->postId, $this->post, $field['args']);
$label = $serviceField->getLabel();
if (is_array($value) && array_key_exists($label, $value)) {
$serviceFields[$fieldId]->setValue($value[$label]);
$arrayIgnore[] = $label;
}
}
}
$newFields[] = $field;
}
}
$service->setFields($serviceFields);
if (!empty($newFields)) {
foreach ($newFields as $newField) {
$field = Mappings::translationField($newField, $this->postId, $this->post, $arrayIgnore);
if (!empty($field)) {
if (is_array($field)) {
foreach ($field as $singleField) {
$service->addField($singleField);
}
} else {
$service->addField($field);
}
}
}
}
$post_translations = [];
foreach ($service->getRelatedTranslations() as $serviceTranslation) {
if ($serviceTranslation->isOriginal()) {
continue;
}
$post_translations[] = $serviceTranslation->getLocale();
}
if (!empty($_POST['trapp_tr_lang'])) {
foreach ($_POST['trapp_tr_lang'] as $trapp_lang => $active) {
$trapp_lang = esc_attr($trapp_lang);
$trapp_lang = PLL()->model->get_language($trapp_lang);
if (!$trapp_lang) {
continue;
}
$locale = $this->filterLocale($trapp_lang->locale);
if (in_array($locale, $post_translations)) {
continue;
}
$service->addTranslatation($locale);
}
}
$row = $service->update();
do_action('bp_trapp_after_save_post', $row, $this->post);
}
示例13: printf
<td class="pll-language-column"><?php
printf('
<input type="hidden" name="post_tr_lang[%1$s]" id="htr_lang_%1$s" value="1"/>
<input type="checkbox" name="trapp_tr_lang[%1$s]" id="htrapp_lang_%1$s" value="1" %2$s %3$s />', esc_attr($language->slug), checked(!empty($value), true, false), disabled(!empty($value), true, false));
?>
</td>
<?php
}
?>
<?php
if ($value) {
?>
<td class="pll-edit-column"><?php
echo PLL()->links->edit_post_translation_link($value);
?>
</td>
<?php
if ($trapp_uri = get_post_meta($value, $trapp_link_key, true)) {
?>
<td class="pll-language-column"><?php
printf('<a class="button" href="%1$s">%2$s</a>', esc_url($trapp_uri), __('Edit in TRAPP', $text_domain));
?>
</td>
<?php
}
?>
<?php
示例14: wpml_language_is_active
/**
* Find out if a specific language is enabled for the site
*
* @since 2.0
*
* @param mixed $null not used
* @param string $slug language code
* @return bool
*/
public function wpml_language_is_active($null, $slug)
{
$language = PLL()->model->get_language($slug);
return empty($language->active) || true === $language->active;
}
示例15: getTermTranslationsArrayByID
/**
* Get the translations IDS of the given term ID.
*
* @global \Polylang $polylang
*
* @param int $ID term id
* @param bool $excludeDefault true to exclude default language
*
* @return array associative array with language code as key and ID of translations
* as value
*/
public static function getTermTranslationsArrayByID($ID, $excludeDefault = false)
{
global $polylang;
$IDS = PLL()->model->term->get_translations($ID);
if (true === $excludeDefault) {
unset($IDS[pll_default_language()]);
}
return $IDS;
}