get_element_trid( $post_id, $wpml_post_type ); $translations = $sitepress->get_element_translations( $trid, $wpml_post_type ); if ( ! $translations ) { return (int) $post_id; } foreach ( $translations as $translation ) { if ( $translation->original ) { $source_id = $translation->element_id; break; } } return (int) $source_id; } /** * @param SitePress $sitepress * * @return array */ private static function init_settings( SitePress $sitepress ) { $tm_settings = $sitepress->get_setting( 'translation-management' ); /** * Until a user explicitly change the settings through * the switcher ( @see WPML_TM_Post_Edit_TM_Editor_Select::save_mode ), * we'll set it by default at run time: * - Native editor set to true if using the manual method * - Native editor set to false otherwise */ if ( ! isset( $tm_settings['post_translation_editor_native'] ) ) { if ( ( (string) ICL_TM_TMETHOD_MANUAL === (string) $tm_settings['doc_translation_method'] ) ) { $tm_settings['post_translation_editor_native'] = true; } else { $tm_settings['post_translation_editor_native'] = false; } if ( ! isset( $tm_settings['post_translation_editor_native_for_post_type'] ) ) { $tm_settings['post_translation_editor_native_for_post_type'] = array(); } } return $tm_settings; } /** * @param null|string $post_type */ public static function delete_all_posts_option( $post_type = null ) { global $wpdb; if ( $post_type ) { $wpdb->query( $wpdb->prepare( "DELETE postmeta FROM {$wpdb->postmeta} AS postmeta INNER JOIN {$wpdb->posts} AS posts ON posts.ID = postmeta.post_id WHERE posts.post_type = %s AND postmeta.meta_key = %s", $post_type, self::POST_META_KEY_USE_NATIVE ) ); } else { delete_post_meta_by_key( self::POST_META_KEY_USE_NATIVE ); } } }