本文整理汇总了PHP中SitePress::get_original_element_id方法的典型用法代码示例。如果您正苦于以下问题:PHP SitePress::get_original_element_id方法的具体用法?PHP SitePress::get_original_element_id怎么用?PHP SitePress::get_original_element_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SitePress
的用法示例。
在下文中一共展示了SitePress::get_original_element_id方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_original
/**
* Returns the original EM_Location object from the provided EM_Location object
* @param EM_Location|EM_Event $object
* @return EM_Location|EM_Event
*/
public static function get_original($object)
{
global $em_wpml_original_cache, $pagenow;
if (!empty($em_wpml_original_cache[$object->blog_id][$object->post_id])) {
//we have done this before....
$original_post_id = $em_wpml_original_cache[$object->blog_id][$object->post_id];
//retrieve cached ID
} else {
//find the original post id via WPML
$original_post_id = SitePress::get_original_element_id($object->post_id, 'post_' . $object->post_type);
//check a few admin specific stuff if a standard check didn't work, in case we're in the admin area translating via WPML
if (empty($original_post_id) && is_admin()) {
if (!empty($_REQUEST['trid'])) {
//we are adding a new translation belonging to a trid set
$original_post_id = SitePress::get_original_element_id_by_trid($_REQUEST['trid']);
} elseif (!empty($_REQUEST['icl_translation_of'])) {
//a new translation has just been submitted
$translation_of = $_REQUEST['icl_translation_of'];
//could be a translation from another translation, e.g. try adding a translation from a second language
$original_post_id = SitePress::get_original_element_id($translation_of, 'post_' . $object->post_type);
}
}
}
//save to the cache (whether already saved or not)
$em_wpml_original_cache[$object->blog_id][$object->post_id] = $original_post_id;
//if the post_ids don't match then the original translation is different to the one passed on, so switch the $object to that translation
if ($original_post_id != $object->post_id) {
//get the EM_Event or EM_Location object
if ($object->post_type == EM_POST_TYPE_EVENT) {
$object = em_get_event($original_post_id, 'post_id');
} elseif ($object->post_type == EM_POST_TYPE_LOCATION) {
$object = em_get_location($original_post_id, 'post_id');
}
}
return $object;
}
示例2: __construct
//.........这里部分代码省略.........
}
//No filtering necessary here. All language filtering is done be the subsequent functionality.
remove_all_filters('terms_clauses');
remove_all_filters('list_terms_exclusions');
$_terms = get_terms($this->taxonomy, $get_terms_args);
// on search - force include parents
if (!empty($this->search)) {
if ($_terms) {
foreach ($_terms as $term) {
$in_results = false;
foreach ($_terms as $term2) {
if ($term2->term_id == $term->parent) {
$in_results = true;
break;
}
}
if (!$in_results) {
while ($term->parent > 0) {
$term = get_term($term->parent, $this->taxonomy);
$_terms[] = $term;
}
}
}
}
}
$this->terms_count = count($_terms);
$_terms = $this->order_terms_by_hierarchy($_terms);
$this->current_page = isset($this->args['page']) ? $this->args['page'] : 1;
$offset = ($this->current_page - 1) * WPML_TT_TERMS_PER_PAGE;
$this->terms = array_slice($_terms, $offset, WPML_TT_TERMS_PER_PAGE);
// prepend parents if needed
if (isset($this->terms[0])) {
while ($this->terms[0]->parent > 0 && $this->terms[0]->parent != $this->child_of) {
foreach ($_terms as $term) {
if ($term->term_id == $this->terms[0]->parent) {
$guide_parent = $term;
break;
}
}
if (!empty($guide_parent)) {
array_unshift($this->terms, $guide_parent);
}
}
}
unset($_terms);
if (is_wp_error($this->terms)) {
$this->error = sprintf(__('Unknown taxonomy: %s'), $this->taxonomy);
return false;
}
if (empty($this->terms) || is_wp_error($this->terms)) {
return;
}
// limit for pagination?
// get term taxonomy ids
foreach ($this->terms as $term) {
$tt_ids[] = $term->term_taxonomy_id;
}
// get list of matching trids
$trids = $wpdb->get_col($wpdb->prepare("SELECT trid FROM {$wpdb->prefix}icl_translations WHERE element_type = %s AND element_id IN (" . join(',', $tt_ids) . ")", 'tax_' . $this->taxonomy));
// get terms by trids
$res = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->prefix}icl_translations WHERE element_type = %s AND trid IN (" . join(',', $trids) . ")", 'tax_' . $this->taxonomy));
$terms_by_trid = array();
foreach ($res as $row) {
$terms_by_trid[$row->trid][$row->language_code] = array('term_taxonomy_id' => $row->element_id, 'source_lang' => $row->source_language_code);
}
$terms_in_old_format = $this->terms;
$this->terms = array();
foreach ($terms_by_trid as $trid => $term_translation) {
foreach ($term_translation as $lang => $term_trid_array) {
foreach ($terms_in_old_format as $key => $term_object) {
if (isset($term_object->term_taxonomy_id) && $term_object->term_taxonomy_id == $term_trid_array['term_taxonomy_id']) {
if (!$term_trid_array['source_lang']) {
$term_object->translation_of = $term_object->term_taxonomy_id;
} else {
$term_object->translation_of = SitePress::get_original_element_id($term_object->term_taxonomy_id, 'tax' . $taxonomy);
}
$this->terms[$trid][$lang] = $term_object;
if ($term_object->translation_of == $term_object->term_taxonomy_id || !isset($this->terms[$trid]['source_lang'])) {
$this->terms[$trid]['source_lang'] = $lang;
}
}
}
}
}
/* If we try to filter for untranslated terms, we will not show any row that has translations in every language. */
foreach ($this->terms as $key => $translated_terms) {
$all_found = true;
foreach ($this->selected_languages as $lang => $langauge) {
if (!isset($translated_terms[$lang])) {
$all_found = false;
}
}
if (!$all_found && isset($_active_languages[$translated_terms['source_lang']])) {
/* If we try to filter for untranslated terms, we will always show the original element and its column.*/
$this->selected_languages[$translated_terms['source_lang']] = $_active_languages[$translated_terms['source_lang']];
} elseif (isset($this->args['status']) && $this->args['status'] == 1) {
unset($this->terms[$key]);
}
}
}