Loco Translate - Version 2.0.1

Version Description

  • Added help link in settings page
  • Fixed opendir warnings in legacy code
  • Catching session errors during init
  • Removing meta row link when plugin not found
Download this release

Release Info

Developer timwhitlock
Plugin Icon 128x128 Loco Translate
Version 2.0.1
Comparing to
See all releases

Code changes from version 2.0.0 to 2.0.1

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.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.0';
49
  }
50
 
51
 
@@ -161,7 +161,7 @@ function loco_autoload( $name ){
161
  require $path;
162
  }
163
  else if( file_exists( $path = ABSPATH.'wp-admin/includes/class-'.strtr(strtolower($name),'_','-').'.php' ) ){
164
- require $path;
165
  }
166
  }
167
 
@@ -180,7 +180,7 @@ if( LOCO_LANG_DIR ){
180
  }
181
 
182
 
183
- // initialize hooks for main site or admin screens:
184
  if( is_admin() ){
185
  Loco_hooks_AdminHooks::init();
186
  }
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.1
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.1';
49
  }
50
 
51
 
161
  require $path;
162
  }
163
  else if( file_exists( $path = ABSPATH.'wp-admin/includes/class-'.strtr(strtolower($name),'_','-').'.php' ) ){
164
+ require_once $path;
165
  }
166
  }
167
 
180
  }
181
 
182
 
183
+ // initialize hooks for admin screens
184
  if( is_admin() ){
185
  Loco_hooks_AdminHooks::init();
186
  }
