uage from the HTTP Referer. This is used in case of ajax actions * that save the term. * * @param string $taxonomy * @param string $post_action * * @return null|string */ public function get_term_lang_ajax( $taxonomy, $post_action ) { if ( isset( $_POST['_ajax_nonce'] ) && filter_var( $_POST['_ajax_nonce'] ) !== false && $post_action === 'add-' . $taxonomy ) { $referrer = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : ''; parse_str( (string) wpml_parse_url( $referrer, PHP_URL_QUERY ), $qvars ); $term_lang = ! empty( $qvars['post'] ) && $this->sitepress->is_translated_post_type( get_post_type( $qvars['post'] ) ) ? $this->post_translations->get_element_lang_code( $qvars['post'] ) : ( isset( $qvars['lang'] ) ? $qvars['lang'] : null ); } return isset( $term_lang ) ? $term_lang : null; } private function get_saved_term_trid( $tt_id, $post_action ) { if ( $post_action === 'editpost' ) { $trid = $this->term_translations->get_element_trid( $tt_id ); } elseif ( $post_action === 'editedtag' ) { $translation_of = filter_input( INPUT_POST, 'icl_translation_of', FILTER_VALIDATE_INT ); $translation_of = $translation_of ? $translation_of : filter_input( INPUT_POST, 'icl_translation_of' ); $trid = $translation_of === 'none' ? false : ( $translation_of ? $this->term_translations->get_element_trid( $translation_of ) : $trid = filter_input( INPUT_POST, 'icl_trid', FILTER_SANITIZE_NUMBER_INT ) ); } else { $trid = filter_input( INPUT_POST, 'icl_trid', FILTER_SANITIZE_NUMBER_INT ); $trid = $trid ? $trid : $this->term_translations->get_element_trid( filter_input( INPUT_POST, 'icl_translation_of', FILTER_VALIDATE_INT ) ); $trid = $trid ? $trid : $this->term_translations->get_element_trid( $tt_id ); } return $trid; } /** * @param int $term_taxonomy_id * @param string $taxonomy * @param array $translations */ private function delete_translations( $term_taxonomy_id, $taxonomy, array $translations ) { $has_filter = remove_filter( 'get_term', array( $this->sitepress, 'get_term_adjust_id' ), 1 ); foreach ( $translations as $translation ) { if ( (int) $translation->element_id !== (int) $term_taxonomy_id ) { wp_delete_term( $translation->term_id, $taxonomy ); } } if ( $has_filter ) { add_filter( 'get_term', array( $this->sitepress, 'get_term_adjust_id' ), 1, 1 ); } } }