->get_results( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $this->populate_cache( $elements ); if ( $element_id && ! isset( $this->translations[ $element_id ] ) ) { $this->translations[ $element_id ] = array(); } } return ! empty( $this->translations[ $element_id ] ); } private function group_and_populate_cache( $elements ) { $trids = array(); foreach ( $elements as $element ) { $trid = $element['trid']; if ( ! isset( $trids[ $trid ] ) ) { $trids[ $trid ] = array(); } $trids[ $trid ][] = $element; } foreach ( $trids as $trid_group ) { $this->populate_cache( $trid_group ); } } private function populate_cache( $elements ) { if ( ! $elements ) { return; } $element_ids = array(); foreach ( $elements as $element ) { $element_id = $element['element_id']; $language_code = $element['language_code']; $element_ids[ $language_code ] = $element_id; $this->element_data[ $element_id ] = array( 'translation_id' => $element['translation_id'], 'trid' => $element['trid'], 'lang' => $language_code, 'source_lang' => $element['source_language_code'], 'type' => substr( $element['element_type'], $this->type_prefix_length ), ); $this->translation_ids_element[ $element['translation_id'] ] = $element_id; } foreach ( $element_ids as $element_id ) { $trid = $this->element_data[ $element_id ]['trid']; $this->trid_groups[ $trid ] = $element_ids; $this->translations[ $element_id ] = &$this->trid_groups[ $trid ]; } } private function filter_for_actual_trans( $element_id ) { $res = $this->translations[ $element_id ]; foreach ( $res as $lang => $element ) { if ( $this->element_data[ $element ]['source_lang'] !== $this->element_data[ $element_id ]['lang'] ) { unset( $res[ $lang ] ); } } return $res; } /** * @param int $post_id * * @return bool */ public function is_a_duplicate( $post_id ) { return (bool) get_post_meta( $post_id, '_icl_lang_duplicate_of', true ); } }