old/lib/loco-admin.php CHANGED
@@ -632,7 +632,7 @@ abstract class LocoAdmin {
632
  * @internal
633
  */
634
  public static function find_grouped( $dir, $match, array $found = array(), $recurse = false, $recursions = array() ){
635
- if( $rs = opendir($dir) ){
636
  while( $f = readdir($rs) ){
637
  if( '.' === $f{0} ){
638
  continue;
632
  * @internal
633
  */
634
  public static function find_grouped( $dir, $match, array $found = array(), $recurse = false, $recursions = array() ){
635
+ if( is_readable($dir) && is_dir($dir) && ( $rs = opendir($dir) ) ){
636
  while( $f = readdir($rs) ){
637
  if( '.' === $f{0} ){
638
  continue;
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: timwhitlock
3
  Tags: translation, translators, localization, localisation, l10n, i18n, Gettext, PO, MO, productivity
4
  Requires at least: 4.0
5
  Tested up to: 4.6
6
- Stable tag: 2.0.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -85,13 +85,19 @@ Help is provided via the [plugin support forum](https://wordpress.org/support/pl
85
 
86
  == Changelog ==
87
 
88
- = 2.0 =
 
 
 
 
 
 
89
  * First release of completely rebuilt version 2
90
 
91
 
92
  == Upgrade Notice ==
93
 
94
- = 2.0 =
95
  * All new version!
96
 
97
 
3
  Tags: translation, translators, localization, localisation, l10n, i18n, Gettext, PO, MO, productivity
4
  Requires at least: 4.0
5
  Tested up to: 4.6
6
+ Stable tag: 2.0.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
85
 
86
  == Changelog ==
87
 
88
+ = 2.0.1 =
89
+ * Added help link in settings page
90
+ * Fixed opendir warnings in legacy code
91
+ * Catching session errors during init
92
+ * Removing meta row link when plugin not found
93
+
94
+ = 2.0.0 =
95
  * First release of completely rebuilt version 2
96
 
97
 
98
  == Upgrade Notice ==
99
 
100
+ = 2.0.0 =
101
  * All new version!
102
 
103
 
src/data/Session.php CHANGED
@@ -72,8 +72,11 @@ class Loco_data_Session extends Loco_data_Serializable {
72
  * @internal
73
  */
74
  final public function __construct( array $raw = array() ){
75
- parent::__construct( array() );
76
  $this->token = wp_get_session_token();
 
 
 
 
77
  $this->manager = WP_Session_Tokens::get_instance( get_current_user_id() );
78
  // populate object from stored session data
79
  $data = $this->getRaw();
72
  * @internal
73
  */
74
  final public function __construct( array $raw = array() ){
 
75
  $this->token = wp_get_session_token();
76
+ if( ! $this->token ){
77
+ throw new Loco_error_Exception('Failed to get session token');
78
+ }
79
+ parent::__construct( array() );
80
  $this->manager = WP_Session_Tokens::get_instance( get_current_user_id() );
81
  // populate object from stored session data
82
  $data = $this->getRaw();
src/hooks/AdminHooks.php CHANGED
@@ -67,12 +67,18 @@ class Loco_hooks_AdminHooks extends Loco_hooks_Hookable {
67
  public function on_plugin_action_links( $links, $plugin = '' ){
68
  try {
69
  if( $plugin && current_user_can('loco_admin') ){
 
 
 
 
 
 
70
  $href = Loco_mvc_AdminRouter::generate('plugin-view', array( 'bundle' => $plugin) );
71
  $links[] = '<a href="'.esc_attr($href).'">'.esc_html__('Translate','loco').'</a>';
72
  }
73
  }
74
  catch( Exception $e ){
75
- // shh..
76
  }
77
  return $links;
78
  }
67
  public function on_plugin_action_links( $links, $plugin = '' ){
68
  try {
69
  if( $plugin && current_user_can('loco_admin') ){
70
+ // pre-empt failure later on if plugin is unknown
71
+ $search = Loco_package_Plugin::get_plugins();
72
+ if( ! array_key_exists($plugin,$search) ){
73
+ throw new Exception('Plugin is not registered: '.$plugin );
74
+ }
75
+ // ok to add "translate" link into meta row
76
  $href = Loco_mvc_AdminRouter::generate('plugin-view', array( 'bundle' => $plugin) );
77
  $links[] = '<a href="'.esc_attr($href).'">'.esc_html__('Translate','loco').'</a>';
78
  }
79
  }
80
  catch( Exception $e ){
81
+ // $links[] = esc_html( 'Debug: '.$e->getMessage() );
82
  }
83
  return $links;
84
  }
src/mvc/AdminController.php CHANGED
@@ -67,7 +67,20 @@ abstract class Loco_mvc_AdminController extends Loco_mvc_Controller {
67
  if( ! isset($query) ){
68
  $query = http_build_query( array( 'utm_campaign' => 'wp', 'utm_source' => 'admin', 'utm_content' => $this->get('_route') ), null, '&' );
69
  }
70
- return $url . ( strpos($url,'?') ? '&' : '?' ) . $query;
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
72
 
73
 
67
  if( ! isset($query) ){
68
  $query = http_build_query( array( 'utm_campaign' => 'wp', 'utm_source' => 'admin', 'utm_content' => $this->get('_route') ), null, '&' );
69
  }
70
+ $u = parse_url( $url );
71
+ if( isset($u['host']) && 'localise.biz' === $u['host'] ){
72
+ $url = 'https://localise.biz'.$u['path'];
73
+ if( isset($u['query']) ){
74
+ $url .= '?'. $u['query'].'&'.$query;
75
+ }
76
+ else {
77
+ $url .= '?'.$query;
78
+ }
79
+ if( isset($u['fragment']) ){
80
+ $url .= '#'.$u['fragment'];
81
+ }
82
+ }
83
+ return $url;
84
  }
85
 
86
 
src/mvc/AdminRouter.php CHANGED
@@ -110,9 +110,14 @@ class Loco_mvc_AdminRouter extends Loco_hooks_Hookable {
110
  throw new Exception( $class.' must inherit Loco_mvc_AdminController');
111
  }
112
  // transfer flash messages from session to admin notice buffer
113
- $session = Loco_data_Session::get();
114
- while( $message = $session->flash('success') ){
115
- Loco_error_AdminNotices::success( $message );
 
 
 
 
 
116
  }
117
  // buffer errors during controller setup
118
  try {
110
  throw new Exception( $class.' must inherit Loco_mvc_AdminController');
111
  }
112
  // transfer flash messages from session to admin notice buffer
113
+ try {
114
+ $session = Loco_data_Session::get();
115
+ while( $message = $session->flash('success') ){
116
+ Loco_error_AdminNotices::success( $message );
117
+ }
118
+ }
119
+ catch( Loco_error_Exception $e ){
120
+ Loco_error_AdminNotices::debug( $e->getMessage() );
121
  }
122
  // buffer errors during controller setup
123
  try {
tpl/admin/config/settings.php CHANGED
@@ -60,6 +60,9 @@ $this->extend('../layout');
60
  <?php esc_html_e('Remember in session','loco')?>
61
  </label>
62
  </p>
 
 
 
63
  </fieldset>
64
  </td>
65
  </tr>
60
  <?php esc_html_e('Remember in session','loco')?>
61
  </label>
62
  </p>
63
+ <span class="description">
64
+ <a href="<?php echo esc_url(apply_filters('loco_external','https://localise.biz/wordpress/plugin/manual/filesystem#remote'))?>" target="_blank">See security notes</a>
65
+ </span>
66
  </fieldset>
67
  </td>
68
  </tr>