PluginProbe ʕ •ᴥ•ʔ
Loco Translate / 2.1.0
Loco Translate v2.1.0
2.8.5 2.8.4 2.5.8 2.6.0 2.6.1 2.6.10 2.6.11 2.6.12 2.6.13 2.6.14 2.6.2 2.6.3 2.6.4 2.6.5 2.6.6 2.6.7 2.6.8 2.6.9 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0 2.8.1 2.8.2 2.8.3 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2 1.2.1 1.2.2 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.14 2.0.15 2.0.16 2.0.17 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7
loco-translate / loco.php
loco-translate Last commit date
languages 8 years ago lib 8 years ago pub 8 years ago src 8 years ago tpl 8 years ago loco.php 8 years ago loco.xml 8 years ago readme.txt 8 years ago
loco.php
174 lines
1 <?php
2 /*
3 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.1.0
8 Author URI: https://localise.biz/wordpress/plugin
9 Text Domain: loco-translate
10 Domain Path: /languages/
11 */
12
13 // disallow execution out of context
14 if( ! function_exists('is_admin') ){
15 return;
16 }
17
18
19 // legacy plugin should not be installed at the same time
20 if( function_exists('loco_require') ){
21 return;
22 }
23
24
25 /**
26 * Get absolute path to Loco primary plugin file
27 * @return string
28 */
29 function loco_plugin_file(){
30 return __FILE__;
31 }
32
33
34 /**
35 * Get version of this plugin
36 * @return string
37 */
38 function loco_plugin_version(){
39 return '2.1.0';
40 }
41
42
43 /**
44 * Get Loco plugin handle, used by WordPress to identify plugin as a relative path
45 * @return string
46 */
47 function loco_plugin_self(){
48 static $handle;
49 isset($handle) or $handle = plugin_basename(__FILE__);
50 return $handle;
51 }
52
53
54 /**
55 * Get absolute path to plugin root directory
56 * @return string
57 */
58 function loco_plugin_root(){
59 static $root;
60 isset($root) or $root = dirname(__FILE__);
61 return $root;
62 }
63
64
65 /**
66 * Check whether currently running in debug mode
67 * @return bool
68 */
69 function loco_debugging(){
70 return apply_filters('loco_debug', WP_DEBUG );
71 }
72
73
74 /**
75 * Whether currently processing an Ajax request
76 * @return bool
77 */
78 function loco_doing_ajax(){
79 return defined('DOING_AJAX') && DOING_AJAX;
80 }
81
82
83 /**
84 * Evaluate a constant by name
85 * @return mixed
86 */
87 function loco_constant( $name ){
88 $value = defined($name) ? constant($name) : null;
89 // constant values will only be modified in tests
90 if( defined('LOCO_TEST') && LOCO_TEST ){
91 $value = apply_filters('loco_constant', $value, $name );
92 $value = apply_filters('loco_constant_'.$name, $value );
93 }
94 return $value;
95 }
96
97
98 /**
99 * Runtime inclusion of any file under plugin root
100 * @return mixed
101 */
102 function loco_include( $relpath ){
103 $path = loco_plugin_root().'/'.$relpath;
104 if( ! file_exists($path) ){
105 throw new Loco_error_Exception('File not found: '.$path);
106 }
107 return include $path;
108 }
109
110
111 /**
112 * Require dependant library once only
113 * @return void
114 */
115 function loco_require_lib( $path ){
116 require_once loco_plugin_root().'/lib/'.$path;
117 }
118
119
120 /**
121 * Check PHP extension required by Loco and load polyfill if needed
122 * @return bool
123 */
124 function loco_check_extension( $name ){
125 static $cache = array();
126 if( ! isset($cache[$name]) ){
127 if( extension_loaded($name) ){
128 $cache[$name] = true;
129 }
130 else {
131 Loco_error_AdminNotices::warn( sprintf( __('Loco requires the "%s" PHP extension. Ask your hosting provider to install it','loco-translate'), $name ) );
132 $class = 'Loco_compat_'.ucfirst($name).'Extension.php';
133 $cache[$name] = class_exists( $class );
134 }
135 }
136 return $cache[$name];
137 }
138
139
140 /**
141 * Class autoloader for Loco classes under src directory.
142 * e.g. class "Loco_foo_FooBar" wil be found in "src/foo/FooBar.php"
143 * Also does autoload for polyfills under "src/compat" if classname < 20 chars
144 * @return void
145 */
146 function loco_autoload( $name ){
147 if( 'Loco_' === substr($name,0,5) ){
148 loco_include( 'src/'.strtr( substr($name,5), '_', '/' ).'.php' );
149 }
150 else if( ! isset($name{20}) && file_exists( $path = loco_plugin_root().'/src/compat/'.$name.'.php') ){
151 require $path;
152 }
153 }
154
155 spl_autoload_register( 'loco_autoload', false );
156
157
158 // provide safe directory for custom translations that won't be deleted during auto-updates
159 if( ! defined('LOCO_LANG_DIR') ){
160 define( 'LOCO_LANG_DIR', rtrim(loco_constant('WP_LANG_DIR'),'/').'/loco' );
161 }
162
163
164 // text domain loading helper for custom file locations. disable by setting constant empty
165 if( LOCO_LANG_DIR ){
166 new Loco_hooks_LoadHelper;
167 }
168
169
170 // initialize hooks for admin screens
171 if( is_admin() ){
172 new Loco_hooks_AdminHooks;
173 }
174