public static function get_job_id_from_request() { /** * @var TranslationManagement $iclTranslationManagement * @var WPML_Post_Translation $wpml_post_translations */ global $iclTranslationManagement, $wpml_post_translations, $wpml_translation_job_factory, $sitepress, $wpdb; $job_id = filter_input(INPUT_GET, 'job_id', FILTER_SANITIZE_NUMBER_INT); $trid = filter_input(INPUT_GET, 'trid', FILTER_SANITIZE_NUMBER_INT); $language_code = filter_input(INPUT_GET, 'language_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $source_language_code = filter_input(INPUT_GET, 'source_language_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS); if (!$job_id && $trid && $language_code) { $job_id = $iclTranslationManagement->get_translation_job_id($trid, $language_code); if (!$job_id) { if (!$source_language_code) { $post_id = SitePress::get_original_element_id_by_trid($trid); } else { $posts_in_trid = $wpml_post_translations->get_element_translations(false, $trid); $post_id = isset($posts_in_trid[$source_language_code]) ? $posts_in_trid[$source_language_code] : false; } $blog_translators = wpml_tm_load_blog_translators(); $args = array('lang_from' => $source_language_code, 'lang_to' => $language_code, 'job_id' => $job_id); if ($post_id && $blog_translators->is_translator($sitepress->get_current_user()->ID, $args)) { $job_id = $wpml_translation_job_factory->create_local_post_job($post_id, $language_code); } } } return $job_id; }
public static function get_job_id_from_request() { /** * @var TranslationManagement $iclTranslationManagement * @var WPML_Post_Translation $wpml_post_translations */ global $iclTranslationManagement, $wpml_post_translations, $wpml_translation_job_factory; $job_id = filter_input(INPUT_GET, 'job_id', FILTER_SANITIZE_NUMBER_INT); $trid = filter_input(INPUT_GET, 'trid', FILTER_SANITIZE_NUMBER_INT); $language_code = filter_input(INPUT_GET, 'language_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $source_language_code = filter_input(INPUT_GET, 'source_language_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS); if (!$job_id && $trid && $language_code) { $job_id = $iclTranslationManagement->get_translation_job_id($trid, $language_code); if (!$job_id) { if (!$source_language_code) { $post_id = SitePress::get_original_element_id_by_trid($trid); } else { $posts_in_trid = $wpml_post_translations->get_element_translations(false, $trid); $post_id = isset($posts_in_trid[$source_language_code]) ? $posts_in_trid[$source_language_code] : false; } if ($post_id && current_user_can('manage_options', $post_id)) { $job_id = $wpml_translation_job_factory->create_local_post_job($post_id, $language_code); } } } return $job_id; }
public static function em_ml_admin_original_event_link($link) { global $EM_Event; if (empty($EM_Event->event_id) && !empty($_REQUEST['trid'])) { $post_id = SitePress::get_original_element_id_by_trid($_REQUEST['trid']); $original_event_link = em_get_event($post_id, 'post_id')->get_edit_url(); } return $link; }
/** * Print the Single Taxonomy Metabox * * @author Andrea Grillo <*****@*****.**> * @since 1.0.0 * * @param $taxonomy string Taxonomy Name * @param $taxonomy_box string Taxonomy Box * * @return void */ public function single_taxonomy_meta_box($taxonomy, $taxonomy_box) { $taxonomy_label = YITH_Vendors()->get_vendors_taxonomy_label(); $vendor = yith_get_vendor('current', 'product'); $vendor_id = 0; $wpml_vendor = null; /* WPML Support */ global $sitepress, $pagenow; if ($vendor->is_valid()) { if (isset($sitepress)) { $vendor_id = yit_wpml_object_id($vendor->id, YITH_Vendors()->get_taxonomy_name(), true); $wpml_vendor = get_term_by('id', $vendor_id, $vendor->term->taxonomy); $vendor_id = $wpml_vendor->term_id; } else { $vendor_id = $vendor->id; } } elseif (isset($sitepress) && $vendor->is_super_user() && 'post-new.php' == $pagenow && !empty($_GET['trid'])) { $original_product_id = SitePress::get_original_element_id_by_trid($_GET['trid']); $original_vendor = yith_get_vendor($original_product_id, 'product'); if ($original_vendor->is_valid()) { $vendor_id = yit_wpml_object_id($original_vendor->id, YITH_Vendors()->get_taxonomy_name(), true); $wpml_vendor = get_term_by('id', $vendor_id, $original_vendor->term->taxonomy); $vendor_id = $wpml_vendor->term_id; } } $args = array('id' => 'tax-input-yith_shop_vendor', 'name' => 'tax_input[yith_shop_vendor]', 'taxonomy' => $this->_taxonomy_name, 'show_option_none' => !$vendor->is_super_user() ? '' : sprintf(__('No %s'), strtolower($taxonomy_label['singular_name'])), 'hide_empty' => !$vendor->is_super_user(), 'selected' => $vendor_id, 'walker' => YITH_Walker_CategoryDropdown(), 'option_none_value' => ''); $vendor = yith_get_vendor('current', 'user'); if ($vendor->is_valid() && $vendor->has_limited_access() && $vendor->is_user_admin()) { echo is_null($wpml_vendor) ? $vendor->name : $wpml_vendor->name; } else { wp_dropdown_categories($args); } }
/** * @param $attachment WP_Post */ function create_duplicated_media($attachment) { global $wpdb, $sitepress; static $parents_processed = array(); if ($attachment->post_parent && !in_array($attachment->post_parent, $parents_processed)) { // see if we have translations. $post_type_prepared = $wpdb->prepare("SELECT post_type FROM {$wpdb->posts} WHERE ID = %d", array($attachment->post_parent)); $post_type = $wpdb->get_var($post_type_prepared); $trid_prepared = $wpdb->prepare("SELECT trid FROM {$wpdb->prefix}icl_translations WHERE element_id=%d AND element_type = %s", array($attachment->post_parent, 'post_' . $post_type)); $trid = $wpdb->get_var($trid_prepared); if ($trid) { update_post_meta($attachment->post_parent, '_wpml_media_duplicate', 1); $attachments_prepared = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_parent = %d", array('attachment', $attachment->post_parent)); $attachments = $wpdb->get_col($attachments_prepared); $translations = $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 = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND post_parent = %d", array('attachment', $translation->element_id)); $attachments_in_translation = $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 = $sitepress->get_default_language(); //Getting the trid and language, just in case image translation already exists $trid = $sitepress->get_element_trid($attachment->ID, 'post_attachment'); if ($trid) { $target_language = $sitepress->get_language_for_element($attachment->ID, 'post_attachment'); } $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); }
/** * @param $args * Creates an automatic translation of a term, the name of which is set as "original" . @ "lang_code" and the slug of which is set as "original_slug" . - . "lang_code". * * @return array|bool */ public static function create_automatic_translation($args) { global $sitepress; $term = false; $lang_code = false; $taxonomy = false; $original_id = false; $original_tax_id = false; $trid = false; $original_term = false; $update_translations = false; $source_language = null; extract($args, EXTR_OVERWRITE); if ($trid && !$original_id) { $original_tax_id = SitePress::get_original_element_id_by_trid($trid); $original_term = get_term_by('term_taxonomy_id', $original_tax_id, $taxonomy, OBJECT, 'no'); } if ($original_id && !$original_tax_id) { $original_term = get_term($original_id, $taxonomy, OBJECT, 'no'); if (isset($original_term['term_taxonomy_id'])) { $original_tax_id = $original_term['term_taxonomy_id']; } } if (!$trid) { $trid = $sitepress->get_element_trid($original_tax_id, 'tax_' . $taxonomy); } if (!$source_language) { $source_language = $sitepress->get_source_language_by_trid($trid); } $existing_translations = $sitepress->get_element_translations($trid, 'tax_' . $taxonomy); if ($lang_code && isset($existing_translations[$lang_code])) { $new_translated_term = false; } else { if (!$original_term) { if ($original_id) { $original_term = get_term($original_id, $taxonomy, OBJECT, 'no'); } elseif ($original_tax_id) { $original_term = get_term_by('term_taxonomy_id', $original_tax_id, $taxonomy, OBJECT, 'no'); } } $translated_slug = false; if (!$term && isset($original_term->name)) { $term = $original_term->name; } if (isset($original_term->slug)) { $translated_slug = self::term_unique_slug($original_term->slug, $taxonomy, $lang_code); } $new_translated_term = false; if ($term) { $new_term_args = array('term' => $term, 'slug' => $translated_slug, 'taxonomy' => $taxonomy, 'lang_code' => $lang_code, 'original_tax_id' => $original_tax_id, 'update_translations' => $update_translations, 'trid' => $trid, 'source_language' => $source_language); $new_translated_term = self::create_new_term($new_term_args); } } return $new_translated_term; }
/** * Returns the original EM_Location object from the provided EM_Location object * @param EM_Location|EM_Event $object * @return EM_Location|EM_Event */ public static function get_original($object) { global $em_wpml_original_cache, $pagenow; if (!empty($em_wpml_original_cache[$object->blog_id][$object->post_id])) { //we have done this before.... $original_post_id = $em_wpml_original_cache[$object->blog_id][$object->post_id]; //retrieve cached ID } else { //find the original post id via WPML $original_post_id = SitePress::get_original_element_id($object->post_id, 'post_' . $object->post_type); //check a few admin specific stuff if a standard check didn't work, in case we're in the admin area translating via WPML if (empty($original_post_id) && is_admin()) { if (!empty($_REQUEST['trid'])) { //we are adding a new translation belonging to a trid set $original_post_id = SitePress::get_original_element_id_by_trid($_REQUEST['trid']); } elseif (!empty($_REQUEST['icl_translation_of'])) { //a new translation has just been submitted $translation_of = $_REQUEST['icl_translation_of']; //could be a translation from another translation, e.g. try adding a translation from a second language $original_post_id = SitePress::get_original_element_id($translation_of, 'post_' . $object->post_type); } } } //save to the cache (whether already saved or not) $em_wpml_original_cache[$object->blog_id][$object->post_id] = $original_post_id; //if the post_ids don't match then the original translation is different to the one passed on, so switch the $object to that translation if ($original_post_id != $object->post_id) { //get the EM_Event or EM_Location object if ($object->post_type == EM_POST_TYPE_EVENT) { $object = em_get_event($original_post_id, 'post_id'); } elseif ($object->post_type == EM_POST_TYPE_LOCATION) { $object = em_get_location($original_post_id, 'post_id'); } } return $object; }