public static function save_term_ajax($sitepress, $lang, $taxonomy, $slug, $name, $trid, $description) { $new_term_object = false; if ($name !== "" && $taxonomy && $trid && $lang) { $args = array('taxonomy' => $taxonomy, 'lang_code' => $lang, 'term' => $name, 'trid' => $trid, 'overwrite' => true); if ($slug) { $args['slug'] = $slug; } if ($description) { $args['description'] = $description; } $switch_lang = new WPML_Temporary_Switch_Language($sitepress, $lang); $res = WPML_Terms_Translations::create_new_term($args); $switch_lang->restore_lang(); if ($res && isset($res['term_taxonomy_id'])) { /* res holds the term taxonomy id, we return the whole term objects to the ajax call */ $switch_lang = new WPML_Temporary_Switch_Language($sitepress, $lang); $new_term_object = get_term_by('term_taxonomy_id', (int) $res['term_taxonomy_id'], $taxonomy); $switch_lang->restore_lang(); $lang_details = $sitepress->get_element_language_details($new_term_object->term_taxonomy_id, 'tax_' . $new_term_object->taxonomy); $new_term_object->trid = $lang_details->trid; $new_term_object->language_code = $lang_details->language_code; WPML_Terms_Translations::icl_save_term_translation_action($taxonomy, $res); } } return $new_term_object; }
public function get($page_name, $lang, $output = OBJECT, $post_type = 'page') { $this->language = $lang; add_filter('query', array($this, 'get_page_by_path_filter')); $temp_lang_switch = new WPML_Temporary_Switch_Language($this->sitepress, $lang); $page = get_page_by_path($page_name, $output, $post_type); $temp_lang_switch->restore_lang(); remove_filter('query', array($this, 'get_page_by_path_filter')); return $page; }