id=%d AND element_type = %s", array( $attachment->post_parent, 'post_' . $post_type ) ); $trid = $this->wpdb->get_var( $trid_prepared ); if ( $trid ) { update_post_meta( $attachment->post_parent, '_wpml_media_duplicate', 1 ); $attachments_prepared = $this->wpdb->prepare( "SELECT ID FROM {$this->wpdb->posts} WHERE post_type = %s AND post_parent = %d", array( 'attachment', $attachment->post_parent ) ); $attachments = $this->wpdb->get_col( $attachments_prepared ); $translations = $this->sitepress->get_element_translations( $trid, 'post_' . $post_type ); foreach ( $translations as $translation ) { if ( $translation->element_id && $translation->element_id != $attachment->post_parent ) { $attachments_in_translation_prepared = $this->wpdb->prepare( "SELECT ID FROM {$this->wpdb->posts} WHERE post_type = %s AND post_parent = %d", array( 'attachment', $translation->element_id ) ); $attachments_in_translation = $this->wpdb->get_col( $attachments_in_translation_prepared ); if ( sizeof( $attachments_in_translation ) == 0 ) { // only duplicate attachments if there a none already. foreach ( $attachments as $attachment_id ) { // duplicate the attachment self::create_duplicate_attachment( $attachment_id, $translation->element_id, $translation->language_code ); } } } } } $parents_processed[] = $attachment->post_parent; } else { // no parent - set to default language $target_language = $this->sitepress->get_default_language(); //Getting the trid and language, just in case image translation already exists $trid = $this->sitepress->get_element_trid( $attachment->ID, 'post_attachment' ); if ( $trid ) { $target_language = $this->sitepress->get_language_for_element( $attachment->ID, 'post_attachment' ); } $this->sitepress->set_element_language_details( $attachment->ID, 'post_attachment', $trid, $target_language ); } //Duplicate the post meta of the source element the translation $source_element_id = SitePress::get_original_element_id_by_trid( $trid ); if ( $source_element_id ) { $this->update_attachment_metadata( $source_element_id ); } update_post_meta( $attachment->ID, 'wpml_media_processed', 1 ); } function set_content_defaults_prepare() { $response = array( 'message' => __( 'Started...', 'sitepress' ) ); echo wp_json_encode( $response ); exit; } function set_content_defaults() { $always_translate_media = $_POST[ 'always_translate_media' ]; $duplicate_media = $_POST[ 'duplicate_media' ]; $duplicate_featured = $_POST[ 'duplicate_featured' ]; $content_defaults_option = array( 'always_translate_media' => $always_translate_media == 'true', 'duplicate_media' => $duplicate_media == 'true', 'duplicate_featured' => $duplicate_featured == 'true' ); $settings = get_option( '_wpml_media' ); $settings['new_content_settings'] = $content_defaults_option; update_option( '_wpml_media', $settings ); $response = array( 'result' => true, 'message' => __( 'Settings saved', 'sitepress' ) ); wp_send_json_success( $response ); } }