Lingotek Translation - Version 1.4.11

Version Description

(2021-5-4) = * Fixed bug that re-uploaded documents instead of patching them * Removed unsupported content type custom field settings * Changed method to track content changes for patching documents * Removed flag that prevented uploading certain untracked documents

Download this release

Release Info

Developer lopez93
Plugin Icon 128x128 Lingotek Translation
Version 1.4.11
Comparing to
See all releases

Code changes from version 1.4.10 to 1.4.11

admin/manage/view-custom-fields.php CHANGED
@@ -11,12 +11,17 @@ if (!empty($_POST)) {
11
 
12
  if (!empty($_POST['submit'])) {
13
  $arr = empty($_POST['settings']) ? array() : $_POST['settings'];
14
-
15
  if (isset($_POST['default_custom_fields'])) {
16
  $default_custom_fields = $_POST['default_custom_fields'];
17
  update_option('lingotek_default_custom_fields', $default_custom_fields);
18
  }
19
  update_option('lingotek_custom_fields', $arr);
 
 
 
 
 
20
  add_settings_error('lingotek_custom_fields_save', 'custom_fields', __('Your <i>Custom Fields</i> were sucessfully saved.', 'lingotek-translation'), 'updated');
21
  }
22
 
11
 
12
  if (!empty($_POST['submit'])) {
13
  $arr = empty($_POST['settings']) ? array() : $_POST['settings'];
14
+
15
  if (isset($_POST['default_custom_fields'])) {
16
  $default_custom_fields = $_POST['default_custom_fields'];
17
  update_option('lingotek_default_custom_fields', $default_custom_fields);
18
  }
19
  update_option('lingotek_custom_fields', $arr);
20
+ $post_types = get_post_types();
21
+ foreach ($post_types as $post_type) {
22
+ $cache_key = 'content_type_fields_' . $post_type;
23
+ wp_cache_delete($cache_key, 'lingotek');
24
+ }
25
  add_settings_error('lingotek_custom_fields_save', 'custom_fields', __('Your <i>Custom Fields</i> were sucessfully saved.', 'lingotek-translation'), 'updated');
26
  }
27
 
include/group-post.php CHANGED
@@ -40,48 +40,52 @@ class Lingotek_Group_Post extends Lingotek_Group {
40
  * @param string $post_type
41
  * @return array
42
  */
43
- static public function get_content_type_fields($post_type, $post_ID = NULL)
44
- {
45
- $arr = 'attachment' == $post_type ?
46
- array(
47
- 'post_title' => __('Title', 'lingotek-translation'),
48
- 'post_excerpt' => __('Caption', 'lingotek-translation'),
49
- 'metas' => array('_wp_attachment_image_alt' => __('Alternative Text', 'lingotek-translation')),
50
- 'post_content' => __('Description', 'lingotek-translation'),
51
- ) : array(
52
- 'post_title' => __('Title', 'lingotek-translation'),
53
- 'post_name' => __('Slug', 'lingotek-translation'),
54
- 'post_content' => __('Content', 'lingotek-translation'),
55
- 'post_excerpt' => __('Excerpt', 'lingotek-translation')
56
- );
57
-
58
- // if the user hasn't visited the custom fields tab, and hasn't saved actions for custom
59
- // fields, and uploaded a post, check the wpml file for settings
60
- if ($post_ID) {
61
- self::get_updated_meta_values($post_ID);
62
- }
63
- // add the custom fields from the lingotek_custom_fields option
64
- $custom_fields = get_option('lingotek_custom_fields', array());
65
-
66
- if (!empty($custom_fields)) {
67
- foreach ($custom_fields as $cf => $setting) {
68
- if ('translate' == $setting)
69
- $arr['metas'][$cf] = $cf;
70
- }
71
- }
72
-
73
- // allow plugins to modify the fields to translate
74
- return apply_filters('lingotek_post_content_type_fields', $arr, $post_type);
75
- }
76
-
77
- /*
78
- * returns custom fields from the wpml-config.xml file
79
- *
80
- * @since 0.2
81
- *
82
- * @param string $post_type
83
- * @return array
84
- */
 
 
 
 
85
  static public function get_custom_fields_from_wpml() {
86
  $wpml_config = PLL_WPML_Config::instance();
87
  $arr = array();
40
  * @param string $post_type
41
  * @return array
42
  */
43
+ static public function get_content_type_fields($post_type, $post_ID = NULL) {
44
+ $cache_key = 'content_type_fields_' . $post_type;
45
+ $arr = wp_cache_get($cache_key, 'lingotek');
46
+ if (!$arr) {
47
+ $arr = 'attachment' == $post_type ?
48
+ array(
49
+ 'post_title' => __('Title', 'lingotek-translation'),
50
+ 'post_excerpt' => __('Caption', 'lingotek-translation'),
51
+ 'metas' => ['_wp_attachment_image_alt' => __('Alternative Text', 'lingotek-translation')],
52
+ 'post_content' => __('Description', 'lingotek-translation'),
53
+ ) : array(
54
+ 'post_title' => __('Title', 'lingotek-translation'),
55
+ 'post_name' => __('Slug', 'lingotek-translation'),
56
+ 'post_content' => __('Content', 'lingotek-translation'),
57
+ 'post_excerpt' => __('Excerpt', 'lingotek-translation')
58
+ );
59
+
60
+ // if the user hasn't visited the custom fields tab, and hasn't saved actions for custom
61
+ // fields, and uploaded a post, check the wpml file for settings
62
+ if ($post_ID) {
63
+ self::get_updated_meta_values($post_ID);
64
+ }
65
+ // add the custom fields from the lingotek_custom_fields option
66
+ $custom_fields = get_option('lingotek_custom_fields', array());
67
+
68
+ if (!empty($custom_fields)) {
69
+ foreach ($custom_fields as $cf => $setting) {
70
+ if ('translate' == $setting) {
71
+ $arr['metas'][$cf] = $cf;
72
+ }
73
+ }
74
+ }
75
+ wp_cache_set($cache_key, $arr, 'lingotek', 300);
76
+ }
77
+ // allow plugins to modify the fields to translate
78
+ return apply_filters('lingotek_post_content_type_fields', $arr, $post_type);
79
+ }
80
+
81
+ /*
82
+ * returns custom fields from the wpml-config.xml file
83
+ *
84
+ * @since 0.2
85
+ *
86
+ * @param string $post_type
87
+ * @return array
88
+ */
89
  static public function get_custom_fields_from_wpml() {
90
  $wpml_config = PLL_WPML_Config::instance();
91
  $arr = array();
include/model.php CHANGED
@@ -89,6 +89,21 @@ class Lingotek_Model {
89
  }
90
  }
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  /*
93
  * get the translation term of an object by its Lingotek document id
94
  *
@@ -308,28 +323,42 @@ class Lingotek_Model {
308
  $post = get_post($post_id);
309
  $language = PLL()->model->post->get_language($post_id);
310
  $profile = self::get_profile($post->post_type, $language, $post_id);
311
- if ('disabled' == $profile['profile'] || empty($post) || empty($language) || get_option( $post_id, false )) {
312
  return;
313
  }
314
-
315
- /**
316
- * Customized workflows have the option to do any sort of pre-processing before a document is uploaded to lingotek.
317
- */
 
 
 
 
 
 
 
 
 
 
318
  $document = $this->get_group('post', $post_id);
 
 
319
  if ($document) {
320
  $document->pre_upload_to_lingotek($post_id, $post->post_type, $language, 'post');
321
  }
322
 
323
  $client = new Lingotek_API();
324
  $external_url = get_page_link($post_id);
325
- $content = Lingotek_Group_Post::get_content($post);
 
 
326
  $params = $this->build_params($external_url, $post->post_title, $post->post_type, $content, $language, $profile, $post_id, $wp_target_locales);
327
  $filter_ids = $this->get_filter_ids($post->post_type, $language, $post_id);
328
  $params = array_merge($params, $filter_ids);
329
- if ($document && 'edited' == $document->status) {
330
  $document->patch($this->format_patch_params($params, $profile, $language));
 
331
  } elseif (!Lingotek_Group::$creating_translation && !self::$copying_post && (!$document || $document->document_id )) {
332
- update_option($post_id, true);
333
  $document_id = $client->upload_document($params, $post->ID);
334
 
335
  if ($document_id) {
@@ -896,4 +925,4 @@ class Lingotek_Model {
896
  }
897
  return $filter_ids;
898
  }
899
- }
89
  }
90
  }
91
 
92
+ /*
93
+ * get document id of an object, false if it wasn't uploaded yet.
94
+ *
95
+ * @since 1.4.11
96
+ *
97
+ * @param string $type either 'post' or 'term' or 'string'
98
+ * @param int|string $id post id or term id or strings translations group name
99
+ * @return string|bool document id or false
100
+ */
101
+ public function get_document_id($type, $id) {
102
+ $document_term = $this->get_group($type, $id );
103
+ $document_id = $document_term != false ? $document_term->document_id : false;
104
+ return $document_id;
105
+ }
106
+
107
  /*
108
  * get the translation term of an object by its Lingotek document id
109
  *
323
  $post = get_post($post_id);
324
  $language = PLL()->model->post->get_language($post_id);
325
  $profile = self::get_profile($post->post_type, $language, $post_id);
326
+ if ('disabled' == $profile['profile'] || empty($post) || empty($language)) {
327
  return;
328
  }
329
+ $document_id = self::get_document_id('post', $post_id);
330
+ $content = null;
331
+ // If we already uploaded this doc, check if it changed and prevent the upload if it didn't.
332
+ if ($document_id) {
333
+ $content = Lingotek_Group_Post::get_content($post);
334
+ $hash_terms = wp_get_object_terms($post->ID, 'lingotek_hash');
335
+ $hash_term = array_pop($hash_terms);
336
+ if (!empty($hash_term)) {
337
+ $new_hash = md5( $content );
338
+ if ( $hash_term->description == $new_hash ) {
339
+ return;
340
+ }
341
+ }
342
+ }
343
  $document = $this->get_group('post', $post_id);
344
+ // Customized workflows have the option to do any sort of pre-processing before a document
345
+ // is uploaded to lingotek.
346
  if ($document) {
347
  $document->pre_upload_to_lingotek($post_id, $post->post_type, $language, 'post');
348
  }
349
 
350
  $client = new Lingotek_API();
351
  $external_url = get_page_link($post_id);
352
+ if (!$content) {
353
+ $content = Lingotek_Group_Post::get_content($post);
354
+ }
355
  $params = $this->build_params($external_url, $post->post_title, $post->post_type, $content, $language, $profile, $post_id, $wp_target_locales);
356
  $filter_ids = $this->get_filter_ids($post->post_type, $language, $post_id);
357
  $params = array_merge($params, $filter_ids);
358
+ if ($document && in_array($document->status, array('edited', 'importing', 'current')) && $document_id) {
359
  $document->patch($this->format_patch_params($params, $profile, $language));
360
+ wp_update_term($hash_term->term_id, 'lingotek_hash', array('description' => $new_hash));
361
  } elseif (!Lingotek_Group::$creating_translation && !self::$copying_post && (!$document || $document->document_id )) {
 
362
  $document_id = $client->upload_document($params, $post->ID);
363
 
364
  if ($document_id) {
925
  }
926
  return $filter_ids;
927
  }
928
+ }
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.4.10
6
  Author: Lingotek and Frédéric Demarle
7
  Author uri: http://lingotek.com
8
  Description: Lingotek offers convenient cloud-based localization and translation.
@@ -16,7 +16,7 @@ if ( ! function_exists( 'add_action' ) ) {
16
  exit();
17
  }
18
 
19
- define( 'LINGOTEK_VERSION', '1.4.10' ); // plugin version (should match above meta).
20
  define( 'LINGOTEK_MIN_PLL_VERSION', '1.8' );
21
  define( 'LINGOTEK_BASENAME', plugin_basename( __FILE__ ) ); // plugin name as known by WP.
22
  define( 'LINGOTEK_PLUGIN_SLUG', 'lingotek-translation' );// plugin slug (should match above meta: Text Domain).
@@ -309,26 +309,81 @@ class Lingotek {
309
  }
310
 
311
  public function lingotek_plugin_migration() {
312
- $version = get_option('lingotek_plugin_version');
313
- if ($version != LINGOTEK_VERSION) {
314
- $this->do_plugin_updates();
315
- }
316
- update_option('lingotek_plugin_version', LINGOTEK_VERSION);
317
- }
318
-
319
- public function do_plugin_updates() {
320
- $cr = get_option('lingotek_community_resources');
321
- if (is_array($cr) && isset($cr['workflows'])) {
322
- // put Lingotek Professional Translation at the top of the select box.
323
- $cr['workflows'] = array_flip($cr['workflows']);
324
- unset($cr['workflows']['Lingotek Professional Translation']);
325
- $cr['workflows'] = array_flip($cr['workflows']);
326
- $cr['workflows'] = array_merge(array('ltk-professional-translation' => 'Lingotek Professional Translation'), $cr['workflows']);
327
- update_option('lingotek_community_resources', $cr);
328
- }
329
- }
330
 
331
- /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
  * Return the plugin slug.
333
  *
334
  * @since 0.1
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.4.11
6
  Author: Lingotek and Frédéric Demarle
7
  Author uri: http://lingotek.com
8
  Description: Lingotek offers convenient cloud-based localization and translation.
16
  exit();
17
  }
18
 
19
+ define( 'LINGOTEK_VERSION', '1.4.11' ); // plugin version (should match above meta).
20
  define( 'LINGOTEK_MIN_PLL_VERSION', '1.8' );
21
  define( 'LINGOTEK_BASENAME', plugin_basename( __FILE__ ) ); // plugin name as known by WP.
22
  define( 'LINGOTEK_PLUGIN_SLUG', 'lingotek-translation' );// plugin slug (should match above meta: Text Domain).
309
  }
310
 
311
  public function lingotek_plugin_migration() {
312
+ $updatesHaveRun = false;
313
+ if ($this->needs_to_run_updates('1.4.11')) {
314
+ // Add the updates introduced in 1.4.11.
315
+ $this->update_1_4_11_for_removing_custom_fields_from_postTypes_settings();
316
+ $this->update_1_4_11_for_removing_custom_fields_autoload();
317
+ $this->update_1_4_11_for_removing_community_resources_autoload();
318
+ $updatesHaveRun = true;
319
+ }
320
+ // If any update happened, inform the user and update the version.
321
+ if ($updatesHaveRun) {
322
+ update_option('lingotek_plugin_version', LINGOTEK_VERSION);
323
+ add_action('admin_notices', function() {
324
+ echo '<div class="notice notice-success is-dismissible">
325
+ <p>' . __('Upgrades for the lingotek translation module have completed.', 'lingotek-translation') . '</p>
326
+ </div>';
327
+ });
328
+ }
329
+ }
330
 
331
+ /**
332
+ * Check if we need to run these updates.
333
+ *
334
+ * It will check that the installed version is newer than the db one, even if we
335
+ * had skipped any version, and ensures we don't run any update if we already did.
336
+ *
337
+ * @param $versionUpdates
338
+ * The version where these updates were introduced.
339
+ * @return bool
340
+ * true if needs to run, false otherwise
341
+ *
342
+ * @since 1.4.11
343
+ */
344
+ public function needs_to_run_updates($versionUpdates) {
345
+ $db_version = get_option('lingotek_plugin_version');
346
+ return (version_compare(LINGOTEK_VERSION, $versionUpdates, '>=') &&
347
+ version_compare($versionUpdates, $db_version, '>'));
348
+ }
349
+
350
+ /**
351
+ * As we already have the metas in the lingotek_custom_fields options, we can
352
+ * remove them from the lingotek_content_type option.
353
+ *
354
+ * @since 1.4.11
355
+ */
356
+ public function update_1_4_11_for_removing_custom_fields_from_postTypes_settings() {
357
+ $settings = get_option('lingotek_content_type');
358
+ foreach ($settings as $postType => &$postTypeSettings) {
359
+ unset($postTypeSettings['fields']['metas']);
360
+ }
361
+ update_option('lingotek_content_type', $settings, false);
362
+ }
363
+
364
+ /**
365
+ * Set the lingotek_custom_fields option as not autoloaded.
366
+ *
367
+ * @since 1.4.11
368
+ */
369
+ public function update_1_4_11_for_removing_custom_fields_autoload() {
370
+ $settings = get_option('lingotek_custom_fields');
371
+ update_option('lingotek_custom_fields', 'fakeValueSoWeForceAutoloadToFalse', false);
372
+ update_option('lingotek_custom_fields', $settings, false);
373
+ }
374
+
375
+ /**
376
+ * Set the lingotek_community_resources option as not autoloaded.
377
+ *
378
+ * @since 1.4.11
379
+ */
380
+ public function update_1_4_11_for_removing_community_resources_autoload() {
381
+ $settings = get_option('lingotek_community_resources');
382
+ update_option('lingotek_community_resources', 'fakeValueSoWeForceAutoloadToFalse', false);
383
+ update_option('lingotek_community_resources', $settings, false);
384
+ }
385
+
386
+ /**
387
  * Return the plugin slug.
388
  *
389
  * @since 0.1
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Lingotek Translation ===
2
- Contributors: chouby, smithworx, erichie, robertdhanna, ipoulsen, elliothanna, lopez93
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: 5.6
7
- Stable tag: 1.4.10
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
  5. The Lingotek Translation plugin provides the ability to Copy, Translate, and Ignore each specific custom field. Our plugin supports Wordpress custom fields and advanced custom fields.
123
 
124
  == Changelog ==
 
 
 
 
 
 
125
  = 1.4.10 (2021-4-15) =
126
  * Fixed bug that slowed down the download and upload process
127
 
1
  === Lingotek Translation ===
2
+ Contributors: chouby, smithworx, erichie, robertdhanna, ipoulsen, elliothanna, lopez93, mbrown97, penyaskito
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: 5.6
7
+ Stable tag: 1.4.11
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
122
  5. The Lingotek Translation plugin provides the ability to Copy, Translate, and Ignore each specific custom field. Our plugin supports Wordpress custom fields and advanced custom fields.
123
 
124
  == Changelog ==
125
+ = 1.4.11 (2021-5-4) =
126
+ * Fixed bug that re-uploaded documents instead of patching them
127
+ * Removed unsupported content type custom field settings
128
+ * Changed method to track content changes for patching documents
129
+ * Removed flag that prevented uploading certain untracked documents
130
+
131
  = 1.4.10 (2021-4-15) =
132
  * Fixed bug that slowed down the download and upload process
133