/** * Captures the Bulk Edit, "Upload New Media" parameters * * @since 2.11 * * @param array $request bulk action request parameters, including ['mla_bulk_action_do_cleanup']. * @param string $bulk_action the requested action. * @param array $custom_field_map [ slug => field_name ] * * @return array updated bulk action request parameters */ public static function mla_list_table_bulk_action_initial_request($request, $bulk_action, $custom_field_map) { MLACore::mla_debug_add(__LINE__ . " MLA_WPML::mla_list_table_bulk_action_initial_request( {$bulk_action} ) request = " . var_export($request, true), MLACore::MLA_DEBUG_CATEGORY_LANGUAGE); /* * Check for Bulk Edit processing during Upload New Media */ if (!empty($_REQUEST['mlaAddNewBulkEditFormString'])) { /* * It is now safe to restore the WPML option settings if they have been * changed for this upload */ if (!empty(self::$wpml_content_defaults)) { WPML_Media::update_setting('new_content_settings', self::$wpml_content_defaults); } /* * Suppress WPML processing in wpml-media.class.php function save_attachment_actions, * which wipes out attachment meta data. */ global $action; $action = 'upload-plugin'; } self::$bulk_edit_request = $request; self::$bulk_edit_map = $custom_field_map; return $request; }
private static function upgrade_2_0() { global $wpdb; global $sitepress; //Check if the old options are set and in case move them to the new plugin settings, then delete the old ones $old_starting_help = get_option('_wpml_media_starting_help'); if ($old_starting_help) { WPML_Media::update_setting('starting_help', $old_starting_help); delete_option('_wpml_media_starting_help'); } //Create translated media $target_language = $sitepress->get_default_language(); $attachment_ids_prepared = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s", 'attachment'); $attachment_ids = $wpdb->get_col($attachment_ids_prepared); //Let's first set the language of all images in default languages foreach ($attachment_ids as $attachment_id) { $wpml_media_lang = get_post_meta($attachment_id, 'wpml_media_lang', true); $wpml_media_duplicate_of = get_post_meta($attachment_id, 'wpml_media_duplicate_of', true); if (!$wpml_media_duplicate_of && (!$wpml_media_lang || $wpml_media_lang == $target_language)) { $trid = $sitepress->get_element_trid($attachment_id, 'post_attachment'); if ($trid) { //Since trid exists, get the language from there $target_language = $sitepress->get_language_for_element($attachment_id, 'post_attachment'); } $sitepress->set_element_language_details($attachment_id, 'post_attachment', $trid, $target_language); } } //Then all the translations foreach ($attachment_ids as $attachment_id) { $wpml_media_lang = get_post_meta($attachment_id, 'wpml_media_lang', true); $wpml_media_duplicate_of = get_post_meta($attachment_id, 'wpml_media_duplicate_of', true); if ($wpml_media_duplicate_of) { $source_language = null; $trid = $sitepress->get_element_trid($wpml_media_duplicate_of, 'post_attachment'); $source_language = false; if ($trid) { //Get the source language of the attachment, just in case is from a language different than the default $source_language = $sitepress->get_language_for_element($wpml_media_duplicate_of, 'post_attachment'); //Fix bug on 1.6, where duplicated images are set to the default language if ($wpml_media_lang == $source_language) { $wpml_media_lang = false; $attachment = get_post($attachment_id); if ($attachment->post_parent) { $parent_post = get_post($attachment->post_parent); $post_parent_language = $sitepress->get_language_for_element($parent_post->ID, 'post_' . $parent_post->post_type); if ($post_parent_language) { $wpml_media_lang = $post_parent_language; } } if (!$wpml_media_lang) { //Trash orphan image wp_delete_attachment($attachment_id); } } } if ($wpml_media_lang) { $sitepress->set_element_language_details($attachment_id, 'post_attachment', $trid, $wpml_media_lang, $target_language, $source_language); } } } //Remove old media translation meta //Remove both meta just in case $attachment_ids = $wpdb->get_col($attachment_ids_prepared); foreach ($attachment_ids as $attachment_id) { delete_post_meta($attachment_id, 'wpml_media_duplicate_of'); delete_post_meta($attachment_id, 'wpml_media_lang'); } //Featured images WPML_Media::duplicate_featured_images(); }