WPGlobus – Multilingual Everything! - Version 2.5.7

Version Description

  • (Core) Registered a new field, translation, in the Rest API response for posts.
Download this release

Release Info

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

Code changes from version 2.5.6 to 2.5.7

includes/class-wpglobus-rest-api.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * File: class-wpglobus-rest-api.php
4
+ *
5
+ * @package WPGlobus
6
+ * @since 2.5.7
7
+ */
8
+
9
+ /**
10
+ * Class WPGlobus_Rest_API
11
+ */
12
+ if ( ! class_exists( 'WPGlobus_Rest_API' ) ) :
13
+
14
+ class WPGlobus_Rest_API {
15
+
16
+ /**
17
+ * Constructor.
18
+ */
19
+ public static function construct() {
20
+
21
+ /**
22
+ * @see wp-includes\rest-api.php
23
+ */
24
+ register_rest_field(
25
+ 'post',
26
+ 'translation',
27
+ array(
28
+ 'get_callback' => array( __CLASS__, 'on__register_rest_field' ),
29
+ )
30
+ );
31
+ }
32
+
33
+ /**
34
+ * Registers a new field.
35
+ *
36
+ *
37
+ * @param string|array $object_type Object(s) the field is being registered
38
+ * to, "post"|"term"|"comment" etc.
39
+ * @param string $attribute The attribute name.
40
+ * @param array $args {
41
+ * Optional. An array of arguments used to handle the registered field.
42
+ *
43
+ * @type callable|null $get_callback Optional. The callback function used to retrieve the field value. Default is
44
+ * 'null', the field will not be returned in the response. The function will
45
+ * be passed the prepared object data.
46
+ * @type callable|null $update_callback Optional. The callback function used to set and update the field value. Default
47
+ * is 'null', the value cannot be set or updated. The function will be passed
48
+ * the model object, like WP_Post.
49
+ * @type array|null $schema Optional. The callback function used to create the schema for this field.
50
+ * Default is 'null', no schema entry will be returned.
51
+ * }
52
+ */
53
+ public static function on__register_rest_field( $object_type, $attribute, $args ) {
54
+
55
+ $response = array(
56
+ 'provider' => 'WPGlobus',
57
+ 'version' => WPGLOBUS_VERSION,
58
+ 'language' => WPGlobus::Config()->language,
59
+ 'enabled_languages' => WPGlobus::Config()->enabled_languages,
60
+ 'languages' => null
61
+ );
62
+
63
+ $_fields = array( 'title', 'content', 'excerpt' );
64
+ foreach( WPGlobus::Config()->enabled_languages as $_language ) {
65
+ foreach( $_fields as $_field ) {
66
+ if ( empty( $object_type[$_field]['raw'] ) ) {
67
+ $response['languages'][$_language][$_field] = false;
68
+ } else {
69
+ $response['languages'][$_language][$_field] = WPGlobus_Core::has_translation( $object_type[$_field]['raw'], $_language );
70
+ }
71
+ }
72
+ }
73
+
74
+ return $response;
75
+ }
76
+ } // class
77
+
78
+ endif;
79
+
80
+ # --- EOF
languages/wpglobus.pot CHANGED
@@ -1,8 +1,8 @@
1
- # Copyright (C) 2020 WPGlobus 2.5.6
2
- # This file is distributed under the same license as the WPGlobus 2.5.6 package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: WPGlobus 2.5.6\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) 2020 WPGlobus 2.5.7
2
+ # This file is distributed under the same license as the WPGlobus 2.5.7 package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: WPGlobus 2.5.7\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
@@ -217,6 +217,10 @@ WPGlobus Version 2 supports WordPress 5.x, with Gutenberg.
217
 
218
  == Changelog ==
219
 
 
 
 
 
220
  = 2.5.6 =
221
 
222
  * (Core) Added `has_translation` function.
217
 
218
  == Changelog ==
219
 
220
+ = 2.5.7 =
221
+
222
+ * (Core) Registered a new field, `translation`, in the Rest API response for posts.
223
+
224
  = 2.5.6 =
225
 
226
  * (Core) Added `has_translation` function.
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: 2.5.6
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', '2.5.6' );
46
  define( 'WPGLOBUS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
47
  define( 'WPGLOBUS_AJAX', 'wpglobus-ajax' );
48
 
@@ -83,6 +83,8 @@ require_once dirname( __FILE__ ) . '/includes/class-wpglobus.php';
83
 
84
  require_once dirname( __FILE__ ) . '/includes/class-wpglobus-core.php';
85
 
 
 
86
  /**
87
  * Admin page helpers.
88
  *
@@ -104,6 +106,8 @@ WPGlobus::Config();
104
  require_once dirname( __FILE__ ) . '/includes/class-wpglobus-filters.php';
105
  require_once dirname( __FILE__ ) . '/includes/wpglobus-controller.php';
106
 
 
 
107
  /**
108
  * Support for Yoast SEO
109
  */
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: 2.5.7
19
  * Author: WPGlobus
20
  * Author URI: https://wpglobus.com/
21
  * Network: false
42
  exit;
43
  }
44
 
45
+ define( 'WPGLOBUS_VERSION', '2.5.7' );
46
  define( 'WPGLOBUS_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
47
  define( 'WPGLOBUS_AJAX', 'wpglobus-ajax' );
48
 
83
 
84
  require_once dirname( __FILE__ ) . '/includes/class-wpglobus-core.php';
85
 
86
+ require_once dirname( __FILE__ ) . '/includes/class-wpglobus-rest-api.php';
87
+
88
  /**
89
  * Admin page helpers.
90
  *
106
  require_once dirname( __FILE__ ) . '/includes/class-wpglobus-filters.php';
107
  require_once dirname( __FILE__ ) . '/includes/wpglobus-controller.php';
108
 
109
+ WPGlobus_Rest_API::construct();
110
+
111
  /**
112
  * Support for Yoast SEO
113
  */