/**
  * Ajax handler for adding a term via Ajax.
  */
 public static function wpml_save_term()
 {
     if (!wpml_is_action_authenticated('wpml_save_term')) {
         wp_send_json_error('Wrong Nonce');
     }
     global $sitepress;
     $lang = filter_input(INPUT_POST, 'term_language_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
     $taxonomy = filter_input(INPUT_POST, 'taxonomy');
     $slug = filter_input(INPUT_POST, 'slug');
     $name = filter_input(INPUT_POST, 'name');
     $trid = filter_input(INPUT_POST, 'trid', FILTER_SANITIZE_NUMBER_INT);
     $description = filter_input(INPUT_POST, 'description');
     $new_term_object = false;
     if ($name !== "" && $taxonomy && $trid && $lang) {
         $args = array('taxonomy' => $taxonomy, 'lang_code' => $lang, 'term' => $name, 'trid' => $trid, 'overwrite' => true);
         if ($slug) {
             $args['slug'] = $slug;
         }
         if ($description) {
             $args['description'] = $description;
         }
         $res = WPML_Terms_Translations::create_new_term($args);
         if ($res && isset($res['term_taxonomy_id'])) {
             /* res holds the term taxonomy id, we return the whole term objects to the ajax call */
             $new_term_object = get_term_by('term_taxonomy_id', (int) $res['term_taxonomy_id'], $taxonomy);
             $lang_details = $sitepress->get_element_language_details($new_term_object->term_taxonomy_id, 'tax_' . $new_term_object->taxonomy);
             $new_term_object->trid = $lang_details->trid;
             $new_term_object->language_code = $lang_details->language_code;
             WPML_Terms_Translations::icl_save_term_translation_action($taxonomy, $res);
         }
     }
     wp_send_json_success($new_term_object);
 }
 /**
  * Ajax handler for saving label translations from the WPML Taxonomy Translations menu.
  */
 public function save_label_translations()
 {
     if (!wpml_is_action_authenticated('wpml_tt_save_labels_translation')) {
         wp_send_json_error('Wrong Nonce');
     }
     $general = isset($_POST['plural']) ? $_POST['plural'] : false;
     $singular = isset($_POST['singular']) ? $_POST['singular'] : false;
     $taxonomy = isset($_POST['taxonomy']) ? $_POST['taxonomy'] : false;
     $language = isset($_POST['taxonomy_language_code']) ? $_POST['taxonomy_language_code'] : false;
     if ($singular && $general && $taxonomy && $language) {
         $tax_label_data = $this->get_label_translations(false, $taxonomy);
         if (isset($tax_label_data['id_singular']) && $tax_label_data['id_singular'] && isset($tax_label_data['id_general']) && $tax_label_data['id_general']) {
             $original_id_singular = $tax_label_data['id_singular'];
             $original_id_plural = $tax_label_data['id_general'];
             icl_add_string_translation($original_id_singular, $language, $singular, ICL_TM_COMPLETE);
             $singular_result = (string) icl_get_string_by_id($original_id_singular, $language);
             icl_add_string_translation($original_id_plural, $language, $general, ICL_TM_COMPLETE);
             $plural_result = (string) icl_get_string_by_id($original_id_plural, $language);
             if ($singular_result && $plural_result) {
                 $result = array('singular' => $singular_result, 'general' => $plural_result, 'lang' => $language);
                 wp_send_json_success($result);
             }
         }
     }
     wp_send_json_error();
 }
/**
 * Potentially handles the request to add strings to the translation basket,
 * triggered by String Translation.
 */
function wpml_tm_add_strings_to_basket()
{
    if (isset($_POST['icl_st_action']) && $_POST['icl_st_action'] === 'send_strings' && wpml_is_action_authenticated('icl-string-translation')) {
        global $wpdb;
        $basket_instance = new WPML_Translation_Basket($wpdb);
        $st_request_handler = new WPML_TM_String_Basket_Request($basket_instance);
        $st_request_handler->send_to_basket($_POST);
    }
}
 public function wpml_need_sync_message()
 {
     if (!wpml_is_action_authenticated('wpml_need_sync_message')) {
         wp_send_json_error('Wrong Nonce');
     }
     $post_ids = filter_input(INPUT_POST, 'duplicated_post_ids');
     $post_ids = array_filter(explode(',', $post_ids));
     do_action('wpml_new_duplicated_terms', $post_ids);
 }
 public function ajax_sync_save()
 {
     if (!wpml_is_action_authenticated('wpml_tt_sync_hierarchy')) {
         wp_send_json_error('Wrong Nonce');
     }
     $sync_helper = wpml_get_hierarchy_sync_helper('term');
     list($taxonomy, $ref_lang) = $this->get_req_data();
     if ($taxonomy) {
         $sync_helper->sync_element_hierarchy($taxonomy, $ref_lang);
         wp_send_json_success(1);
     } else {
         wp_send_json_error('No taxonomy in request!');
     }
 }
 /**
  * Ajax handler for adding a term via Ajax.
  */
 public static function wpml_save_term_action()
 {
     if (!wpml_is_action_authenticated('wpml_save_term')) {
         wp_send_json_error('Wrong Nonce');
     }
     global $sitepress;
     $lang = filter_input(INPUT_POST, 'term_language_code', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
     $taxonomy = filter_input(INPUT_POST, 'taxonomy');
     $slug = filter_input(INPUT_POST, 'slug');
     $name = filter_input(INPUT_POST, 'name');
     $trid = filter_input(INPUT_POST, 'trid', FILTER_SANITIZE_NUMBER_INT);
     $description = filter_input(INPUT_POST, 'description');
     $new_term_object = self::save_term_ajax($sitepress, $lang, $taxonomy, $slug, $name, $trid, $description);
     $sitepress->get_wp_api()->wp_send_json_success($new_term_object);
 }
 public function delete_orphans_action()
 {
     if (wpml_is_action_authenticated('wpml_orphan_comment')) {
         $result = false;
         $data = $_POST['data'];
         $how_many = null;
         if (isset($data['how_many']) && is_numeric($data['how_many'])) {
             $how_many = (int) $data['how_many'];
         }
         if ($how_many) {
             $result = $this->delete_orphans($how_many);
         }
         wp_send_json_success($result);
     } else {
         wp_send_json_error('Wrong Nonce');
     }
 }
Example #8
0
/**
 * Ajax handler for canceling translation Jobs.
 */
function icl_cancel_translation_jobs()
{
    if (!wpml_is_action_authenticated('icl_cancel_translation_jobs')) {
        die('Wrong Nonce');
    }
    /** @var TranslationManagement $iclTranslationManagement */
    global $iclTranslationManagement;
    $job_ids = isset($_POST['job_ids']) ? $_POST['job_ids'] : false;
    if ($job_ids) {
        foreach ((array) $job_ids as $key => $job_id) {
            $iclTranslationManagement->cancel_translation_request($job_id);
        }
    }
    wp_send_json_success($job_ids);
}
 public function migrate_one_job()
 {
     if (wpml_is_action_authenticated('upgrade_icl_account')) {
         wp_send_json_success($this->wpml_icl_migration->migrate_one_icl_job());
     } else {
         wp_send_json_error('Wrong Nonce');
     }
 }