WPGlobus – Multilingual Everything! - Version 1.9.25

Version Description

  • ADDED:
    • Core/Meta: filter to enable/disable meta.
    • Vendor/ACF: New function to get ACF fields for post.
Download this release

Release Info

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

Code changes from version 1.9.24 to 1.9.25

includes/admin/meta/class-wpglobus-meta.php CHANGED
@@ -3,6 +3,7 @@
3
  * Class WPGlobus_Meta
4
  *
5
  * @since 1.9.17
 
6
  *
7
  * @package WPGlobus\Admin\Meta
8
  * @author Alex Gor(alexgff)
@@ -75,6 +76,12 @@ if ( ! class_exists( 'WPGlobus_Meta' ) ) :
75
 
76
  return self::$instance;
77
  }
 
 
 
 
 
 
78
 
79
  /**
80
  * Update post meta data.
@@ -150,7 +157,14 @@ if ( ! class_exists( 'WPGlobus_Meta' ) ) :
150
  $_passed_value = $passed_value;
151
 
152
  if ( ! empty( $_passed_value ) && WPGlobus::Config()->default_language !== self::$builder->get_language() ) {
153
- $_passed_value = WPGlobus_Utils::build_multilingual_string( array( self::$builder->get_language() => $_passed_value ) );
 
 
 
 
 
 
 
154
  }
155
 
156
  return add_metadata( $meta_type, $object_id, $raw_meta_key, $_passed_value );
@@ -175,53 +189,62 @@ if ( ! class_exists( 'WPGlobus_Meta' ) ) :
175
 
176
  if ( isset( $meta_cache[ $meta_key ] ) ) {
177
 
178
- foreach ( $meta_cache[ $meta_key ] as $_key => $_ml_value ) {
 
 
 
 
 
 
 
179
 
180
- $_new_ml_array = array();
181
 
182
- if ( WPGlobus_Core::has_translations( $_ml_value ) ) {
183
 
184
- foreach ( WPGlobus::Config()->enabled_languages as $language ) :
185
 
186
- if ( $language === self::$builder->get_language() ) {
187
 
188
- if ( ! empty( $meta_value ) ) {
189
- $_new_ml_array[ $language ] = $meta_value;
190
- }
191
- } else {
192
 
193
- $_value = WPGlobus_Core::text_filter( $_ml_value, $language, WPGlobus::RETURN_EMPTY );
194
 
195
- if ( '' !== $_value ) {
196
- $_new_ml_array[ $language ] = $_value;
 
197
  }
198
- }
199
 
200
- endforeach;
201
 
202
- $_new_value = WPGlobus_Utils::build_multilingual_string( $_new_ml_array );
203
-
204
- } else {
205
 
206
- if ( WPGlobus::Config()->default_language === self::$builder->get_language() ) {
207
- $_new_ml_array[ WPGlobus::Config()->default_language ] = $meta_value;
208
  } else {
209
- $_new_ml_array[ WPGlobus::Config()->default_language ] = $_ml_value;
210
- if ( ! empty( $meta_value ) ) {
211
- $_new_ml_array[ self::$builder->get_language() ] = $meta_value;
 
 
 
 
 
212
  }
213
- }
214
 
215
- $_new_value = WPGlobus_Utils::build_multilingual_string( $_new_ml_array );
216
 
217
- }
218
 
219
- if ( ! empty( $_new_value ) ) {
220
- $meta_value = maybe_unserialize( $_new_value );
 
 
221
  }
222
  }
223
  }
224
-
225
  $data = compact( 'meta_value' );
226
  $where = array(
227
  $column => $object_id,
@@ -229,7 +252,7 @@ if ( ! class_exists( 'WPGlobus_Meta' ) ) :
229
  );
230
 
231
  $result = $wpdb->update( $table, $data, $where );
232
-
233
  if ( ! $result ) {
234
  return false;
235
  }
@@ -343,6 +366,22 @@ if ( ! class_exists( 'WPGlobus_Meta' ) ) :
343
  $return_value = 'as_single';
344
  }
345
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
346
  /**
347
  * May be called many times on one page. Let's cache.
348
  */
@@ -375,7 +414,7 @@ if ( ! class_exists( 'WPGlobus_Meta' ) ) :
375
  }
376
  }
377
  }
