public function untrash_translation($trans_id)
 {
     if (WPML_WordPress_Actions::is_bulk_untrash($trans_id)) {
         // Do nothing as the translation is part of the bulk untrash.
     } else {
         wp_untrash_post($trans_id);
     }
 }
 function make_duplicate($master_post_id, $lang)
 {
     global $wpml_post_translations;
     do_action('icl_before_make_duplicate', $master_post_id, $lang);
     $master_post = get_post($master_post_id);
     $is_duplicated = false;
     $translations = $wpml_post_translations->get_element_translations($master_post_id, false, false);
     if (isset($translations[$lang])) {
         $post_array['ID'] = $translations[$lang];
         if (WPML_WordPress_Actions::is_bulk_trash($post_array['ID']) || WPML_WordPress_Actions::is_bulk_untrash($post_array['ID'])) {
             return true;
         }
         $is_duplicated = get_post_meta($translations[$lang], '_icl_lang_duplicate_of', true);
     }
     $post_array['post_author'] = $master_post->post_author;
     $post_array['post_date'] = $master_post->post_date;
     $post_array['post_date_gmt'] = $master_post->post_date_gmt;
     $duplicated_post_content = $this->duplicate_post_content($lang, $master_post);
     $post_array['post_content'] = addslashes_gpc($duplicated_post_content);
     $duplicated_post_title = $this->duplicate_post_title($lang, $master_post);
     $post_array['post_title'] = addslashes_gpc($duplicated_post_title);
     $duplicated_post_excerpt = $this->duplicate_post_excerpt($lang, $master_post);
     $post_array['post_excerpt'] = addslashes_gpc($duplicated_post_excerpt);
     if ($this->sitepress->get_setting('sync_post_status')) {
         $sync_post_status = true;
     } else {
         $sync_post_status = !isset($post_array['ID']) || $this->sitepress->get_setting('sync_delete') && $master_post->post_status === 'trash' || $is_duplicated;
     }
     if ($sync_post_status || isset($post_array['ID']) && get_post_status($post_array['ID']) === 'auto-draft') {
         $post_array['post_status'] = $master_post->post_status;
     }
     $post_array['comment_status'] = $master_post->comment_status;
     $post_array['ping_status'] = $master_post->ping_status;
     $post_array['post_name'] = $master_post->post_name;
     if ($master_post->post_parent) {
         $parent = $this->sitepress->get_object_id($master_post->post_parent, $master_post->post_type, false, $lang);
         $post_array['post_parent'] = $parent;
     }
     $post_array['menu_order'] = $master_post->menu_order;
     $post_array['post_type'] = $master_post->post_type;
     $post_array['post_mime_type'] = $master_post->post_mime_type;
     $trid = $this->sitepress->get_element_trid($master_post->ID, 'post_' . $master_post->post_type);
     $id = $this->save_duplicate($post_array, $lang);
     require_once ICL_PLUGIN_PATH . '/inc/cache.php';
     icl_cache_clear();
     global $ICL_Pro_Translation;
     /** @var WPML_Pro_Translation $ICL_Pro_Translation */
     if ($ICL_Pro_Translation) {
         $ICL_Pro_Translation->_content_fix_links_to_translated_content($id, $lang);
     }
     if (!is_wp_error($id)) {
         $ret = $this->run_wpml_actions($master_post, $trid, $lang, $id, $post_array);
     } else {
         $ret = false;
     }
     return $ret;
 }
