public function set_active_languages($arr) { global $wpdb; $tmp = $this->sanitize_language_input($arr); if ((bool) $tmp === false) { return false; } foreach ($tmp as $code) { $default_locale_prepared = $wpdb->prepare("SELECT default_locale FROM {$wpdb->prefix}icl_languages WHERE code= %s LIMIT 1", $code); $default_locale = $wpdb->get_var($default_locale_prepared); if ($default_locale) { $code_exists_prepared = $wpdb->prepare("SELECT code FROM {$wpdb->prefix}icl_locale_map WHERE code = %s LIMIT 1", $code); $code_exists = $wpdb->get_var($code_exists_prepared); if ($code_exists) { $wpdb->update($wpdb->prefix . 'icl_locale_map', array('locale' => $default_locale), array('code' => $code)); } else { $wpdb->insert($wpdb->prefix . 'icl_locale_map', array('code' => $code, 'locale' => $default_locale)); } } SitePress_Setup::insert_default_category($code); } $wpdb->query("UPDATE {$wpdb->prefix}icl_languages SET active = 1 WHERE code IN (" . wpml_prepare_in($tmp) . " ) "); $wpdb->query("UPDATE {$wpdb->prefix}icl_languages SET active = 0 WHERE code NOT IN (" . wpml_prepare_in($tmp) . " ) "); $this->updated_active_languages(); return true; }
function insert_one($data) { global $sitepress, $wpdb; $data = stripslashes_deep(stripslashes_deep($data)); // Insert main table. if (!$this->insert_main_table($data['code'], $data['english_name'], $data['default_locale'], 0, 1, $data['encode_url'], $data['tag'])) { $this->error(__('Adding language failed.', 'sitepress')); return false; } // add locale map $locale_exists = $wpdb->get_var($wpdb->prepare("SELECT code\n FROM {$wpdb->prefix}icl_locale_map\n WHERE code=%s", $data['code'])); if ($locale_exists) { $wpdb->update($wpdb->prefix . 'icl_locale_map', array('locale' => $data['default_locale']), array('code' => $data['code'])); } else { $wpdb->insert($wpdb->prefix . 'icl_locale_map', array('code' => $data['code'], 'locale' => $data['default_locale'])); } // Insert translations. $all_languages = $sitepress->get_languages(); foreach ($all_languages as $key => $lang) { // If submitted. if (array_key_exists($lang['code'], $data['translations'])) { if (empty($data['translations'][$lang['code']])) { $data['translations'][$lang['code']] = $data['english_name']; } if (!$this->insert_translation($data['translations'][$lang['code']], $data['code'], $lang['code'])) { $this->error(sprintf(__('Error adding translation %s for %s.', 'sitepress'), $data['code'], $lang['code'])); } } else { if (!$this->insert_translation($data['english_name'], $data['code'], $lang['code'])) { $this->error(sprintf(__('Error adding translation %s for %s.', 'sitepress'), $data['code'], $lang['code'])); } } } // Insert native name. if (!isset($data['translations']['add']) || empty($data['translations']['add'])) { $data['translations']['add'] = $data['english_name']; } if (!$this->insert_translation($data['translations']['add'], $data['code'], $data['code'])) { $this->error(__('Error adding native name.', 'sitepress')); } // Handle flag. if ($data['flag_upload'] == 'true' && !empty($_FILES['icl_edit_languages']['name']['add']['flag_file'])) { if ($filename = $this->upload_flag('add')) { $data['flag'] = $filename; $from_template = 1; } else { $data['flag'] = $data['code'] . '.png'; $from_template = 0; } } else { if (empty($data['flag'])) { $data['flag'] = $data['code'] . '.png'; } $from_template = 0; } // Insert flag table. if (!$this->insert_flag($data['code'], $data['flag'], $from_template)) { $this->error(__('Error adding flag.', 'sitepress')); } SitePress_Setup::insert_default_category($data['code']); }