Version Description
- Reduced session failures to debug notices
- Added wp_roles support for WP < 4.3
- Fixed domain listener bugs
Download this release
Release Info
Developer | timwhitlock |
Plugin | Loco Translate |
Version | 2.0.4 |
Comparing to | |
See all releases |
Code changes from version 2.0.3 to 2.0.4
- loco.php +2 -2
- old/tpl/admin-nav.tpl.php +1 -1
- old/tpl/admin-upgrade.tpl.php +3 -3
- readme.txt +5 -0
- src/admin/DebugController.php +1 -0
- src/admin/RootController.php +4 -0
- src/admin/bundle/BaseController.php +11 -4
- src/admin/file/DeleteController.php +10 -4
- src/ajax/XgettextController.php +7 -2
- src/api/WordPressFileSystem.php +25 -12
- src/api/WordPressTranslations.php +1 -0
- src/data/Permissions.php +14 -2
- src/hooks/AdminHooks.php +1 -0
- src/mvc/AdminRouter.php +1 -1
- src/package/Listener.php +38 -38
- tpl/admin/bundle/incompat.php +1 -1
- tpl/admin/config/version.php +1 -1
- tpl/admin/root.php +2 -6
loco.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Loco Translate
|
|
4 |
Plugin URI: https://wordpress.org/plugins/loco-translate/
|
5 |
Description: Translate themes and plugins directly in WordPress
|
6 |
Author: Tim Whitlock
|
7 |
-
Version: 2.0.
|
8 |
Author URI: https://localise.biz/wordpress/plugin
|
9 |
Text Domain: loco
|
10 |
Domain Path: /languages/
|
@@ -45,7 +45,7 @@ function loco_plugin_file(){
|
|
45 |
* @return string
|
46 |
*/
|
47 |
function loco_plugin_version(){
|
48 |
-
return '2.0.
|
49 |
}
|
50 |
|
51 |
|
4 |
Plugin URI: https://wordpress.org/plugins/loco-translate/
|
5 |
Description: Translate themes and plugins directly in WordPress
|
6 |
Author: Tim Whitlock
|
7 |
+
Version: 2.0.4
|
8 |
Author URI: https://localise.biz/wordpress/plugin
|
9 |
Text Domain: loco
|
10 |
Domain Path: /languages/
|
45 |
* @return string
|
46 |
*/
|
47 |
function loco_plugin_version(){
|
48 |
+
return '2.0.4';
|
49 |
}
|
50 |
|
51 |
|
old/tpl/admin-nav.tpl.php
CHANGED
@@ -8,7 +8,7 @@
|
|
8 |
<p>
|
9 |
<strong>Legacy mode:</strong>
|
10 |
You're running the old version of Loco Translate.
|
11 |
-
<a href="<?php echo esc_url(LocoAdmin::uri(array(),'upgrade'))?>">Start using the all new version 2
|
12 |
</p>
|
13 |
</div>
|
14 |
|
8 |
<p>
|
9 |
<strong>Legacy mode:</strong>
|
10 |
You're running the old version of Loco Translate.
|
11 |
+
<a href="<?php echo esc_url(LocoAdmin::uri(array(),'upgrade'))?>">Start using the all new version 2.</a>
|
12 |
</p>
|
13 |
</div>
|
14 |
|
old/tpl/admin-upgrade.tpl.php
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
<div class="wrap loco-admin">
|
2 |
|
3 |
<h3>
|
4 |
-
Start using Loco Translate 2
|
5 |
</h3>
|
6 |
<p>
|
7 |
-
<strong>Version 1 of Loco Translate is
|
8 |
</p>
|
9 |
<p>
|
10 |
-
Version 2
|
11 |
Because it's a major version increase, we're making the upgrade optional for the time being.
|
12 |
</p>
|
13 |
|
1 |
<div class="wrap loco-admin">
|
2 |
|
3 |
<h3>
|
4 |
+
Start using Loco Translate 2
|
5 |
</h3>
|
6 |
<p>
|
7 |
+
<strong>Version 1 of Loco Translate is no longer maintained.</strong>
|
8 |
</p>
|
9 |
<p>
|
10 |
+
Version 2 is a complete rebuild. <a href="https://localise.biz/help/wordpress/translate-plugin/changelog" target="_blank">See what's changed here</a>.<br />
|
11 |
Because it's a major version increase, we're making the upgrade optional for the time being.
|
12 |
</p>
|
13 |
|
readme.txt
CHANGED
@@ -85,6 +85,11 @@ Help is provided via the [plugin support forum](https://wordpress.org/support/pl
|
|
85 |
|
86 |
== Changelog ==
|
87 |
|
|
|
|
|
|
|
|
|
|
|
88 |
= 2.0.3 =
|
89 |
* Added support for Windows servers
|
90 |
* Removed incomplete config warning on bundle overview
|
85 |
|
86 |
== Changelog ==
|
87 |
|
88 |
+
= 2.0.4 =
|
89 |
+
* Reduced session failures to debug notices
|
90 |
+
* Added wp_roles support for WP < 4.3
|
91 |
+
* Fixed domain listener bugs
|
92 |
+
|
93 |
= 2.0.3 =
|
94 |
* Added support for Windows servers
|
95 |
* Removed incomplete config warning on bundle overview
|
src/admin/DebugController.php
CHANGED
@@ -29,6 +29,7 @@ class Loco_admin_DebugController extends Loco_mvc_AdminController {
|
|
29 |
'count' => count($bundle),
|
30 |
);
|
31 |
}
|
|
|
32 |
|
33 |
$plugins = array();
|
34 |
/* @var $bundle Loco_package_Bundle */
|
29 |
'count' => count($bundle),
|
30 |
);
|
31 |
}
|
32 |
+
$this->set('themes', $themes );
|
33 |
|
34 |
$plugins = array();
|
35 |
/* @var $bundle Loco_package_Bundle */
|
src/admin/RootController.php
CHANGED
@@ -66,6 +66,10 @@ class Loco_admin_RootController extends Loco_admin_list_BaseController {
|
|
66 |
$locale = Loco_Locale::parse($tag);
|
67 |
$this->set( 'locale', $locale );
|
68 |
}
|
|
|
|
|
|
|
|
|
69 |
return $this->view('admin/root');
|
70 |
}
|
71 |
|
66 |
$locale = Loco_Locale::parse($tag);
|
67 |
$this->set( 'locale', $locale );
|
68 |
}
|
69 |
+
|
70 |
+
// roll back link
|
71 |
+
$this->set( 'rollback', Loco_mvc_AdminRouter::generate('config-version') );
|
72 |
+
|
73 |
return $this->view('admin/root');
|
74 |
}
|
75 |
|
src/admin/bundle/BaseController.php
CHANGED
@@ -124,11 +124,18 @@ abstract class Loco_admin_bundle_BaseController extends Loco_mvc_AdminController
|
|
124 |
'loco-nonce' => wp_create_nonce('fsConnect'),
|
125 |
) );
|
126 |
$this->set('fsFields', $fields );
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
$
|
|
|
|
|
|
|
131 |
}
|
|
|
|
|
|
|
|
|
132 |
return $fields;
|
133 |
}
|
134 |
|
124 |
'loco-nonce' => wp_create_nonce('fsConnect'),
|
125 |
) );
|
126 |
$this->set('fsFields', $fields );
|
127 |
+
|
128 |
+
// may have fs credentials saved in session
|
129 |
+
try {
|
130 |
+
$session = Loco_data_Session::get();
|
131 |
+
if( isset($session['loco-fs']) ){
|
132 |
+
$fields['connection_type'] = $session['loco-fs']['connection_type'];
|
133 |
+
}
|
134 |
}
|
135 |
+
catch( Exception $e ){
|
136 |
+
Loco_error_AdminNotices::debug( $e->getMessage() );
|
137 |
+
}
|
138 |
+
|
139 |
return $fields;
|
140 |
}
|
141 |
|
src/admin/file/DeleteController.php
CHANGED
@@ -79,10 +79,16 @@ class Loco_admin_file_DeleteController extends Loco_admin_file_BaseController {
|
|
79 |
$api->authorizeDelete($trash);
|
80 |
$trash->unlink();
|
81 |
}
|
82 |
-
//
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
$href = Loco_mvc_AdminRouter::generate( $this->get('type').'-view', array( 'bundle' => $this->get('bundle') ) );
|
87 |
if( wp_redirect($href) ){
|
88 |
exit;
|
79 |
$api->authorizeDelete($trash);
|
80 |
$trash->unlink();
|
81 |
}
|
82 |
+
// flash message for display after redirect
|
83 |
+
try {
|
84 |
+
$n = count( $files );
|
85 |
+
Loco_data_Session::get()->flash('success', sprintf( _n('File deleted','%u files deleted',$n,'loco'),$n) );
|
86 |
+
Loco_data_Session::close();
|
87 |
+
}
|
88 |
+
catch( Exception $e ){
|
89 |
+
// tollerate session failure
|
90 |
+
}
|
91 |
+
// redirect to bundle overview
|
92 |
$href = Loco_mvc_AdminRouter::generate( $this->get('type').'-view', array( 'bundle' => $this->get('bundle') ) );
|
93 |
if( wp_redirect($href) ){
|
94 |
exit;
|
src/ajax/XgettextController.php
CHANGED
@@ -56,8 +56,13 @@ class Loco_ajax_XgettextController extends Loco_ajax_common_BundleController {
|
|
56 |
Loco_data_RecentItems::get()->pushBundle( $bundle )->persist();
|
57 |
|
58 |
// put flash message into session to be displayed on redirected page
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
// redirect front end to bundle view. Discourages manual editing of template
|
63 |
$type = strtolower( $bundle->getType() );
|
56 |
Loco_data_RecentItems::get()->pushBundle( $bundle )->persist();
|
57 |
|
58 |
// put flash message into session to be displayed on redirected page
|
59 |
+
try {
|
60 |
+
Loco_data_Session::get()->flash('success', __('Template file created','loco') );
|
61 |
+
Loco_data_Session::close();
|
62 |
+
}
|
63 |
+
catch( Exception $e ){
|
64 |
+
Loco_error_AdminNotices::debug( $e->getMessage() );
|
65 |
+
}
|
66 |
|
67 |
// redirect front end to bundle view. Discourages manual editing of template
|
68 |
$type = strtolower( $bundle->getType() );
|
src/api/WordPressFileSystem.php
CHANGED
@@ -105,14 +105,19 @@ class Loco_api_WordPressFileSystem {
|
|
105 |
$this->creds_out = array();
|
106 |
|
107 |
// observe settings held temporarily in session
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
$this->
|
113 |
-
|
|
|
|
|
114 |
}
|
115 |
}
|
|
|
|
|
|
|
116 |
|
117 |
$post = Loco_mvc_PostParams::get();
|
118 |
$dflt = array( 'hostname' => '', 'username' => '', 'password' => '', 'public_key' => '', 'private_key' => '', 'connection_type' => '');
|
@@ -203,15 +208,23 @@ class Loco_api_WordPressFileSystem {
|
|
203 |
|
204 |
/**
|
205 |
* Set current credentials in session if settings allow
|
206 |
-
* @return
|
207 |
*/
|
208 |
private function persistCredentials(){
|
209 |
-
|
210 |
-
|
211 |
-
$
|
212 |
-
|
213 |
-
|
|
|
|
|
|
|
214 |
}
|
|
|
|
|
|
|
|
|
|
|
215 |
}
|
216 |
|
217 |
|
105 |
$this->creds_out = array();
|
106 |
|
107 |
// observe settings held temporarily in session
|
108 |
+
try {
|
109 |
+
$session = Loco_data_Session::get();
|
110 |
+
if( isset($session['loco-fs']) ){
|
111 |
+
$creds = $session['loco-fs'];
|
112 |
+
if( $this->tryCredentials($creds,$file) ){
|
113 |
+
$this->creds_in = array();
|
114 |
+
return true;
|
115 |
+
}
|
116 |
}
|
117 |
}
|
118 |
+
catch( Exception $e ){
|
119 |
+
// tollerate session failure
|
120 |
+
}
|
121 |
|
122 |
$post = Loco_mvc_PostParams::get();
|
123 |
$dflt = array( 'hostname' => '', 'username' => '', 'password' => '', 'public_key' => '', 'private_key' => '', 'connection_type' => '');
|
208 |
|
209 |
/**
|
210 |
* Set current credentials in session if settings allow
|
211 |
+
* @return bool whether creds persisted
|
212 |
*/
|
213 |
private function persistCredentials(){
|
214 |
+
try {
|
215 |
+
$settings = Loco_data_Settings::get();
|
216 |
+
if( $settings['fs_persist'] ){
|
217 |
+
$session = Loco_data_Session::get();
|
218 |
+
$session['loco-fs'] = $this->creds_out;
|
219 |
+
$session->persist();
|
220 |
+
return true;
|
221 |
+
}
|
222 |
}
|
223 |
+
catch( Exception $e ){
|
224 |
+
// tollerate session failure
|
225 |
+
Loco_error_AdminNotices::debug( $e->getMessage() );
|
226 |
+
}
|
227 |
+
return false;
|
228 |
}
|
229 |
|
230 |
|
src/api/WordPressTranslations.php
CHANGED
@@ -17,6 +17,7 @@ class Loco_api_WordPressTranslations {
|
|
17 |
if( ! function_exists('wp_get_available_translations') ){
|
18 |
require_once ABSPATH.'wp-admin/includes/translation-install.php';
|
19 |
}
|
|
|
20 |
return wp_get_available_translations();
|
21 |
}
|
22 |
|
17 |
if( ! function_exists('wp_get_available_translations') ){
|
18 |
require_once ABSPATH.'wp-admin/includes/translation-install.php';
|
19 |
}
|
20 |
+
// WordPress will raise Warning if offline
|
21 |
return wp_get_available_translations();
|
22 |
}
|
23 |
|
src/data/Permissions.php
CHANGED
@@ -8,11 +8,23 @@
|
|
8 |
class Loco_data_Permissions {
|
9 |
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
/**
|
12 |
* @return array<WP_Role>
|
13 |
*/
|
14 |
public function getRoles(){
|
15 |
-
$roles = wp_roles();
|
16 |
// lazy create "translator" role
|
17 |
if( ! $roles->get_role('translator') ){
|
18 |
$roles->add_role( 'translator', 'Translator', array( 'loco_admin' => true ) );
|
@@ -67,7 +79,7 @@ class Loco_data_Permissions {
|
|
67 |
$label = _x( 'Translator', 'User role', 'loco' );
|
68 |
}
|
69 |
else {
|
70 |
-
$names = wp_roles()->role_names;
|
71 |
$label = isset($names[$id]) ? translate_user_role( $names[$id] ) : $id;
|
72 |
}
|
73 |
return $label;
|
8 |
class Loco_data_Permissions {
|
9 |
|
10 |
|
11 |
+
/**
|
12 |
+
* Polyfill for wp_roles which requires WP >= 4.3
|
13 |
+
*/
|
14 |
+
private static function wp_roles(){
|
15 |
+
global $wp_roles;
|
16 |
+
if( ! isset($wp_roles) ){
|
17 |
+
get_role('ping');
|
18 |
+
}
|
19 |
+
return $wp_roles;
|
20 |
+
}
|
21 |
+
|
22 |
+
|
23 |
/**
|
24 |
* @return array<WP_Role>
|
25 |
*/
|
26 |
public function getRoles(){
|
27 |
+
$roles = self::wp_roles();
|
28 |
// lazy create "translator" role
|
29 |
if( ! $roles->get_role('translator') ){
|
30 |
$roles->add_role( 'translator', 'Translator', array( 'loco_admin' => true ) );
|
79 |
$label = _x( 'Translator', 'User role', 'loco' );
|
80 |
}
|
81 |
else {
|
82 |
+
$names = self::wp_roles()->role_names;
|
83 |
$label = isset($names[$id]) ? translate_user_role( $names[$id] ) : $id;
|
84 |
}
|
85 |
return $label;
|
src/hooks/AdminHooks.php
CHANGED
@@ -28,6 +28,7 @@ class Loco_hooks_AdminHooks extends Loco_hooks_Hookable {
|
|
28 |
// initialize Ajax router before hook fired so we can handle output buffering
|
29 |
if( 'loco_' === substr($action,0,5) && isset($_REQUEST['route']) ){
|
30 |
new Loco_mvc_AjaxRouter;
|
|
|
31 |
}
|
32 |
}
|
33 |
// @codeCoverageIgnoreEnd
|
28 |
// initialize Ajax router before hook fired so we can handle output buffering
|
29 |
if( 'loco_' === substr($action,0,5) && isset($_REQUEST['route']) ){
|
30 |
new Loco_mvc_AjaxRouter;
|
31 |
+
Loco_package_Listener::create();
|
32 |
}
|
33 |
}
|
34 |
// @codeCoverageIgnoreEnd
|
src/mvc/AdminRouter.php
CHANGED
@@ -116,7 +116,7 @@ class Loco_mvc_AdminRouter extends Loco_hooks_Hookable {
|
|
116 |
Loco_error_AdminNotices::success( $message );
|
117 |
}
|
118 |
}
|
119 |
-
catch(
|
120 |
Loco_error_AdminNotices::debug( $e->getMessage() );
|
121 |
}
|
122 |
// buffer errors during controller setup
|
116 |
Loco_error_AdminNotices::success( $message );
|
117 |
}
|
118 |
}
|
119 |
+
catch( Exception $e ){
|
120 |
Loco_error_AdminNotices::debug( $e->getMessage() );
|
121 |
}
|
122 |
// buffer errors during controller setup
|
src/package/Listener.php
CHANGED
@@ -226,45 +226,45 @@ class Loco_package_Listener extends Loco_hooks_Hookable {
|
|
226 |
if( is_null($relative) ){
|
227 |
continue;
|
228 |
}
|
229 |
-
// theme
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
}
|
267 |
-
// bundle was a theme, even if we couldn't configure it
|
268 |
break 2;
|
269 |
}
|
270 |
|
226 |
if( is_null($relative) ){
|
227 |
continue;
|
228 |
}
|
229 |
+
// theme's "stylesheet directory" must be immediately under this root
|
230 |
+
// passed path could root of theme, or any directory below it, but we only need the top level
|
231 |
+
$chunks = explode( '/', $relative, 2 );
|
232 |
+
$handle = current( $chunks );
|
233 |
+
if( ! $handle ){
|
234 |
+
continue;
|
235 |
+
}
|
236 |
+
$theme = new WP_Theme( $handle, $root );
|
237 |
+
if( ! $theme->exists() ){
|
238 |
+
continue;
|
239 |
+
}
|
240 |
+
$abspath = $root.'/'.$handle;
|
241 |
+
// theme may have officially declared text domain
|
242 |
+
if( $default = $theme->get('TextDomain') ){
|
243 |
+
$this->domains[$handle] = $default;
|
244 |
+
}
|
245 |
+
// else set current domain as default if not already set
|
246 |
+
else if ( ! isset($this->domains[$handle]) ){
|
247 |
+
$this->domains[$handle] = $domain;
|
248 |
+
}
|
249 |
+
if( ! isset($this->domainPaths[$domain]) ){
|
250 |
+
$this->domainPaths[$domain] = self::relative( $path, $abspath );
|
251 |
+
}
|
252 |
+
// theme bundle may already exist
|
253 |
+
if( isset($this->themes[$handle]) ){
|
254 |
+
$bundle = $this->themes[$handle];
|
255 |
+
}
|
256 |
+
// create default project for theme bundle
|
257 |
+
else {
|
258 |
+
$bundle = Loco_package_Theme::createFromTheme($theme);
|
259 |
+
$this->themes[$handle] = $bundle;
|
260 |
+
}
|
261 |
+
// possibility that additional text domains are being added
|
262 |
+
$project = $bundle->getProject($slug);
|
263 |
+
if( ! $project ){
|
264 |
+
$project = new Loco_package_Project( $bundle, new Loco_package_TextDomain($domain), $slug );
|
265 |
+
$bundle->addProject( $project );
|
266 |
}
|
267 |
+
// bundle was a theme, even if we couldn't configure it, so no point checking plugins
|
268 |
break 2;
|
269 |
}
|
270 |
|
tpl/admin/bundle/incompat.php
CHANGED
@@ -8,7 +8,7 @@ $this->extend('../layout');
|
|
8 |
<div class="notice inline notice-error">
|
9 |
<p>
|
10 |
<strong class="has-icon"><?php esc_html_e('Unconfigured bundle','loco')?></strong><br />
|
11 |
-
<span>This bundle isn't
|
12 |
<span>Click the <a href="<?php $tabs[1]->e('href')?>">setup</a> tab for more information.</span>
|
13 |
</p>
|
14 |
</div>
|
8 |
<div class="notice inline notice-error">
|
9 |
<p>
|
10 |
<strong class="has-icon"><?php esc_html_e('Unconfigured bundle','loco')?></strong><br />
|
11 |
+
<span>This bundle isn't automatically compatible and requires configuration.</span><br />
|
12 |
<span>Click the <a href="<?php $tabs[1]->e('href')?>">setup</a> tab for more information.</span>
|
13 |
</p>
|
14 |
</div>
|
tpl/admin/config/version.php
CHANGED
@@ -37,7 +37,7 @@ $this->extend('../layout');
|
|
37 |
</h3>
|
38 |
<p>
|
39 |
If you have problems running the 2.x branch, you can revert back to the legacy version.<br />
|
40 |
-
Note that
|
41 |
</p>
|
42 |
<p class="submit">
|
43 |
<input type="submit" value="Enable legacy version" class="button" />
|
37 |
</h3>
|
38 |
<p>
|
39 |
If you have problems running the 2.x branch, you can revert back to the legacy version.<br />
|
40 |
+
Note that maintenance for the 1.x branch has stopped and there will be no further releases.
|
41 |
</p>
|
42 |
<p class="submit">
|
43 |
<input type="submit" value="Enable legacy version" class="button" />
|
tpl/admin/root.php
CHANGED
@@ -11,12 +11,8 @@ $this->extend('layout');
|
|
11 |
Welcome to the all new version 2
|
12 |
</h3>
|
13 |
<p>
|
14 |
-
|
15 |
-
|
16 |
-
</p>
|
17 |
-
<p>
|
18 |
-
If you get stuck, use the "Help" dropdown at the top of the screen or try our
|
19 |
-
<a href="<?php echo esc_url(apply_filters('loco_external','https://localise.biz/wordpress/plugin'))?>">help pages</a>.
|
20 |
</p>
|
21 |
</div><?php
|
22 |
|
11 |
Welcome to the all new version 2
|
12 |
</h3>
|
13 |
<p>
|
14 |
+
This is an early release of our completely rebuilt plugin.
|
15 |
+
You can switch to <a href="<?php $params->e('rollback')?>"> version 1</a> if you want to keep using the old plugin.
|
|
|
|
|
|
|
|
|
16 |
</p>
|
17 |
</div><?php
|
18 |
|