Пример #3
0
 public function save_post_actions($pidd, $post)
 {
     global $sitepress, $wpdb;
     wp_defer_term_counting(true);
     $post = isset($post) ? $post : get_post($pidd);
     // exceptions
     if (!$this->has_save_post_action($post)) {
         wp_defer_term_counting(false);
         return;
     }
     if (WPML_WordPress_Actions::is_bulk_trash($pidd) || WPML_WordPress_Actions::is_bulk_untrash($pidd)) {
         return;
     }
     $default_language = $sitepress->get_default_language();
     // allow post arguments to be passed via wp_insert_post directly and not be expected on $_POST exclusively
     $post_vars = (array) $_POST;
     foreach ((array) $post as $k => $v) {
         $post_vars[$k] = $v;
     }
     $post_vars['post_type'] = isset($post_vars['post_type']) ? $post_vars['post_type'] : $post->post_type;
     $post_id = $pidd;
     if (isset($post_vars['action']) && $post_vars['action'] === 'post-quickpress-publish') {
         $language_code = $default_language;
     } else {
         $post_id = isset($post_vars['post_ID']) ? $post_vars['post_ID'] : $pidd;
         //latter case for XML-RPC publishing
         $language_code = $this->get_save_post_lang($post_id, $sitepress);
     }
     if ($this->is_inline_action($post_vars) && !($language_code = $this->get_element_lang_code($post_id))) {
         return;
     }
     if (isset($post_vars['icl_translation_of']) && is_numeric($post_vars['icl_translation_of'])) {
         $translation_of_data_prepared = $wpdb->prepare("SELECT trid, language_code\n\t\t\t\t FROM {$wpdb->prefix}icl_translations\n\t\t\t\t WHERE element_id=%d\n\t\t\t\t  AND element_type=%s", $post_vars['icl_translation_of'], 'post_' . $post->post_type);
         list($trid, $source_language) = $wpdb->get_row($translation_of_data_prepared, 'ARRAY_N');
     }
     $trid = isset($trid) && $trid ? $trid : $this->get_save_post_trid($post_id, $post->post_status);
     // after getting the right trid set the source language from it by referring to the root translation
     // of this trid, in case no proper source language has been set yet
     $source_language = isset($source_language) ? $source_language : $this->get_save_post_source_lang($trid, $language_code, $default_language);
     $this->maybe_set_elid($trid, $post->post_type, $language_code, $post_id, $source_language);
     $translation_sync = $this->get_sync_helper();
     $original_id = $this->get_original_element($post_id);
     if ($original_id) {
         $translation_sync->sync_with_translations($original_id, $post_vars);
     }
     if (isset($post_vars['icl_tn_note'])) {
         update_post_meta($post_id, '_icl_translator_note', $post_vars['icl_tn_note']);
     }
     require_once ICL_PLUGIN_PATH . '/inc/cache.php';
     icl_cache_clear($post_vars['post_type'] . 's_per_language', true);
     wp_defer_term_counting(false);
 }
 public function save_post_actions($pidd, $post)
 {
     global $sitepress;
     wp_defer_term_counting(true);
     $post = isset($post) ? $post : get_post($pidd);
     // exceptions
     if (!$this->has_save_post_action($post)) {
         wp_defer_term_counting(false);
         return;
     }
     if (WPML_WordPress_Actions::is_bulk_trash($pidd) || WPML_WordPress_Actions::is_bulk_untrash($pidd) || WPML_WordPress_Actions::is_heartbeat()) {
         return;
     }
     $default_language = $sitepress->get_default_language();
     $post_vars = (array) $_POST;
     foreach ((array) $post as $k => $v) {
         $post_vars[$k] = $v;
     }
     $post_vars['post_type'] = isset($post_vars['post_type']) ? $post_vars['post_type'] : $post->post_type;
     $post_id = $pidd;
     if (isset($post_vars['action']) && $post_vars['action'] === 'post-quickpress-publish') {
         $language_code = $default_language;
     } else {
         $post_id = isset($post_vars['post_ID']) ? $post_vars['post_ID'] : $pidd;
         //latter case for XML-RPC publishing
         $language_code = $this->get_save_post_lang($post_id, $sitepress);
     }
     if ($this->is_inline_action($post_vars) && !($language_code = $this->get_element_lang_code($post_id))) {
         return;
     }
     if (isset($post_vars['icl_translation_of']) && is_numeric($post_vars['icl_translation_of'])) {
         $translation_of_data_prepared = $this->wpdb->prepare("SELECT trid, language_code\n\t\t\t\t FROM {$this->wpdb->prefix}icl_translations\n\t\t\t\t WHERE element_id=%d\n\t\t\t\t\tAND element_type=%s\n\t\t\t\t LIMIT 1", $post_vars['icl_translation_of'], 'post_' . $post->post_type);
         list($trid, $source_language) = $this->wpdb->get_row($translation_of_data_prepared, 'ARRAY_N');
     }
     if (isset($post_vars['icl_translation_of']) && $post_vars['icl_translation_of'] == 'none') {
         $trid = null;
         $source_language = $language_code;
     } else {
         $trid = isset($trid) && $trid ? $trid : $this->get_save_post_trid($post_id, $post->post_status);
         // after getting the right trid set the source language from it by referring to the root translation
         // of this trid, in case no proper source language has been set yet
         $source_language = isset($source_language) ? $source_language : $this->get_save_post_source_lang($trid, $language_code, $default_language);
     }
     if (isset($post_vars['icl_tn_note'])) {
         update_post_meta($post_id, '_icl_translator_note', $post_vars['icl_tn_note']);
     }
     $save_filter_action_state = new WPML_WP_Filter_State('save_post');
     $this->after_save_post($trid, $post_vars, $language_code, $source_language);
     $save_filter_action_state->restore();
 }
 public function untrash_translation($trans_id)
 {
     if (!WPML_WordPress_Actions::is_bulk_untrash($trans_id)) {
         wp_untrash_post($trans_id);
     }
 }
 function make_duplicate($master_post_id, $lang)
 {
     global $wpml_post_translations, $wpml_language_resolution;
     static $duplicated_post_ids;
     if (!isset($duplicated_post_ids)) {
         $duplicated_post_ids = array();
     }
     //It is already done? (avoid infinite recursions)
     if (!$wpml_language_resolution->is_language_active($lang) || in_array($master_post_id . '|' . $lang, $duplicated_post_ids)) {
         return true;
     }
     $duplicated_post_ids[] = $master_post_id . '|' . $lang;
     global $sitepress, $sitepress_settings;
     do_action('icl_before_make_duplicate', $master_post_id, $lang);
     $master_post = get_post($master_post_id);
     $is_duplicated = false;
     $translations = $wpml_post_translations->get_element_translations($master_post_id, false, false);
     if (isset($translations[$lang])) {
         $post_array['ID'] = $translations[$lang];
         if (WPML_WordPress_Actions::is_bulk_trash($post_array['ID']) || WPML_WordPress_Actions::is_bulk_untrash($post_array['ID'])) {
             return true;
         }
         $is_duplicated = get_post_meta($translations[$lang], '_icl_lang_duplicate_of', true);
     }
     $post_array['post_author'] = $master_post->post_author;
     $post_array['post_date'] = $master_post->post_date;
     $post_array['post_date_gmt'] = $master_post->post_date_gmt;
     $post_array['post_content'] = addslashes_gpc(apply_filters('icl_duplicate_generic_string', $master_post->post_content, $lang, array('context' => 'post', 'attribute' => 'content', 'key' => $master_post->ID)));
     $post_array['post_title'] = addslashes_gpc(apply_filters('icl_duplicate_generic_string', $master_post->post_title, $lang, array('context' => 'post', 'attribute' => 'title', 'key' => $master_post->ID)));
     $post_array['post_excerpt'] = addslashes_gpc(apply_filters('icl_duplicate_generic_string', $master_post->post_excerpt, $lang, array('context' => 'post', 'attribute' => 'excerpt', 'key' => $master_post->ID)));
     if (isset($sitepress_settings['sync_post_status']) && $sitepress_settings['sync_post_status']) {
         $sync_post_status = true;
     } else {
         $sync_post_status = !isset($post_array['ID']) || $sitepress_settings['sync_delete'] && $master_post->post_status == 'trash' || $is_duplicated;
     }
     if ($sync_post_status || isset($post_array['ID']) && get_post_status($post_array['ID']) === 'auto-draft') {
         $post_array['post_status'] = $master_post->post_status;
     }
     $post_array['comment_status'] = $master_post->comment_status;
     $post_array['ping_status'] = $master_post->ping_status;
     $post_array['post_name'] = $master_post->post_name;
     if ($master_post->post_parent) {
         $parent = icl_object_id($master_post->post_parent, $master_post->post_type, false, $lang);
         $post_array['post_parent'] = $parent;
     }
     $post_array['menu_order'] = $master_post->menu_order;
     $post_array['post_type'] = $master_post->post_type;
     $post_array['post_mime_type'] = $master_post->post_mime_type;
     $trid = $sitepress->get_element_trid($master_post->ID, 'post_' . $master_post->post_type);
     $id = $this->save_duplicate($post_array, $lang);
     require_once ICL_PLUGIN_PATH . '/inc/cache.php';
     icl_cache_clear();
     global $ICL_Pro_Translation;
     /** @var WPML_Pro_Translation $ICL_Pro_Translation */
     if ($ICL_Pro_Translation) {
         $ICL_Pro_Translation->_content_fix_links_to_translated_content($id, $lang);
     }
     if (!is_wp_error($id)) {
         $ret = $this->run_wpml_actions($master_post, $trid, $lang, $id, $post_array);
     } else {
         $ret = false;
     }
     return $ret;
 }