WPGlobus – Multilingual Everything! - Version 1.9.21

Version Description

  • FIXED:
    • All in One SEO Pack: correct saving empty value (keyword, description) for extra languages.
    • Yoast SEO: correct filter multilingual title on front-end.
Download this release

Release Info

Developer tivnet
Plugin Icon 128x128 WPGlobus – Multilingual Everything!
Version 1.9.21
Comparing to
See all releases

Code changes from version 1.9.20 to 1.9.21

includes/vendor/aioseopack/class-wpglobus-aioseopack.php CHANGED
@@ -46,7 +46,7 @@ class WPGlobus_All_in_One_SEO_Pack {
46
  */
47
  add_filter( 'localization', array( __CLASS__, 'filter__title' ), 0 );
48
  }
49
-
50
  /**
51
  * Get instance of this class.
52
  *
@@ -59,6 +59,18 @@ class WPGlobus_All_in_One_SEO_Pack {
59
  return self::$instance;
60
  }
61
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  /**
63
  * All In One SEO Pack has not filter for title when generate it in get_page_snippet_info() function.
64
  * @see '$title = $this->internationalize( get_post_meta( $post->ID, '_aioseop_title', true ) );' string in all-in-one-seo-pack\aioseop_class.php.
@@ -85,12 +97,21 @@ class WPGlobus_All_in_One_SEO_Pack {
85
 
86
  /**
87
  * Get exist fields before deleting.
 
 
 
 
 
 
 
88
  */
