Lingotek Translation - Version 1.2.5

Version Description

(2017-1-4) =

  • Added option to select the default behavior of new Custom Fields
  • Added option to enable deleting single translations
  • Fixed a bug that prevented the translation of taxonomy slugs and descriptions
Download this release

Release Info

Developer erichie
Plugin Icon 128x128 Lingotek Translation
Version 1.2.5
Comparing to
See all releases

Code changes from version 1.2.4 to 1.2.5

admin/filters-post.php CHANGED
@@ -10,6 +10,7 @@
10
  class Lingotek_Filters_Post extends PLL_Admin_Filters_Post {
11
  public $lgtm; // Lingotek model
12
  public $pllm;
 
13
 
14
  /*
15
  * Constructor
@@ -21,6 +22,7 @@ class Lingotek_Filters_Post extends PLL_Admin_Filters_Post {
21
 
22
  $this->lgtm = &$GLOBALS['wp_lingotek']->model;
23
  $this->pllm = &$GLOBALS['polylang']->model;
 
24
 
25
  // automatic upload
26
  add_action('post_updated', array(&$this, 'post_updated'), 10, 3);
@@ -226,16 +228,30 @@ class Lingotek_Filters_Post extends PLL_Admin_Filters_Post {
226
  */
227
  public function delete_post($post_id) {
228
  static $avoid_recursion = array();
 
229
 
230
  if (!wp_is_post_revision($post_id) && !in_array($post_id, $avoid_recursion)) {
231
  // sync delete is not needed when emptying the bin as trash is synced
232
- if (empty($_REQUEST['delete_all'])) {
233
  $tr_ids = $this->get_translations_to_sync($post_id);
234
  $avoid_recursion = array_merge($avoid_recursion, array_values($tr_ids));
235
  foreach ($tr_ids as $tr_id) {
236
  wp_delete_post($tr_id, true); // forces deletion for the translations which are not already in the list
237
  }
238
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  $this->lgtm->delete_post($post_id);
240
  }
241
  // delete lingotek_profile term upon post deletion
@@ -260,8 +276,13 @@ class Lingotek_Filters_Post extends PLL_Admin_Filters_Post {
260
  * @param int $post_id
261
  */
262
  public function trash_post($post_id) {
263
- foreach ($this->get_translations_to_sync($post_id) as $tr_id)
264
- wp_trash_post($tr_id);
 
 
 
 
 
265
  }
266
 
267
  /*
10
  class Lingotek_Filters_Post extends PLL_Admin_Filters_Post {
11
  public $lgtm; // Lingotek model
12
  public $pllm;
13
+ public $lingotek_prefs;
14
 
15
  /*
16
  * Constructor
22
 
23
  $this->lgtm = &$GLOBALS['wp_lingotek']->model;
24
  $this->pllm = &$GLOBALS['polylang']->model;
25
+ $this->lingotek_prefs = Lingotek_Model::get_prefs();
26
 
27
  // automatic upload
28
  add_action('post_updated', array(&$this, 'post_updated'), 10, 3);
228
  */
229
  public function delete_post($post_id) {
230
  static $avoid_recursion = array();
231
+ $group = $this->lgtm->get_group('post', $post_id);
232
 
233
  if (!wp_is_post_revision($post_id) && !in_array($post_id, $avoid_recursion)) {
234
  // sync delete is not needed when emptying the bin as trash is synced
235
+ if (empty($_REQUEST['delete_all']) && isset($this->lingotek_prefs['delete_linked_content']['enabled'])) {
236
  $tr_ids = $this->get_translations_to_sync($post_id);
237
  $avoid_recursion = array_merge($avoid_recursion, array_values($tr_ids));
238
  foreach ($tr_ids as $tr_id) {
239
  wp_delete_post($tr_id, true); // forces deletion for the translations which are not already in the list
240
  }
241
  }
242
+ if ($group !== 0 && $group->source == $post_id) {
243
+ $group->disassociate();
244
+ }
245
+ else if ($group->source !== null) {
246
+ $post_lang = pll_get_post_language($post_id, 'locale');
247
+ if ($this->lingotek_prefs['delete_document_from_tms']) {
248
+ unset($group->desc_array['lingotek']['translations'][$post_lang]);
249
+ }
250
+ else {
251
+ $group->desc_array['lingotek']['translations'][$post_lang] = 'ready';
252
+ }
253
+ $group->save();
254
+ }
255
  $this->lgtm->delete_post($post_id);
256
  }
257
  // delete lingotek_profile term upon post deletion
276
  * @param int $post_id
277
  */
278
  public function trash_post($post_id) {
279
+ if (isset($this->lingotek_prefs['delete_linked_content']['enabled'])) {
280
+ foreach ($this->get_translations_to_sync($post_id) as $tr_id)
281
+ wp_trash_post($tr_id);
282
+ }
283
+ else {
284
+ wp_trash_post($post_id);
285
+ }
286
  }
287
 
288
  /*
admin/manage/view-content.php CHANGED
@@ -53,8 +53,12 @@ else {
53
  foreach ($data[$key]['fields']['label'] as $key1 => $arr) {
54
  if (is_array($arr)) {
55
  foreach (array_keys($arr) as $key2) {
56
- if(empty($_POST[$key]['fields'][$key1][$key2]))
57
- $content_types[$key]['fields'][$key1][$key2] = 1;
 
 
 
 
58
  }
59
  }
60
  elseif (isset($_POST[$key]) && empty($_POST[$key]['fields'][$key1])) {
53
  foreach ($data[$key]['fields']['label'] as $key1 => $arr) {
54
  if (is_array($arr)) {
55
  foreach (array_keys($arr) as $key2) {
56
+ if(!isset($_POST[$key]['fields'][$key1][$key2])) {
57
+ $content_types[$key]['fields'][$key1][$key2] = 1;
58
+ }
59
+ else {
60
+ $content_types[$key]['fields'][$key1][$key2] = 0;
61
+ }
62
  }
63
  }
64
  elseif (isset($_POST[$key]) && empty($_POST[$key]['fields'][$key1])) {
admin/manage/view-custom-fields.php CHANGED
@@ -3,12 +3,18 @@
3
  global $polylang;
4
 
5
  $items = array();
 
 
6
 
7
  if (!empty($_POST)) {
8
  check_admin_referer('lingotek-custom-fields', '_wpnonce_lingotek-custom-fields');
9
 
10
  if (!empty($_POST['submit'])) {
11
  $arr = empty($_POST['settings']) ? array() : $_POST['settings'];
 
 
 
 
12
  update_option('lingotek_custom_fields', $arr);
13
  add_settings_error('lingotek_custom_fields_save', 'custom_fields', __('Your <i>Custom Fields</i> were sucessfully saved.', 'lingotek-translation'), 'updated');
14
  }
@@ -21,6 +27,7 @@ if (!empty($_POST)) {
21
  }
22
 
23
  $items = Lingotek_Group_Post::get_cached_meta_values();
 
24
 
25
  ?>
26
 
@@ -28,8 +35,18 @@ $items = Lingotek_Group_Post::get_cached_meta_values();
28
  <p class="description"><?php _e('Custom Fields can be translated, copied, or ignored. Click "Refresh Custom Fields" to identify and enable your custom fields.', 'lingotek-translation'); ?></p>
29
 
30
  <form id="lingotek-custom-fields" method="post" action="admin.php?page=lingotek-translation_manage&amp;sm=custom-fields" class="validate"><?php
31
- wp_nonce_field('lingotek-custom-fields', '_wpnonce_lingotek-custom-fields');
32
 
 
 
 
 
 
 
 
 
 
 
33
  $table = new Lingotek_Custom_Fields_Table();
34
  $table->prepare_items($items);
35
  $table->display();
@@ -39,4 +56,4 @@ $table->display();
39
  <?php submit_button(__('Save Changes', 'lingotek-translation'), 'primary', 'submit', false); ?>
40
  <?php submit_button(__( 'Refresh Custom Fields', 'lingotek-translation'), 'secondary', 'refresh', false ); ?>
41
  </p>
42
- </form>
3
  global $polylang;
4
 
5
  $items = array();
6
+ $default_setting = array('ignore' => 'Ignore', 'translate' => 'Translate', 'copy' => 'Copy');
7
+ $default_custom_fields = '';
8
 
9
  if (!empty($_POST)) {
10
  check_admin_referer('lingotek-custom-fields', '_wpnonce_lingotek-custom-fields');
11
 
12
  if (!empty($_POST['submit'])) {
13
  $arr = empty($_POST['settings']) ? array() : $_POST['settings'];
14
+ if (isset($_POST['default_custom_fields'])) {
15
+ $default_custom_fields = $_POST['default_custom_fields'];
16
+ update_option('lingotek_default_custom_fields', $default_custom_fields);
17
+ }
18
  update_option('lingotek_custom_fields', $arr);
19
  add_settings_error('lingotek_custom_fields_save', 'custom_fields', __('Your <i>Custom Fields</i> were sucessfully saved.', 'lingotek-translation'), 'updated');
20
  }
27
  }
28
 
29
  $items = Lingotek_Group_Post::get_cached_meta_values();
30
+ $default_custom_fields = get_option('lingotek_default_custom_fields');
31
 
32
  ?>
33
 
35
  <p class="description"><?php _e('Custom Fields can be translated, copied, or ignored. Click "Refresh Custom Fields" to identify and enable your custom fields.', 'lingotek-translation'); ?></p>
36
 
37
  <form id="lingotek-custom-fields" method="post" action="admin.php?page=lingotek-translation_manage&amp;sm=custom-fields" class="validate"><?php
38
+ wp_nonce_field('lingotek-custom-fields', '_wpnonce_lingotek-custom-fields'); ?>
39
 
40
+ <br>
41
+ <label for="default_custom_fields">Default configuration for new Custom Fields</label>
42
+ <select name="default_custom_fields"><?php
43
+ foreach ($default_setting as $key => $title) {
44
+ $selected = $key == $default_custom_fields ? 'selected="selected"' : '';
45
+ echo "\n\t<option value='" . $key . "' $selected>" . $title . '</option>';
46
+ } ?>
47
+ </select>
48
+
49
+ <?php
50
  $table = new Lingotek_Custom_Fields_Table();
51
  $table->prepare_items($items);
52
  $table->display();
56
  <?php submit_button(__('Save Changes', 'lingotek-translation'), 'primary', 'submit', false); ?>
57
  <?php submit_button(__( 'Refresh Custom Fields', 'lingotek-translation'), 'secondary', 'refresh', false ); ?>
58
  </p>
59
+ </form>
admin/settings/view-preferences.php CHANGED
@@ -33,6 +33,13 @@ $setting_details = array(
33
  'delete' => __('Delete documents from Lingotek TMS when disassociating.', 'lingotek-translation'),
34
  )
35
  ),
 
 
 
 
 
 
 
36
  'import_enabled' => array(
37
  'type' => 'checkboxes',
38
  'label' => __('Import', 'wp-lingotek'),
33
  'delete' => __('Delete documents from Lingotek TMS when disassociating.', 'lingotek-translation'),
34
  )
35
  ),
36
+ 'delete_linked_content' => array(
37
+ 'type' => 'checkboxes',
38
+ 'label' => __('Deleting Content', 'wp-lingotek'),
39
+ 'description' => __('When enabled, deleting source or target content will also delete all linked content.', 'wp-lingotek'),
40
+ 'values' => array(
41
+ 'enabled' => __('Delete linked content', 'wp-lingotek')
42
+ )),
43
  'import_enabled' => array(
44
  'type' => 'checkboxes',
45
  'label' => __('Import', 'wp-lingotek'),
include/api.php CHANGED
@@ -446,12 +446,12 @@ class Lingotek_API extends Lingotek_HTTP {
446
  }
447
 
448
  public function get_communities() {
449
- $response = $this->get(add_query_arg(array('limit' => 100), $this->api_url . '/community'));
450
  return !is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response) ? json_decode(wp_remote_retrieve_body($response)) : false;
451
  }
452
 
453
  public function get_projects($community_id) {
454
- $response = $this->get(add_query_arg(array('community_id' => $community_id, 'limit' => 100), $this->api_url . '/project'));
455
  if (wp_remote_retrieve_response_code($response) == 204) {
456
  return array();// there are currently no projects
457
  }
@@ -459,17 +459,17 @@ class Lingotek_API extends Lingotek_HTTP {
459
  }
460
 
461
  public function get_vaults($community_id) {
462
- $response = $this->get(add_query_arg(array('community_id' => $community_id, 'limit' => 100), $this->api_url . '/vault'));
463
  return !is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response) ? json_decode(wp_remote_retrieve_body($response)) : false;
464
  }
465
 
466
  public function get_workflows($community_id) {
467
- $response = $this->get(add_query_arg(array('community_id' => $community_id, 'limit' => 100), $this->api_url . '/workflow'));
468
  return !is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response) ? json_decode(wp_remote_retrieve_body($response)) : false;
469
  }
470
 
471
  public function get_filters() {
472
- $response = $this->get(add_query_arg(array('limit' => 100), $this->api_url . '/filter'));
473
  return !is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response) ? json_decode(wp_remote_retrieve_body($response)) : false;
474
  }
475
 
446
  }
447
 
448
  public function get_communities() {
449
+ $response = $this->get(add_query_arg(array('limit' => 1000), $this->api_url . '/community'));
450
  return !is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response) ? json_decode(wp_remote_retrieve_body($response)) : false;
451
  }
452
 
453
  public function get_projects($community_id) {
454
+ $response = $this->get(add_query_arg(array('community_id' => $community_id, 'limit' => 1000), $this->api_url . '/project'));
455
  if (wp_remote_retrieve_response_code($response) == 204) {
456
  return array();// there are currently no projects
457
  }
459
  }
460
 
461
  public function get_vaults($community_id) {
462
+ $response = $this->get(add_query_arg(array('community_id' => $community_id, 'limit' => 1000), $this->api_url . '/vault'));
463
  return !is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response) ? json_decode(wp_remote_retrieve_body($response)) : false;
464
  }
465
 
466
  public function get_workflows($community_id) {
467
+ $response = $this->get(add_query_arg(array('community_id' => $community_id, 'limit' => 1000), $this->api_url . '/workflow'));
468
  return !is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response) ? json_decode(wp_remote_retrieve_body($response)) : false;
469
  }
470
 
471
  public function get_filters() {
472
+ $response = $this->get(add_query_arg(array('limit' => 1000), $this->api_url . '/filter'));
473
  return !is_wp_error($response) && 200 == wp_remote_retrieve_response_code($response) ? json_decode(wp_remote_retrieve_body($response)) : false;
474
  }
475
 
include/group-post.php CHANGED
@@ -163,6 +163,7 @@ class Lingotek_Group_Post extends Lingotek_Group {
163
  $custom_fields_from_wpml = self::get_custom_fields_from_wpml();
164
  $custom_fields_from_postmeta = self::get_custom_fields_from_wp_postmeta($post_ID);
165
  $custom_fields_from_lingotek = get_option('lingotek_custom_fields', array());
 
166
  $custom_fields = array();
167
  $items = array();
168
 
@@ -181,7 +182,7 @@ class Lingotek_Group_Post extends Lingotek_Group {
181
  }
182
  // no lingotek setting, no wpml setting, so save default setting of ignore
183
  else {
184
- $custom_fields[$cf['meta_key']] = 'ignore';
185
  }
186
  }
187
  // lingotek already has this field setting saved
163
  $custom_fields_from_wpml = self::get_custom_fields_from_wpml();
164
  $custom_fields_from_postmeta = self::get_custom_fields_from_wp_postmeta($post_ID);
165
  $custom_fields_from_lingotek = get_option('lingotek_custom_fields', array());
166
+ $default_custom_fields = get_option('lingotek_default_custom_fields') ? get_option('lingotek_default_custom_fields') : 'ignore';
167
  $custom_fields = array();
168
  $items = array();
169
 
182
  }
183
  // no lingotek setting, no wpml setting, so save default setting of ignore
184
  else {
185
+ $custom_fields[$cf['meta_key']] = $default_custom_fields;
186
  }
187
  }
188
  // lingotek already has this field setting saved
include/model.php CHANGED
@@ -153,6 +153,9 @@ class Lingotek_Model {
153
  'delete_document_from_tms' => array(
154
  'delete' => 1,
155
  ),
 
 
 
156
  );
157
  $prefs = array_merge($default, get_option('lingotek_prefs', $default)); // ensure defaults are set for missing keys
158
  return $prefs;
@@ -504,6 +507,7 @@ class Lingotek_Model {
504
  public function delete_post($object_id) {
505
  if ($document = $this->get_group('post', $object_id)) {
506
  $client = new Lingotek_API();
 
507
 
508
  if ($document->source == $object_id) {
509
  $client->delete_document($document->document_id, $object_id);
@@ -511,7 +515,9 @@ class Lingotek_Model {
511
  else {
512
  PLL()->model->post->delete_translation($object_id);
513
  $lang = PLL()->model->post->get_language($object_id);
514
- $client->delete_translation($document->document_id, $lang->lingotek_locale, $object_id);
 
 
515
  }
516
  }
517
  }
153
  'delete_document_from_tms' => array(
154
  'delete' => 1,
155
  ),
156
+ 'delete_linked_content' => array(
157
+ 'enabled' => 1,
158
+ ),
159
  );
160
  $prefs = array_merge($default, get_option('lingotek_prefs', $default)); // ensure defaults are set for missing keys
161
  return $prefs;
507
  public function delete_post($object_id) {
508
  if ($document = $this->get_group('post', $object_id)) {
509
  $client = new Lingotek_API();
510
+ $lingotek_prefs = Lingotek_Model::get_prefs();
511
 
512
  if ($document->source == $object_id) {
513
  $client->delete_document($document->document_id, $object_id);
515
  else {
516
  PLL()->model->post->delete_translation($object_id);
517
  $lang = PLL()->model->post->get_language($object_id);
518
+ if ($lingotek_prefs['delete_document_from_tms']) {
519
+ $client->delete_translation($document->document_id, $lang->lingotek_locale, $object_id);
520
+ }
521
  }
522
  }
523
  }
lingotek.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin name: Lingotek Translation
4
  Plugin URI: http://lingotek.com/wordpress#utm_source=wpadmin&utm_medium=plugin&utm_campaign=wplingotektranslationplugin
5
- Version: 1.2.4
6
  Author: Lingotek and Frédéric Demarle
7
  Author uri: http://lingotek.com
8
  Description: Lingotek offers convenient cloud-based localization and translation.
@@ -15,7 +15,7 @@ GitHub Plugin URI: https://github.com/lingotek/lingotek-translation
15
  if (!function_exists('add_action'))
16
  exit();
17
 
18
- define('LINGOTEK_VERSION', '1.2.4'); // plugin version (should match above meta)
19
  define('LINGOTEK_MIN_PLL_VERSION', '1.8');
20
  define('LINGOTEK_BASENAME', plugin_basename(__FILE__)); // plugin name as known by WP
21
  define('LINGOTEK_PLUGIN_SLUG', 'lingotek-translation');// plugin slug (should match above meta: Text Domain)
2
  /*
3
  Plugin name: Lingotek Translation
4
  Plugin URI: http://lingotek.com/wordpress#utm_source=wpadmin&utm_medium=plugin&utm_campaign=wplingotektranslationplugin
5
+ Version: 1.2.5
6
  Author: Lingotek and Frédéric Demarle
7
  Author uri: http://lingotek.com
8
  Description: Lingotek offers convenient cloud-based localization and translation.
15
  if (!function_exists('add_action'))
16
  exit();
17
 
18
+ define('LINGOTEK_VERSION', '1.2.5'); // plugin version (should match above meta)
19
  define('LINGOTEK_MIN_PLL_VERSION', '1.8');
20
  define('LINGOTEK_BASENAME', plugin_basename(__FILE__)); // plugin name as known by WP
21
  define('LINGOTEK_PLUGIN_SLUG', 'lingotek-translation');// plugin slug (should match above meta: Text Domain)
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: chouby, smithworx, erichie
3
  Donate link: http://lingotek.com/
4
  Tags: automation, bilingual, international, language, Lingotek, localization, multilanguage, multilingual, translate, translation
5
  Requires at least: 3.8
6
- Tested up to: 4.6
7
- Stable tag: 1.2.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -122,6 +122,12 @@ For more, visit the [Lingotek documentation site](https://lingotek.atlassian.net
122
 
123
  == Changelog ==
124
 
 
 
 
 
 
 
125
  = 1.2.4 (2016-10-10) =
126
 
127
  * Fixed a bug that prevented the saving of Translation Profiles when the content type list was paginated
3
  Donate link: http://lingotek.com/
4
  Tags: automation, bilingual, international, language, Lingotek, localization, multilanguage, multilingual, translate, translation
5
  Requires at least: 3.8
6
+ Tested up to: 4.7
7
+ Stable tag: 1.2.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
122
 
123
  == Changelog ==
124
 
125
+ = 1.2.5 (2017-1-4) =
126
+
127
+ * Added option to select the default behavior of new Custom Fields
128
+ * Added option to enable deleting single translations
129
+ * Fixed a bug that prevented the translation of taxonomy slugs and descriptions
130
+
131
  = 1.2.4 (2016-10-10) =
132
 
133
  * Fixed a bug that prevented the saving of Translation Profiles when the content type list was paginated