/**
  * Modify and extend the substitution values used for the Bulk Edit on Upload form.
  *
  * @since 2.20
  *
  * @param	array	$page_values [ parameter_name => parameter_value ] pairs
  */
 public static function mla_upload_bulk_edit_form_values($page_values)
 {
     /*
      * Add markup to the $page_values ['custom_fields'] element for the "Always translate" checkbox
      */
     if (class_exists('WPML_Media')) {
         $content_defaults = WPML_Media::get_setting('new_content_settings');
         if (isset($content_defaults['always_translate_media']) && $content_defaults['always_translate_media']) {
             $true_selected = 'selected="selected"';
             $false_selected = '';
         } else {
             $true_selected = '';
             $false_selected = 'selected="selected"';
         }
         $page_values['custom_fields'] .= '      <label class="inline-edit-c_0 clear"><span class="title">WPML</span><span class="input-text-wrap">' . "\n";
         $page_values['custom_fields'] .= '      <select name="mla_always_translate_media">' . "\n";
         $page_values['custom_fields'] .= '        <option ' . $true_selected . ' value="true">' . __('Yes', 'media-library-assistant') . '&nbsp;</option>' . "\n";
         $page_values['custom_fields'] .= '        <option ' . $false_selected . ' value="false">' . __('No', 'media-library-assistant') . '&nbsp;</option>' . "\n";
         $page_values['custom_fields'] .= '      </select><span>&nbsp;' . __('Make media available in all languages', 'media-library-assistant') . '</span>' . "\n";
         $page_values['custom_fields'] .= '      </span></label>' . "\n";
     }
     return $page_values;
 }
 /**
  * Add a duplicate translation for an item, then redirect to the Media/Edit Media screen
  *
  * @since 2.11
  *
  * @param	string	$mla_admin_action	the requested action.
  * @param	integer	$mla_item_ID		zero (0), or the affected attachment.
  */
 public static function mla_list_table_custom_admin_action($mla_admin_action, $mla_item_ID)
 {
     if ('wpml_create_translation' == $mla_admin_action) {
         $new_item = WPML_Media::create_duplicate_attachment($mla_item_ID, $_REQUEST['mla_parent_ID'], $_REQUEST['lang']);
         $view_args = isset($_REQUEST['mla_source']) ? array('mla_source' => $_REQUEST['mla_source']) : array();
         wp_redirect(add_query_arg($view_args, admin_url('post.php') . '?action=edit&post=' . $new_item . '&message=201'), 302);
         exit;
     }
 }
 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();
 }
Exemplo n.º 4
0
 /**
  *    Needed by class init and by all static methods that use self::$settings
  */
 public static function init_settings()
 {
     if (!self::$settings) {
         self::$settings = get_option(self::$settings_option_key);
     }
     $default_settings = array('version' => false, 'starting_help' => false, 'new_content_settings' => array('always_translate_media' => true, 'duplicate_media' => true, 'duplicate_featured' => true));
     if (!self::$settings) {
         self::$settings = $default_settings;
     }
 }
Exemplo n.º 5
0
 function sync_thumbnail_id($orig_post_id, $trnsl_post_id, $lang)
 {
     if (defined('WPML_MEDIA_VERSION')) {
         $thumbnail_id = get_post_meta($orig_post_id, '_thumbnail_id', true);
         $trnsl_thumbnail = apply_filters('translate_object_id', $thumbnail_id, 'attachment', false, $lang);
         if (is_null($trnsl_thumbnail) && $thumbnail_id) {
             $trnsl_thumbnail = WPML_Media::create_duplicate_attachment($thumbnail_id, wp_get_post_parent_id($thumbnail_id), $lang);
         }
         update_post_meta($trnsl_post_id, '_thumbnail_id', $trnsl_thumbnail);
         update_post_meta($orig_post_id, '_wpml_media_duplicate', 1);
         update_post_meta($orig_post_id, '_wpml_media_featured', 1);
     }
 }