89
  public static function filter__get_exist_fields( $check, $object_id, $meta_key, $meta_value, $delete_all ) {
90
 
91
  if ( $delete_all ) {
92
  return $check;
93
  }
 
 
94
 
95
  if ( isset( self::$meta_fields[ $meta_key ] ) ) {
96
 
@@ -100,12 +121,46 @@ class WPGlobus_All_in_One_SEO_Pack {
100
 
101
  global $wpdb;
102
 
103
- //$value = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key = %s AND post_id = %d;", $meta_key, $object_id ) );
104
  $value = $wpdb->get_results( $wpdb->prepare( "SELECT meta_value, meta_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND post_id = %d;", $meta_key, $object_id ) );
105
 
106
  if ( $value && $value[0] ) {
107
- self::$meta_fields[ $meta_key ] = $value[0]->meta_value;
108
  self::$meta_fields_in_processing[ $meta_key ] = $value[0]->meta_id;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  }
110
 
111
  }
@@ -120,7 +175,7 @@ class WPGlobus_All_in_One_SEO_Pack {
120
  public static function filter__rewrite_fields( $check, $object_id, $meta_key, $meta_value ) {
121
 
122
  global $wpdb;
123
-
124
  if ( isset( self::$meta_fields[ $meta_key ] ) ) {
125
 
126
  if ( ! isset( self::$meta_fields_in_processing[ $meta_key ] ) ) {
@@ -134,21 +189,21 @@ class WPGlobus_All_in_One_SEO_Pack {
134
  $ml_value[$language] = $val;
135
  }
136
  }
137
-
138
  if ( empty($meta_value) ) {
139
  unset( $ml_value[ WPGlobus::Config()->builder->get_language() ] );
140
  } else {
141
  $ml_value[ WPGlobus::Config()->builder->get_language() ] = $meta_value;
142
  }
143
-
144
- $meta_value = WPGlobus_Utils::build_multilingual_string($ml_value);
145
 
146
  $meta_value = maybe_serialize( $meta_value );
 
 
 
 
147
 
148
- if ( isset(self::$meta_fields_in_processing[ $meta_key ]) && (int) self::$meta_fields_in_processing[ $meta_key ] > 0 ) {
149
-
150
- $mid = (int) self::$meta_fields_in_processing[ $meta_key ];
151
-
152
  $result = $wpdb->update(
153
  $wpdb->postmeta,
154
  array(
@@ -183,11 +238,11 @@ class WPGlobus_All_in_One_SEO_Pack {
183
  wp_cache_delete( $object_id, 'post_meta' );
184
 
185
  unset( self::$meta_fields_in_processing[ $meta_key ] );
186
-
187
  return $mid;
188
 
189
  }
190
-
191
  return $check;
192
 
193
  }
46
  */
47
  add_filter( 'localization', array( __CLASS__, 'filter__title' ), 0 );
48
  }
49
+
50
  /**
51
  * Get instance of this class.
52
  *
59
  return self::$instance;
60
  }
61
 
62
+ /**
63
+ * We need to have own copy of this function because we should save empty value if some field in current language is empty.
64
+ * @since 1.9.18
65
+ */
66
+ protected static function build_multilingual_string( $translations ) {
67
+ $sz = '';
68
+ foreach ( $translations as $language => $text ) {
69
+ $sz .= WPGlobus::add_locale_marks( $text, $language );
70
+ }
71
+ return $sz;
72
+ }
73
+
74
  /**
75
  * All In One SEO Pack has not filter for title when generate it in get_page_snippet_info() function.
76
  * @see '$title = $this->internationalize( get_post_meta( $post->ID, '_aioseop_title', true ) );' string in all-in-one-seo-pack\aioseop_class.php.
97
 
98
  /**
99
  * Get exist fields before deleting.
100
+ *
101
+ * AioSEOPack does strange thing, it deletes meta from table and adds it again instead of updating.
102
+ * Let's revise this scenario.
103
+ * 1. get meta ID and meta Value for existing fields @see 'filter__get_exist_fields' filter.
104
+ * 2. remove meta value for current language, if we don't do it in 'filter__get_exist_fields' then we can not do it in 'filter__rewrite_fields'.
105
+ * 3. update meta @see 'filter__rewrite_fields' filter.
106
+ * 4. or add meta if it is not exists.
107
  */
108
  public static function filter__get_exist_fields( $check, $object_id, $meta_key, $meta_value, $delete_all ) {
109
 
110
  if ( $delete_all ) {
111
  return $check;
112
  }
113
+
114
+ global $wpdb;
115
 
116
  if ( isset( self::$meta_fields[ $meta_key ] ) ) {
117
 
121
 
122
  global $wpdb;
123
 
 
124
  $value = $wpdb->get_results( $wpdb->prepare( "SELECT meta_value, meta_id FROM {$wpdb->postmeta} WHERE meta_key = %s AND post_id = %d;", $meta_key, $object_id ) );
125
 
126
  if ( $value && $value[0] ) {
127
+
128
  self::$meta_fields_in_processing[ $meta_key ] = $value[0]->meta_id;
129
+
130
+ if ( empty( $value[0]->meta_value ) ) {
131
+
132
+ self::$meta_fields[ $meta_key ] = '';
133
+
134
+ } else {
135
+
136
+ self::$meta_fields[ $meta_key ] = $value[0]->meta_value;
137
+
138
+ $_ml_value = array();
139
+ foreach( WPGlobus::Config()->enabled_languages as $language ) :
140
+ if ( $language == WPGlobus::Config()->builder->get_language() ) {
141
+ $_ml_value[$language] = '';
142
+ } else {
143
+ $_ml_value[$language] = WPGlobus_Core::text_filter(self::$meta_fields[ $meta_key ], $language, WPGlobus::RETURN_EMPTY);
144
+ }
145
+ endforeach;
146
+
147
+ self::$meta_fields[ $meta_key ] = self::build_multilingual_string($_ml_value);
148
+
149
+ self::$meta_fields[ $meta_key ] = maybe_serialize( self::$meta_fields[ $meta_key ] );
150
+
151
+ }
152
+
153
+ $result = $wpdb->update(
154
+ $wpdb->postmeta,
155
+ array(
156
+ 'meta_key' => $meta_key,
157
+ 'meta_value' => self::$meta_fields[ $meta_key ]
158
+ ),
159
+ array( 'meta_id' => self::$meta_fields_in_processing[ $meta_key ] ),
160
+ array( '%s', '%s' ),
161
+ array( '%d' )
162
+ );
163
+
164
  }
165
 
166
  }
175
  public static function filter__rewrite_fields( $check, $object_id, $meta_key, $meta_value ) {
176
 
177
  global $wpdb;
178
+
179
  if ( isset( self::$meta_fields[ $meta_key ] ) ) {
180
 
181
  if ( ! isset( self::$meta_fields_in_processing[ $meta_key ] ) ) {
189
  $ml_value[$language] = $val;
190
  }
191
  }
192
+
193
  if ( empty($meta_value) ) {
194
  unset( $ml_value[ WPGlobus::Config()->builder->get_language() ] );
195
  } else {
196
  $ml_value[ WPGlobus::Config()->builder->get_language() ] = $meta_value;
197
  }
198
+
199
+ $meta_value = self::build_multilingual_string($ml_value);
200
 
201
  $meta_value = maybe_serialize( $meta_value );
202
+
203
+ $mid = (int) self::$meta_fields_in_processing[ $meta_key ];
204
+
205
+ if ( $mid > 0 ) {
206
 
 
 
 
 
207
  $result = $wpdb->update(
208
  $wpdb->postmeta,
209
  array(
238
  wp_cache_delete( $object_id, 'post_meta' );
239
 
240
  unset( self::$meta_fields_in_processing[ $meta_key ] );
241
+
242
  return $mid;
243
 
244
  }
245
+
246
  return $check;
247
 
248
  }
includes/vendor/yoast-seo/class-wpglobus-yoastseo80.php CHANGED
@@ -116,10 +116,6 @@ class WPGlobus_YoastSEO {
116
  * AJAX is probably not required (waiting for a case).
117
  */
118
  //add_filter( 'wpseo_title', array( 'WPGlobus_Filters', 'filter__text' ), PHP_INT_MAX );
119
- /**
120
- * '_yoast_wpseo_title' field is not multilingual @see yoast-seo.json because it is a mask only.
121
- * @since 1.9.18
122
- */
123
  add_filter( 'wpseo_title', array( __CLASS__, 'filter__title' ), PHP_INT_MAX );
124
 
125
  add_filter( 'wpseo_metadesc', array( 'WPGlobus_Filters', 'filter__text' ), PHP_INT_MAX );
@@ -129,14 +125,14 @@ class WPGlobus_YoastSEO {
129
  * @see <title> view-source:http://www.dev-wpg.com/test-post-seo/
130
  * @see <title> view-source:http://www.dev-wpg.com/ru/test-post-seo/
131
  */
132
- //add_filter( 'get_post_metadata', array( __CLASS__, 'filter__get_post_metadata' ), 0, 4 );
133
 
134
  /**
135
  * Filter meta keywords.
136
  * @from 1.8.8
137
  */
138
  add_filter( 'wpseo_metakeywords', array( __CLASS__, 'filter__metakeywords' ), 0 );
139
-
140
  }
141
 
142
  }
@@ -151,10 +147,58 @@ class WPGlobus_YoastSEO {
151
  * @return string.
152
  */
153
  public static function filter__title( $title ) {
154
- //if ( WPGlobus::Config()->language == WPGlobus::Config()->default_language ) {
155
- //return $title;
156
- //}
157
- return WPGlobus_Core::extract_text( $title, WPGlobus::Config()->language );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  }
159
 
160
  /**
@@ -222,7 +266,7 @@ class WPGlobus_YoastSEO {
222
  *
223
  * @return null|array Return metadata array if we are "in business".
224
  */
225
- public static function filter__get_post_metadata(
226
  $metadata, $post_id, $meta_key, $single
227
  ) {
228
  // Yoast does not pass any `meta_key`, and does not ask for `single`.
116
  * AJAX is probably not required (waiting for a case).
117
  */
118
  //add_filter( 'wpseo_title', array( 'WPGlobus_Filters', 'filter__text' ), PHP_INT_MAX );
 
 
 
 
119
  add_filter( 'wpseo_title', array( __CLASS__, 'filter__title' ), PHP_INT_MAX );
120
 
121
  add_filter( 'wpseo_metadesc', array( 'WPGlobus_Filters', 'filter__text' ), PHP_INT_MAX );
125
  * @see <title> view-source:http://www.dev-wpg.com/test-post-seo/
126
  * @see <title> view-source:http://www.dev-wpg.com/ru/test-post-seo/
127
  */
128
+ add_filter( 'get_post_metadata', array( __CLASS__, 'filter__get_post_metadata' ), 6, 4 );
129
 
130
  /**
131
  * Filter meta keywords.
132
  * @from 1.8.8
133
  */
134
  add_filter( 'wpseo_metakeywords', array( __CLASS__, 'filter__metakeywords' ), 0 );
135
+
136
  }
137
 
138
  }
147
  * @return string.
148
  */
149
  public static function filter__title( $title ) {
150
+ /**
151
+ * In some cases we can get $title like {:en}En title{:}{:ru}Ru title{:}{:fr}Fr title{:} - SiteTitle
152
+ * so, let's filter.
153
+ */
154
+ if ( WPGlobus_Core::has_translations($title) ) {
155
+ return WPGlobus_Core::extract_text( $title, WPGlobus::Config()->language );
156
+ }
157
+ return $title;
158
+ }
159
+
160
+ /**
161
+ * Filter post meta.
162
+ *
163
+ * @since 1.9.21
164
+ * @see function function get_value() in wordpress-seo\inc\class-wpseo-meta.php
165
+ */
166
+ public static function filter__get_post_metadata( $check, $object_id, $meta_key, $single ) {
167
+
168
+ global $post;
169
+
170
+ if ( $single ) {
171
+ return $check;
172
+ }
173
+
174
+ if ( ! is_object($post) ) {
175
+ return $check;
176
+ }
177
+
178
+ if ( $object_id != $post->ID ) {
179
+ return $check;
180
+ }
181
+
182
+ $meta_type = 'post';
183
+
184
+ /**
185
+ * May be called many times on one page. Let's cache.
186
+ */
187
+ static $_cache;
188
+ if ( isset( $_cache[ $meta_type ][ $object_id ] ) ) {
189
+ return $_cache[ $meta_type ][ $object_id ];
190
+ }
191
+
192
+ $meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
193
+
194
+ if ( ! empty($meta_cache['_yoast_wpseo_title'][0]) ) {
195
+ $meta_cache['_yoast_wpseo_title'][0] = WPGlobus_Core::text_filter( $meta_cache['_yoast_wpseo_title'][0], WPGlobus::Config()->language, WPGlobus::RETURN_EMPTY );
196
+ }
197
+
198
+ $_cache[ $meta_type ][ $object_id ] = $meta_cache;
199
+
200
+ return $meta_cache;
201
+
202
  }
203
 
204
  /**
266
  *
267
  * @return null|array Return metadata array if we are "in business".
268
  */
269
+ public static function filter__get_post_metadata_OLD(
270
  $metadata, $post_id, $meta_key, $single
271
  ) {
272
  // Yoast does not pass any `meta_key`, and does not ask for `single`.
languages/wpglobus.pot CHANGED
@@ -1,8 +1,8 @@
1
- # Copyright (C) 2018 WPGlobus 1.9.20
2
- # This file is distributed under the same license as the WPGlobus 1.9.20 package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: WPGlobus 1.9.20\n"
6
  "MIME-Version: 1.0\n"
7
  "Content-Type: text/plain; charset=UTF-8\n"
8
  "Content-Transfer-Encoding: 8bit\n"
1
+ # Copyright (C) 2018 WPGlobus 1.9.21
2
+ # This file is distributed under the same license as the WPGlobus 1.9.21 package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: WPGlobus 1.9.21\n"
6
  "MIME-Version: 1.0\n"
7
  "Content-Type: text/plain; charset=UTF-8\n"
8
  "Content-Transfer-Encoding: 8bit\n"
readme.txt CHANGED
@@ -218,6 +218,12 @@ This maintenance release introduces Gutenberg support in beta-stage.
218
 
219
  == Changelog ==
220
 
 
 
 
 
 
 
221
  = 1.9.20 =
222
 
223
  * FIXED:
218
 
219
  == Changelog ==
220
 
221
+ = 1.9.21 =
222
+
223
+ * FIXED:
224
+ * All in One SEO Pack: correct saving empty value (keyword, description) for extra languages.
225
+ * Yoast SEO: correct filter multilingual title on front-end.
226
+
227
  = 1.9.20 =
228
 
229
  * FIXED:
wpglobus.php CHANGED
@@ -15,7 +15,7 @@
15
  * Description: A WordPress Globalization / Multilingual Plugin. Posts, pages, menus, widgets and even custom fields - in multiple languages!
16
  * Text Domain: wpglobus
17
  * Domain Path: /languages/
18
- * Version: 1.9.20
19
  * Author: WPGlobus
20
  * Author URI: https://wpglobus.com/
21
  * Network: false
@@ -42,7 +42,7 @@ if ( ! defined( 'ABSPATH' ) ) {
42
  exit;
43
  }
44
 
45
- define( 'WPGLOBUS_VERSION', '1.9.20' );
46
  define( 'WPGLOBUS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
47
 
48
  /**
15
  * Description: A WordPress Globalization / Multilingual Plugin. Posts, pages, menus, widgets and even custom fields - in multiple languages!
16
  * Text Domain: wpglobus
17
  * Domain Path: /languages/
18
+ * Version: 1.9.21
19
  * Author: WPGlobus
20
  * Author URI: https://wpglobus.com/
21
  * Network: false
42
  exit;
43
  }
44
 
45
+ define( 'WPGLOBUS_VERSION', '1.9.21' );
46
  define( 'WPGLOBUS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
47
 
48
  /**