本文整理汇总了PHP中pll_get_post_language函数的典型用法代码示例。如果您正苦于以下问题:PHP pll_get_post_language函数的具体用法?PHP pll_get_post_language怎么用?PHP pll_get_post_language使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pll_get_post_language函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPostLanguage
/**
* @param int $postId the post id
* @return string language of the post or false if not found
*/
public static function getPostLanguage($postId)
{
if (function_exists('pll_get_post_language')) {
return pll_get_post_language($postId);
}
return false;
}
示例2: syncProductsMeta
/**
* Sync porduct meta
*
* @return false if the current post type is not "porduct"
*/
public function syncProductsMeta()
{
$currentScreen = get_current_screen();
if ($currentScreen->post_type !== 'product') {
return false;
}
// sync product meta with polylang
add_filter('pll_copy_post_metas', array(__CLASS__, 'getProductMetaToCopy'));
$ID = false;
$disable = false;
/*
* Disable editing product meta for translation
*
* if the "post" is defined in $_GET then we should check if the current
* porduct has a translation and it is the same as the default translation
* lang defined in polylang then porduct meta editing must by enabled
*
* if the "new_lang" is defined or if the current page is the "edit"
* page then porduct meta editing must by disabled
*/
if (isset($_GET['post'])) {
$ID = absint($_GET['post']);
$disable = $ID && pll_get_post_language($ID) != pll_default_language();
} elseif (isset($_GET['new_lang']) || $currentScreen->base == 'edit') {
$disable = isset($_GET['new_lang']) && esc_attr($_GET['new_lang']) != pll_default_language() ? true : false;
$ID = isset($_GET['from_post']) ? absint($_GET['from_post']) : false;
}
// disable fields edit for translation
if ($disable) {
add_action('admin_print_scripts', array($this, 'addFieldsLocker'), 100);
}
/* sync selected prodcut type */
$this->syncSelectedProdcutType($ID);
}
示例3: 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;
}
示例4: display_payment_language
public function display_payment_language($payment_id)
{
?>
<div class="column-container">
<div class="column">
<strong><?php
_e('Language:', 'edd-polylang');
?>
</strong>
<input type="text" name="edd-payment-language" value="<?php
echo esc_attr(pll_get_post_language($payment_id, 'name'));
?>
" class="medium-text"/>
</div>
</div>
<?php
}
示例5: change
/**
* Change the product stock in the given order item.
*
* @param array $item the order data
* @param string $action STOCK_REDUCE_ACTION | STOCK_INCREASE_ACTION
*/
protected function change(array $item, $action = self::STOCK_REDUCE_ACTION)
{
$productID = $item['product_id'];
$productObject = wc_get_product($productID);
$productLang = pll_get_post_language($productID);
$variationID = $item['variation_id'];
/* Handle Products */
if ($productObject && $productLang) {
/* Get the translations IDS */
$translations = Utilities::getProductTranslationsArrayByObject($productObject);
/* Remove the current product from translation array */
unset($translations[$productLang]);
$isManageStock = $productObject->managing_stock();
$isVariation = $variationID && $variationID > 0;
$method = $action === self::STOCK_REDUCE_ACTION ? 'reduce_stock' : 'increase_stock';
$change = $action === self::STOCK_REDUCE_ACTION ? $item['qty'] : $item['change'];
/* Sync stock for all translation */
foreach ($translations as $ID) {
/* Only if product is managing stock */
if ($isManageStock) {
if ($translation = wc_get_product($ID)) {
$translation->{$method}($change);
}
}
$general = Settings::getOption('general', MetasList::getID(), array('total_sales'));
if (in_array('total_sales', $general)) {
update_post_meta($ID, 'total_sales', get_post_meta($productID, 'total_sales', true));
}
}
/* Handle variation */
if ($isVariation) {
$posts = Variation::getRelatedVariation($variationID);
foreach ($posts as $post) {
if ($post->ID == $variationID) {
continue;
}
$variation = wc_get_product($post);
if ($variation && $variation->managing_stock()) {
$variation->{$method}($change);
}
}
}
}
}
示例6: syncProductsMeta
/**
* Sync product meta.
*
* @return false if the current post type is not "product"
*/
public function syncProductsMeta()
{
// sync product meta with polylang
add_filter('pll_copy_post_metas', array(__CLASS__, 'getProductMetaToCopy'));
// Shipping Class translation is not supported after WooCommerce 2.6 but it is
// still implemented by WooCommerce as a taxonomy. Therefore Polylang will not
// copy the Shipping Class meta. We need to take care of it.
if (Utilities::woocommerceVersionCheck('2.6')) {
add_action('wp_insert_post', array($this, 'syncShippingClass'), 10, 3);
}
$currentScreen = get_current_screen();
if ($currentScreen->post_type !== 'product') {
return false;
}
$ID = false;
$disable = false;
/*
* Disable editing product meta for translation
*
* if the "post" is defined in $_GET then we should check if the current
* product has a translation and it is the same as the default translation
* lang defined in polylang then product meta editing must by enabled
*
* if the "new_lang" is defined or if the current page is the "edit"
* page then product meta editing must by disabled
*/
if (isset($_GET['post'])) {
$ID = absint($_GET['post']);
$disable = $ID && pll_get_post_language($ID) != pll_default_language();
} elseif (isset($_GET['new_lang']) || $currentScreen->base == 'edit') {
$disable = isset($_GET['new_lang']) && esc_attr($_GET['new_lang']) != pll_default_language() ? true : false;
$ID = isset($_GET['from_post']) ? absint($_GET['from_post']) : false;
// Add the '_translation_porduct_type' meta, for the case where
// the product was created before plugin acivation.
$this->addProductTypeMeta($ID);
}
// disable fields edit for translation
if ($disable) {
add_action('admin_print_scripts', array($this, 'addFieldsLocker'), 100);
}
/* sync selected product type */
$this->syncSelectedproductType($ID);
}
示例7: polylang_slug_unique_slug_in_language
/**
* Checks if the slug is unique within language.
*
* @since 0.1.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $slug The desired slug (post_name).
* @param int $post_ID Post ID.
* @param string $post_status No uniqueness checks are made if the post is still draft or pending.
* @param string $post_type Post type.
* @param int $post_parent Post parent ID.
*
* @return string Unique slug for the post within language, based on $post_name (with a -1, -2, etc. suffix).
*/
function polylang_slug_unique_slug_in_language($slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug)
{
// Return slug if it was not changed.
if ($original_slug === $slug) {
return $slug;
}
global $wpdb;
// Get language of a post
$lang = pll_get_post_language($post_ID);
$options = get_option('polylang');
// return the slug if Polylang does not return post language or has incompatable redirect setting or is not translated post type.
if (empty($lang) || 0 === $options['force_lang'] || !pll_is_translated_post_type($post_type)) {
return $slug;
}
// " INNER JOIN $wpdb->term_relationships AS pll_tr ON pll_tr.object_id = ID".
$join_clause = polylang_slug_model_post_join_clause();
// " AND pll_tr.term_taxonomy_id IN (" . implode(',', $languages) . ")".
$where_clause = polylang_slug_model_post_where_clause($lang);
// Polylang does not translate attachements - skip if it is one.
// @TODO Recheck this with the Polylang settings
if ('attachment' == $post_type) {
// Attachment slugs must be unique across all types.
$check_sql = "SELECT post_name FROM {$wpdb->posts} {$join_clause} WHERE post_name = %s AND ID != %d {$where_clause} LIMIT 1";
$post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $original_slug, $post_ID));
} elseif (is_post_type_hierarchical($post_type)) {
// Page slugs must be unique within their own trees. Pages are in a separate
// namespace than posts so page slugs are allowed to overlap post slugs.
$check_sql = "SELECT ID FROM {$wpdb->posts} {$join_clause} WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d {$where_clause} LIMIT 1";
$post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $original_slug, $post_type, $post_ID, $post_parent));
} else {
// Post slugs must be unique across all posts.
$check_sql = "SELECT post_name FROM {$wpdb->posts} {$join_clause} WHERE post_name = %s AND post_type = %s AND ID != %d {$where_clause} LIMIT 1";
$post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $original_slug, $post_type, $post_ID));
}
if (!$post_name_check) {
return $original_slug;
} else {
return $slug;
}
}
示例8: syncProductsMeta
/**
* Sync porduct meta
*
* @return false if the current post type is not "product"
*/
public function syncProductsMeta()
{
// sync product meta with polylang
add_filter('pll_copy_post_metas', array(__CLASS__, 'getProductMetaToCopy'));
$currentScreen = get_current_screen();
if ($currentScreen->post_type !== 'product') {
return false;
}
$ID = false;
$disable = false;
/*
* Disable editing product meta for product translations
*
* In case of a "Add or update product" ($GET['post'] is set), and the
* product language is different from the default, it is a product translation
* and editing the product metadata should be disabled.
*
* In case of a "Add product translation" ($GET['new_lang'] is set), or the
* 'edit' page, editing product metadata should be disabled.
*/
if (isset($_GET['post'])) {
// Add or update product
$ID = absint($_GET['post']);
$disable = $ID && pll_get_post_language($ID) != pll_default_language();
} elseif (isset($_GET['new_lang']) || $currentScreen->base == 'edit') {
// Add product translation
$ID = isset($_GET['from_post']) ? absint($_GET['from_post']) : false;
$disable = isset($_GET['new_lang']) && esc_attr($_GET['new_lang']) != pll_default_language() ? true : false;
// Add the '_translation_porduct_type' meta,for the case the product
// was created before plugin acivation.
$this->add_product_type_meta($ID);
}
// disable fields edit for product translations
if ($disable) {
add_action('admin_print_scripts', array($this, 'addFieldsLocker'), 100);
}
// sync the product type selection in the product data settings box
$this->sync_product_type_selection($ID);
}
示例9: 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);
}
}
示例10: jetpack_widget_get_top_posts
public function jetpack_widget_get_top_posts($posts, $post_ids, $count)
{
foreach ($posts as $k => $post) {
if (pll_current_language() !== pll_get_post_language($post['post_id'])) {
unset($posts[$k]);
}
}
return $posts;
}
示例11: jetpack_relatedposts_filter_filters
/**
* Jetpack
* Allows to make sure that related posts are in the correct language
*
* @since 1.8
*
* @param array $filters Array of ElasticSearch filters based on the post_id and args.
* @param string $post_id Post ID of the post for which we are retrieving Related Posts.
* @return array
*/
function jetpack_relatedposts_filter_filters($filters, $post_id)
{
$slug = sanitize_title(pll_get_post_language($post_id, 'name'));
$filters[] = array('term' => array('taxonomy.language.slug' => $slug));
return $filters;
}
示例12: 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);
}
示例13: getOrderLangauge
/**
* Get the order language
*
* @param integer $ID order ID
*
* @return string|false language in success , false otherwise
*/
public static function getOrderLangauge($ID)
{
return pll_get_post_language($ID);
}
示例14: edit_form_top
public function edit_form_top()
{
global $post_ID;
printf('<input type="hidden" id="post_lang_choice" name="post_lang_choice" value="%s" />', pll_get_post_language($post_ID));
wp_nonce_field('pll_language', '_pll_nonce');
}
示例15: listing_images_default
/**
* 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;
}
}