378
-
379
  $_cache[ $_cache_meta_key ][ $object_id ][ $return_value ] = $meta_cache;
380
 
381
  return $meta_cache;
@@ -387,12 +426,18 @@ if ( ! class_exists( 'WPGlobus_Meta' ) ) :
387
  if ( $single ) {
388
 
389
  $_value = WPGlobus_Core::text_filter( $meta_cache[ $meta_key ][0], self::$builder->get_language(), WPGlobus::RETURN_EMPTY );
390
-
391
  if ( ! empty( $_value ) ) {
392
  $_value = maybe_unserialize( $_value );
393
  }
394
 
395
- $_cache[ $_cache_meta_key ][ $object_id ][ $return_value ] = $_value;
 
 
 
 
 
 
396
 
397
  return $_value;
398
 
@@ -448,6 +493,30 @@ if ( ! class_exists( 'WPGlobus_Meta' ) ) :
448
 
449
  return false;
450
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
  }
452
 
453
  endif;
3
  * Class WPGlobus_Meta
4
  *
5
  * @since 1.9.17
6
+ * @since 1.9.25 Added build_multilingual_string function.
7
  *
8
  * @package WPGlobus\Admin\Meta
9
  * @author Alex Gor(alexgff)
76
 
77
  return self::$instance;
78
  }
79
+
80
+ /**
81
+ public static function get_post_meta( $post_id = false ) {
82
+ $meta_cache = wp_cache_get($post_id, 'post_meta');
83
+ }
84
+ // */
85
 
86
  /**
87
  * Update post meta data.
157
  $_passed_value = $passed_value;
158
 
159
  if ( ! empty( $_passed_value ) && WPGlobus::Config()->default_language !== self::$builder->get_language() ) {
160
+ if ( WPGlobus_Core::has_translations( $_passed_value ) ) {
161
+ /**
162
+ * We get multilingual $meta_value. Let save it as is.
163
+ * @since 1.9.25 do nothing.
164
+ */
165
+ } else {
166
+ $_passed_value = self::build_multilingual_string( array( self::$builder->get_language() => $_passed_value ) );
167
+ }
168
  }
169
 
170
  return add_metadata( $meta_type, $object_id, $raw_meta_key, $_passed_value );
189
 
190
  if ( isset( $meta_cache[ $meta_key ] ) ) {
191
 
192
+ if ( WPGlobus_Core::has_translations( $passed_value ) ) {
193
+ /**
194
+ * We get multilingual $meta_value. Let save it as is.
195
+ */
196
+ // @since 1.9.25 do nothing.
197
+ } else {
198
+
199
+ foreach ( $meta_cache[ $meta_key ] as $_key => $_ml_value ) {
200
 
201
+ $_new_ml_array = array();
202
 
203
+ if ( WPGlobus_Core::has_translations( $_ml_value ) ) {
204
 
205
+ foreach ( WPGlobus::Config()->enabled_languages as $language ) :
206
 
207
+ if ( $language === self::$builder->get_language() ) {
208
 
209
+ if ( ! empty( $meta_value ) ) {
210
+ $_new_ml_array[ $language ] = $meta_value;
211
+ }
212
+ } else {
213
 
214
+ $_value = WPGlobus_Core::text_filter( $_ml_value, $language, WPGlobus::RETURN_EMPTY );
215
 
216
+ if ( '' !== $_value ) {
217
+ $_new_ml_array[ $language ] = $_value;
218
+ }
219
  }
 
220
 
221
+ endforeach;
222
 
223
+ $_new_value = self::build_multilingual_string( $_new_ml_array );
 
 
224
 
 
 
225
  } else {
226
+
227
+ if ( WPGlobus::Config()->default_language === self::$builder->get_language() ) {
228
+ $_new_ml_array[ WPGlobus::Config()->default_language ] = $meta_value;
229
+ } else {
230
+ $_new_ml_array[ WPGlobus::Config()->default_language ] = $_ml_value;
231
+ if ( ! empty( $meta_value ) ) {
232
+ $_new_ml_array[ self::$builder->get_language() ] = $meta_value;
233
+ }
234
  }
 
235
 
236
+ $_new_value = self::build_multilingual_string( $_new_ml_array );
237
 
238
+ }
239
 
240
+ if ( ! empty( $_new_value ) ) {
241
+ //$meta_value = maybe_unserialize( $_new_value );
242
+ $meta_value = $_new_value;
243
+ }
244
  }
245
  }
246
  }
