本文整理汇总了PHP中pll_get_term函数的典型用法代码示例。如果您正苦于以下问题:PHP pll_get_term函数的具体用法?PHP pll_get_term怎么用?PHP pll_get_term使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pll_get_term函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hyyan_slider_query
/**
* Build WP_Query object for the given slider
*
* @see Hyyan_Slider_Shortcode::FILTER_SHORTCODE_QueryArgs
*
* @param string $slider slider name
* @param string $order slides order
* @param string $orderBy order slides by ?
*
* @return \WP_Query
* @throws \RuntimeException if the slider does not exist
*/
function hyyan_slider_query($slider, $order = 'DESC', $orderBy = 'rand')
{
$slider = esc_attr((string) $slider);
/** check for term existance */
if (!term_exists($slider, Hyyan_Slider::CUSTOM_TAXONOMY)) {
throw new \RuntimeException(sprintf('Can not build query for %s slider - term does not exist', $slider));
}
if (function_exists('pll_get_term')) {
// get slider object
$term = get_term_by('slug', $slider, Hyyan_Slider::CUSTOM_TAXONOMY);
$slider = $term->slug;
if ($term) {
// find the id of translated slider
$id = pll_get_term($term->term_id);
// get translated slider object
$trans_term = get_term($id, Hyyan_Slider::CUSTOM_TAXONOMY);
if ($trans_term && !$trans_term instanceof WP_Error) {
$slider = $trans_term->slug;
}
}
}
/**
* Query object
*
* @see Hyyan_Slider_Shortcode::FILTER_SHORTCODE_QueryArgs
*
* @var WP_Query
*/
$query = new WP_Query(apply_filters(Hyyan_Slider_Events::FILTER_SHORTCODE_QueryArgs, array('post_type' => Hyyan_Slider::CUSTOM_POST, 'taxonomy' => Hyyan_Slider::CUSTOM_TAXONOMY, 'term' => $slider, 'post_status' => 'publish', 'order' => esc_attr($order), 'orderby' => esc_attr($orderBy), 'posts_per_page' => -1, 'lang' => null)));
return $query;
}
示例2: shim_untranslated
public function shim_untranslated($query_args, $args)
{
$def_lang = pll_default_language();
$cur_lang = pll_current_language();
$mixed = $cur_lang != $def_lang;
if (apply_filters('listify_polylang_only_selected', false)) {
return $query_args;
}
if (isset($query_args['tax_query']) && $mixed) {
$taxes = $query_args['tax_query'];
foreach ($taxes as $key => $tax) {
$terms = $tax['terms'];
$trans = array();
if (is_array($terms)) {
foreach ($terms as $term) {
// annoying since we have slugs but get an id but need back to slugs
$obj = get_term_by('slug', $term, $tax['taxonomy']);
$trans = pll_get_term($obj->term_id, $def_lang);
$trans = get_term_by('id', $trans, $tax['taxonomy']);
$query_args['tax_query'][$key]['terms'] = array_merge($terms, array($trans->slug));
}
}
}
}
$terms = get_terms('post_translations');
$exclude = array();
foreach ($terms as $translation) {
$trans = unserialize($translation->description);
if ($mixed) {
$exclude[] = $trans[$def_lang];
}
}
if ($mixed) {
if (isset($query_args['post__in'])) {
$query_args['post__in'] = array_diff($query_args['post__in'], $exclude);
unset($query_args['post__not_in']);
} else {
$query_args['post__not_in'] = $exclude;
}
}
return $query_args;
}
示例3: layeredNavInit
/**
* Layered Nav Init
*
* @global array $_chosen_attributes
*
* @return false if not layered nav filter
*/
public function layeredNavInit()
{
if (!(is_active_widget(false, false, 'woocommerce_layered_nav', true) && !is_admin())) {
return false;
}
global $_chosen_attributes;
$attributes = wc_get_attribute_taxonomies();
foreach ($attributes as $tax) {
$attribute = wc_sanitize_taxonomy_name($tax->attribute_name);
$taxonomy = wc_attribute_taxonomy_name($attribute);
$name = 'filter_' . $attribute;
if (!(!empty($_GET[$name]) && taxonomy_exists($taxonomy))) {
continue;
}
$terms = explode(',', $_GET[$name]);
$termsTranslations = array();
foreach ($terms as $ID) {
$translation = pll_get_term($ID);
$termsTranslations[] = $translation ? $translation : $ID;
}
$_GET[$name] = implode(',', $termsTranslations);
$_chosen_attributes[$taxonomy]['terms'] = $termsTranslations;
}
}
示例4: translate_tax_query_recursive
protected function translate_tax_query_recursive($tax_queries)
{
foreach ($tax_queries as $key => $q) {
if (isset($q['taxonomy']) && $this->model->is_translated_taxonomy($q['taxonomy'])) {
$arr = array();
$field = isset($q['field']) && in_array($q['field'], array('slug', 'name')) ? $q['field'] : 'term_id';
foreach ((array) $q['terms'] as $t) {
$arr[] = ($tag = get_term_by($field, $t, $q['taxonomy'])) && ($tr_id = pll_get_term($tag->term_id)) && !is_wp_error($tr = get_term($tr_id, $q['taxonomy'])) ? $tr->{$field} : $t;
}
$tax_queries[$key]['terms'] = $arr;
} elseif (is_array($q)) {
$tax_queries[$key] = $this->translate_tax_query_recursive($q);
}
}
return $tax_queries;
}
示例5: twenty_fourteen_option_featured_content
/**
* Twenty Fourteen
* Translates the featured tag id in featured content settings
* Mainly to allow hiding it when requested in featured content options
* Acts only on frontend
*
* @since 1.4
*
* @param array $settings featured content settings
* @return array modified $settings
*/
public function twenty_fourteen_option_featured_content($settings)
{
if (!PLL_ADMIN && $settings['tag-id'] && ($tr = pll_get_term($settings['tag-id']))) {
$settings['tag-id'] = $tr;
}
return $settings;
}
示例6: tc_pll_translate_tax
/**
* Tax filtering (home/blog posts filtered by cat)
* @param array of term ids
*/
function tc_pll_translate_tax($term_ids)
{
if (!(is_array($term_ids) && !empty($term_ids))) {
return $term_ids;
}
$translated_terms = array();
foreach ($term_ids as $id) {
$translated_term = pll_get_term($id);
$translated_terms[] = $translated_term ? $translated_term : $id;
}
return array_unique($translated_terms);
}
示例7: skip_default_attributes_meta
public function skip_default_attributes_meta($check, $object_id, $meta_key, $meta_value)
{
// Ignore if not default attribute
if ('_default_attributes' === $meta_key) {
$product = wc_get_product($object_id);
// Don't let anyone delete the meta. NO ONE!
if ($product && current_filter() === 'delete_post_metadata') {
return false;
}
// _default_attributes meta should be unique
if ($product && current_filter() === 'add_post_metadata') {
$old_value = get_post_meta($product->id, '_default_attributes');
return empty($old_value) ? $check : false;
}
// Maybe is Variable Product
// New translations of Variable Products are first created as simple
if ($product && Utilities::maybe_variable_product($product)) {
// Try Polylang first
$lang = pll_get_post_language($product->id);
if (!$lang) {
// Must be a new translation and Polylang doesn't stored the language yet
$lang = isset($_GET['new_lang']) ? $_GET['new_lang'] : '';
}
foreach ($meta_value as $key => $value) {
$term = get_term_by('slug', $value, $key);
if ($term && pll_is_translated_taxonomy($term->taxonomy)) {
$translated_term_id = pll_get_term($term->term_id, $lang);
$translated_term = get_term_by('id', $translated_term_id, $term->taxonomy);
// If meta is taxonomy managed by Polylang and is in the
// correct language process, otherwise return false to
// stop execution
return $value === $translated_term->slug ? $check : false;
}
}
}
}
return $check;
}
示例8: pll_translation_url_filter
/**
* Fix "PLL_Frontend_Links->get_translation_url()".
*/
public function pll_translation_url_filter($url, $lang)
{
global $wp_query, $polylang;
if (is_category()) {
$term = get_category_by_slug($wp_query->get('category_name'));
$translated_term = get_term(pll_get_term($term->term_id, $lang), $term->taxonomy);
return home_url('/' . $lang . '/' . $translated_term->slug);
} elseif (is_archive()) {
$post_type = $wp_query->query_vars['post_type'];
// If the post type is handle, let the "$this->get_post_type_archive_link"
// function handle this.
if (isset($this->post_types[$post_type])) {
return $this->get_post_type_archive_link($post_type, $lang);
}
}
return $url;
}
开发者ID:jussikinnula,项目名称:wp-polylang-translate-rewrite-slugs,代码行数:20,代码来源:polylang-translate-rewrite-slugs.php
示例9: getPolylangRedirectUrl
private function getPolylangRedirectUrl($lang_code)
{
global $polylang;
$lang = $polylang->model->get_language($lang_code);
$from = $this->site_url . $this->request_uri;
if (is_singular() && !is_front_page()) {
$translated_post_id = pll_get_post(get_queried_object_id(), $lang->slug);
if ($translated_post_id && get_post_status($translated_post_id) === 'publish') {
return get_permalink($translated_post_id);
} else {
return new WP_Error('404', __('Page Not Found', 'wp-geo-redirect'));
}
}
if (is_front_page()) {
return pll_home_url($lang->slug);
}
if (is_home()) {
if (get_option('show_on_front') === 'page') {
$translated_post_id = pll_get_post(get_option('page_for_posts'), $lang->slug);
if ($translated_post_id && get_post_status($translated_post_id) === 'publish') {
return get_permalink($translated_post_id);
} else {
return new WP_Error('404', __('Page Not Found', 'wp-geo-redirect'));
}
} else {
return pll_home_url($lang->slug);
}
}
if (is_search()) {
return $polylang->links_model->switch_language_in_link($from, $lang);
}
if (is_tax() || is_category() || is_tag()) {
$translated_term_id = pll_get_term(get_queried_object_id(), $lang->slug);
if (get_queried_object_id() === $translated_term_id) {
return;
}
return get_term_link($translated_term_id, get_queried_object()->taxonomy);
}
return $polylang->links_model->switch_language_in_link($from, $lang);
}
示例10: translateCategoryIDS
/**
* Translate Category IDS for category report
*
* @global \Polylang $polylang
* @global \WooCommerce $woocommerce
*
* @return false if woocommerce or polylang not found
*/
public function translateCategoryIDS()
{
global $polylang, $woocommerce;
if (!$polylang || !$woocommerce) {
return false;
}
/* Check for product_ids */
if (!isset($_GET['show_categories'])) {
return false;
}
if (!static::isCombine() && (isset($_GET['lang']) && esc_attr($_GET['lang']) !== 'all')) {
$IDS = (array) $_GET['show_categories'];
$extendedIDS = array();
$lang = esc_attr($_GET['lang']);
foreach ($IDS as $ID) {
$translation = pll_get_term($ID, $lang);
if ($translation) {
$extendedIDS[] = $translation;
}
}
if (!empty($extendedIDS)) {
$_GET['show_categories'] = $extendedIDS;
}
}
}
示例11: twenty_fourteen_option_featured_content
/**
* Twenty Fourteen
* Translates the featured tag id in featured content settings
* Mainly to allow hiding it when requested in featured content options
* Acts only on frontend
*
* @since 1.4
*
* @param array $settings featured content settings
* @return array modified $settings
*/
public function twenty_fourteen_option_featured_content($settings)
{
if (PLL() instanceof PLL_Frontend && $settings['tag-id'] && ($tr = pll_get_term($settings['tag-id']))) {
$settings['tag-id'] = $tr;
}
return $settings;
}
示例12: get_terms_args
public function get_terms_args($args, $taxonomies)
{
if (!empty($args['include']) && $this->model->is_translated_taxonomy($taxonomies)) {
foreach (wp_parse_id_list($args['include']) as $id) {
$arr[] = ($tr = pll_get_term($id)) ? $tr : $id;
}
$args['include'] = $arr;
}
return $args;
}
示例13: 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;
}
示例14: getTranslatedTerms
/**
* Get an array with all available translations for a given term
*
* @param int $termID
* @return array Indexed array with as key the language code, and as value the post id
*/
public function getTranslatedTerms($termID)
{
$languages = pll_the_languages(array('raw' => 1));
$result = array();
foreach ($languages as $lang) {
$lang = $lang['slug'];
$transTermID = pll_get_term($termID, $lang);
if (is_int($transTermID) && $transTermID !== $termID) {
$result[$lang] = $transTermID;
}
}
return $result;
}
示例15: add_to_cart_handler_variable
/**
* Custom add to cart handler for variable products
*
* Based on function add_to_cart_handler_variable( $product_id ) from
* <install_dir>/wp-content/plugins/woocommerce/includes/class-wc-form-handler.php
* but using $url as argument.Therefore we use the initial bits from
* add_to_cart_action( $url ).
*
* @param string $url Add to cart url (e.g. https://www.yourdomain.com/?add-to-cart=123&quantity=1&variation_id=117&attribute_size=Small&attribute_color=Black )
*/
public function add_to_cart_handler_variable($url)
{
// From add_to_cart_action( $url )
if (empty($_REQUEST['add-to-cart']) || !is_numeric($_REQUEST['add-to-cart'])) {
return;
}
$product_id = apply_filters('woocommerce_add_to_cart_product_id', absint($_REQUEST['add-to-cart']));
$was_added_to_cart = false;
$adding_to_cart = wc_get_product($product_id);
if (!$adding_to_cart) {
return;
}
// End: From add_to_cart_action( $url )
// From add_to_cart_handler_variable( $product_id )
$variation_id = empty($_REQUEST['variation_id']) ? '' : absint($_REQUEST['variation_id']);
$quantity = empty($_REQUEST['quantity']) ? 1 : wc_stock_amount($_REQUEST['quantity']);
$missing_attributes = array();
$variations = array();
$attributes = $adding_to_cart->get_attributes();
// If no variation ID is set, attempt to get a variation ID from posted attributes.
if (empty($variation_id)) {
$variation_id = $adding_to_cart->get_matching_variation(wp_unslash($_POST));
}
/**
* Custom code to check if a translation of the product is already in the
* cart,* and in that case, replace the variation being added to the cart
* by the respective translation in the language of the product already
* in the cart.
* NOTE: The product_id is filtered by $this->add_to_cart() and holds the
* id of the product translation, if one exists in the cart.
*/
if ($product_id != absint($_REQUEST['add-to-cart'])) {
// There is a translation of the product already in the cart:
// Get the language of the product in the cart
$lang = pll_get_post_language($product_id);
// Get the respective variation in the language of the product in the cart
$variation = $this->get_variation_translation($variation_id, $lang);
$variation_id = $variation->variation_id;
} else {
$variation = wc_get_product($variation_id);
}
/**
* End of custom code.
*/
//$variation = wc_get_product( $variation_id );
// Verify all attributes
foreach ($attributes as $attribute) {
if (!$attribute['is_variation']) {
continue;
}
$taxonomy = 'attribute_' . sanitize_title($attribute['name']);
if (isset($_REQUEST[$taxonomy])) {
// Get value from post data
if ($attribute['is_taxonomy']) {
// Don't use wc_clean as it destroys sanitized characters
$value = sanitize_title(stripslashes($_REQUEST[$taxonomy]));
/**
* Custom code to check if a translation of the product is already in the cart,
* and in that case, replace the variation attribute being added to the cart by
* the respective translation in the language of the product already in the cart
* NOTE: The product_id is filtered by $this->add_to_cart() and holds the id of
* the product translation, if one exists in the cart.
*/
if ($product_id != absint($_REQUEST['add-to-cart'])) {
// Get the translation of the term
$term = get_term_by('slug', $value, $attribute['name']);
$_term = get_term_by('id', pll_get_term(absint($term->term_id), $lang), $attribute['name']);
if ($_term) {
$value = $_term->slug;
}
}
/**
* End of custom code.
*/
} else {
$value = wc_clean(stripslashes($_REQUEST[$taxonomy]));
}
// Get valid value from variation
$valid_value = isset($variation->variation_data[$taxonomy]) ? $variation->variation_data[$taxonomy] : '';
// Allow if valid
if ('' === $valid_value || $valid_value === $value) {
$variations[$taxonomy] = $value;
continue;
}
} else {
$missing_attributes[] = wc_attribute_label($attribute['name']);
}
}
if (!empty($missing_attributes)) {
wc_add_notice(sprintf(_n('%s is a required field', '%s are required fields', sizeof($missing_attributes), 'woocommerce'), wc_format_list_of_items($missing_attributes)), 'error');
//.........这里部分代码省略.........