247
+
248
  $data = compact( 'meta_value' );
249
  $where = array(
250
  $column => $object_id,
252
  );
253
 
254
  $result = $wpdb->update( $table, $data, $where );
255
+
256
  if ( ! $result ) {
257
  return false;
258
  }
366
  $return_value = 'as_single';
367
  }
368
 
369
+ /**
370
+ * Disable/enable to filter meta field.
371
+ *
372
+ * @since 1.9.25
373
+ *
374
+ * @param string $meta_key Meta key.
375
+ *
376
+ * @return string|boolean String if to filter meta field or false if not.
377
+ */
378
+ if ( ! empty($meta_key) && is_string($meta_key) ) {
379
+ $meta_key = apply_filters('wpglobus/meta/key', $meta_key);
380
+ if ( false === $meta_key ) {
381
+ return $check;
382
+ }
383
+ }
384
+
385
  /**
386
  * May be called many times on one page. Let's cache.
387
  */
414
  }
415
  }
416
  }
417
+
418
  $_cache[ $_cache_meta_key ][ $object_id ][ $return_value ] = $meta_cache;
419
 
420
  return $meta_cache;
426
  if ( $single ) {
427
 
428
  $_value = WPGlobus_Core::text_filter( $meta_cache[ $meta_key ][0], self::$builder->get_language(), WPGlobus::RETURN_EMPTY );
429
+
430
  if ( ! empty( $_value ) ) {
431
  $_value = maybe_unserialize( $_value );
432
  }
433
 
434
+
435
+ if ( is_array($_value) ) {
436
+ // !!!!!!
437
+ $_value = array($_value);
438
+ } else {
439
+ $_cache[ $_cache_meta_key ][ $object_id ][ $return_value ] = $_value;
440
+ }
441
 
442
  return $_value;
443
 
493
 
494
  return false;
495
  }
496
+
497
+ /**
498
+ * Build multilingual string.
499
+ *
500
+ * @since 1.9.25
501
+ * @todo First idea is: This function needs for Page Builder by SiteOrigin because it should serialize array before creating multilingual string.
502
+ */
503
+ protected static function build_multilingual_string( $ml_array ) {
504
+
505
+ /**
506
+ * @todo W.I.P with Page Builder by SiteOrigin.
507
+ */
508
+ /**
509
+ foreach( $ml_array as $language=>$value ) {
510
+ if ( is_array($value) ) {
511
+ $ml_array[$language] = maybe_serialize($value);
512
+ }
513
+ }
514
+ // */
515
+
516
+ $_str = WPGlobus_Utils::build_multilingual_string($ml_array);
517
+
518
+ return $_str;
519
+ }
520
  }
521
 
522
  endif;
includes/vendor/acf/class-wpglobus-acf.php CHANGED
@@ -10,6 +10,8 @@
10
  */
11
  class WPGlobus_Acf_2 {
12
 
 
 
13
  protected static $post_multilingual_fields = null;
14
 
15
  protected static $post_acf_field_prefix = 'acf-';
@@ -46,17 +48,102 @@ class WPGlobus_Acf_2 {
46
  return self::$post_multilingual_fields;
47
  }
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  /**
50
  * Get post meta.
 
51
  * Don't use get_field_objects() to get ACF fields @see advanced-custom-fields\includes\api\api-template.php
52
  * to prevent incorrect behavior on post page.
53
- */
54
  public static function get_post_meta_fields( $post_id ) {
55
 
56
  global $wpdb;
57
 
58
  $_post_meta_fields = array();
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  $post_id = (int) $post_id;
61
 
62
  if ( $post_id > 0 ) {
10
  */
11
  class WPGlobus_Acf_2 {
12
 
13
+ protected static $acf_fields = null;
14
+
15
  protected static $post_multilingual_fields = null;
16
 
17
  protected static $post_acf_field_prefix = 'acf-';
48
  return self::$post_multilingual_fields;
49
  }
50
 
51
+ /**
52
+ * Retrieves acf fields which was got @see get_post_meta_fields().
53
+ *
54
+ * @since 1.9.25
55
+ *
56
+ * @param int|string $post_id Reserved for future version.
57
+ *
58
+ * @return array|false An array of acf fields or false if $acf_fields is null.
59
+ */
60
+ public static function get_acf_fields( $post_id ) {
61
+ if ( ! is_null( self::$acf_fields ) ) {
62
+ return self::$acf_fields;
63
+ }
64
+ return false;
65
+ }
66
+
67
  /**
68
  * Get post meta.
69
+ *
70
  * Don't use get_field_objects() to get ACF fields @see advanced-custom-fields\includes\api\api-template.php
71
  * to prevent incorrect behavior on post page.
72
+ */
73
  public static function get_post_meta_fields( $post_id ) {
74
 
75
  global $wpdb;
76
 
77
  $_post_meta_fields = array();
78
 
79
+ $post_id = (int) $post_id;
80
+
81
+ if ( $post_id > 0 ) {
82
+
83
+ $info = acf_get_post_id_info( $post_id );
84
+
85
+ if ( $info['type'] == 'post' ) {
86
+
87
+ /**
88
+ * @todo Check the case when DB has many records with 'acf-field' post type.
89
+ */
90
+ $fields = $wpdb->get_results($wpdb->prepare(
91
+ "SELECT post_excerpt, post_name FROM $wpdb->posts WHERE post_type = '%s'",
92
+ 'acf-field'
93
+ ) );
94
+
95
+ if ( ! empty($fields) ) {
96
+
97
+ /**
98
+ * Filter to enable/disable wysiwyg field.
99
+ * Returning boolean.
100
+ *
101
+ * @since 1.9.17
102
+ *
103
+ * @param boolean.
104
+ */
105
+ $field_wysiwyg_enabled = apply_filters('wpglobus/vendor/acf/field/wysiwyg', false);
106
+
107
+ self::$post_multilingual_fields = array();
108
+
109
+ foreach( $fields as $key=>$field ) :
110
+
111
+ $_acf_field = acf_maybe_get_field( $field->post_name );
112
+
113
+ if ( empty($_acf_field['type']) ) {
114
+ continue;
115
+ }
116
+
117
+ if ( $_acf_field['type'] == 'wysiwyg' && ! $field_wysiwyg_enabled ) {
118
+ // do nothing
119
+ } else {
120
+ $_post_meta_fields[] = $field->post_excerpt;
121
+ self::$post_multilingual_fields[] = self::$post_acf_field_prefix . $field->post_name;
122
+ }
123
+ self::$acf_fields[$field->post_excerpt] = $_acf_field;
124
+
125
+ endforeach;
126
+ }
127
+ }
128
+ }
129
+
130
+ return $_post_meta_fields;
131
+
132
+ }
133
+
134
+ /**
135
+ * Get post meta.
136
+ *
137
+ * Version 0.
138
+ * Don't use get_field_objects() to get ACF fields @see advanced-custom-fields\includes\api\api-template.php
139
+ * to prevent incorrect behavior on post page.
140
+ */
141
+ public static function get_post_meta_fields_0( $post_id ) {
142
+
143
+ global $wpdb;
144
+
145
+ $_post_meta_fields = array();
146
+
147
  $post_id = (int) $post_id;
148
 
149
  if ( $post_id > 0 ) {
languages/wpglobus.pot CHANGED
@@ -1,8 +1,8 @@
1
- # Copyright (C) 2018 WPGlobus 1.9.24
2
- # This file is distributed under the same license as the WPGlobus 1.9.24 package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: WPGlobus 1.9.24\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.25
2
+ # This file is distributed under the same license as the WPGlobus 1.9.25 package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: WPGlobus 1.9.25\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.24 =
222
 
223
  * FIXED:
218
 
219
  == Changelog ==
220
 
221
+ = 1.9.25 =
222
+
223
+ * ADDED:
224
+ * Core/Meta: filter to enable/disable meta.
225
+ * Vendor/ACF: New function to get ACF fields for post.
226
+
227
  = 1.9.24 =
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.24
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.24' );
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.25
19
  * Author: WPGlobus
20
  * Author URI: https://wpglobus.com/
21
  * Network: false
42
  exit;
43
  }
44
 
45
+ define( 'WPGLOBUS_VERSION', '1.9.25' );
46
  define( 'WPGLOBUS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
47
 
48
  /**