PluginProbe
Bogo / 2.9
Bogo v2.9
3.9.3 trunk 1.0 1.1 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.8 2.8.1 2.9 3.0 3.0.1 All 52 releases
← All changes | admin/admin.php +130 -21 2.82.9 View file →
@@ -35,8 +35,11 @@
35 35 plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ),
36 36 array( 'jquery' ), BOGO_VERSION, true );
37 37
38 38 $local_args = array(
39 + 'saveAlert' => __(
40 + "The changes you made will be lost if you navigate away from this page.",
41 + 'bogo' ),
39 42 'rest_api' => array(
40 43 'url' => trailingslashit( rest_url( 'bogo/v1' ) ),
41 44 'nonce' => wp_create_nonce( 'wp_rest' ) ) );
42 45
@@ -74,13 +77,25 @@
74 77
75 78 add_action( 'admin_menu', 'bogo_admin_menu' );
76 79
77 80 function bogo_admin_menu() {
78 - $tools = add_management_page(
79 - __( 'Bogo Tools', 'bogo' ), __( 'Bogo', 'bogo' ),
80 - 'update_core', 'bogo-tools', 'bogo_tools_page' );
81 + add_menu_page( __( 'Languages', 'bogo' ), __( 'Languages', 'bogo' ),
82 + 'bogo_manage_language_packs', 'bogo', 'bogo_tools_page',
83 + 'dashicons-translation', 73 ); // between Users (70) and Tools (75)
81 84
85 + $tools = add_submenu_page( 'bogo',
86 + __( 'Installed Languages', 'bogo' ),
87 + __( 'Installed Languages', 'bogo' ),
88 + 'bogo_manage_language_packs', 'bogo', 'bogo_tools_page' );
89 +
82 90 add_action( 'load-' . $tools, 'bogo_load_tools_page' );
91 +
92 + $texts = add_submenu_page( 'bogo',
93 + __( 'Translatable Text Strings', 'bogo' ),
94 + __( 'Text Translation', 'bogo' ),
95 + 'bogo_edit_text_translation', 'bogo-texts', 'bogo_texts_page' );
96 +
97 + add_action( 'load-' . $texts, 'bogo_load_texts_page' );
83 98 }
84 99
85 100 function bogo_load_tools_page() {
86 101 require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
@@ -89,10 +104,10 @@
89 104
90 105 if ( 'install_translation' == $action ) {
91 106 check_admin_referer( 'bogo-tools' );
92 107
93 - if ( ! current_user_can( 'update_core' ) ) {
94 - wp_die( __( 'You are not allowed to install translations.', 'bogo' ) );
108 + if ( ! current_user_can( 'bogo_manage_language_packs' ) ) {
109 + wp_die( __( "You are not allowed to install translations.", 'bogo' ) );
95 110 }
96 111
97 112 $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
98 113
@@ -98,13 +113,13 @@
98 113
99 114 if ( wp_download_language_pack( $locale ) ) {
100 115 $redirect_to = add_query_arg(
101 116 array( 'locale' => $locale, 'message' => 'install_success' ),
102 - menu_page_url( 'bogo-tools', false ) );
117 + menu_page_url( 'bogo', false ) );
103 118 } else {
104 119 $redirect_to = add_query_arg(
105 120 array( 'locale' => $locale, 'message' => 'install_failed' ),
106 - menu_page_url( 'bogo-tools', false ) );
121 + menu_page_url( 'bogo', false ) );
107 122 }
108 123
109 124 wp_safe_redirect( $redirect_to );
110 125 exit();
@@ -112,10 +127,10 @@
112 127
113 128 if ( 'delete_translation' == $action ) {
114 129 check_admin_referer( 'bogo-tools' );
115 130
116 - if ( ! current_user_can( 'update_core' ) ) {
117 - wp_die( __( 'You are not allowed to delete translations.', 'bogo' ) );
131 + if ( ! current_user_can( 'bogo_manage_language_packs' ) ) {
132 + wp_die( __( "You are not allowed to delete translations.", 'bogo' ) );
118 133 }
119 134
120 135 $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
121 136
@@ -121,13 +136,13 @@
121 136
122 137 if ( bogo_delete_language_pack( $locale ) ) {
123 138 $redirect_to = add_query_arg(
124 139 array( 'locale' => $locale, 'message' => 'delete_success' ),
125 - menu_page_url( 'bogo-tools', false ) );
140 + menu_page_url( 'bogo', false ) );
126 141 } else {
127 142 $redirect_to = add_query_arg(
128 143 array( 'locale' => $locale, 'message' => 'delete_failed' ),
129 - menu_page_url( 'bogo-tools', false ) );
144 + menu_page_url( 'bogo', false ) );
130 145 }
131 146
132 147 wp_safe_redirect( $redirect_to );
133 148 exit();
@@ -139,9 +154,9 @@
139 154 bogo_set_prop( 'enus_deactivated', true );
140 155
141 156 $redirect_to = add_query_arg(
142 157 array( 'message' => 'enus_deactivated' ),
143 - menu_page_url( 'bogo-tools', false ) );
158 + menu_page_url( 'bogo', false ) );
144 159
145 160 wp_safe_redirect( $redirect_to );
146 161 exit();
147 162 }
@@ -152,9 +167,9 @@
152 167 bogo_set_prop( 'enus_deactivated', false );
153 168
154 169 $redirect_to = add_query_arg(
155 170 array( 'message' => 'enus_activated' ),
156 - menu_page_url( 'bogo-tools', false ) );
171 + menu_page_url( 'bogo', false ) );
157 172
158 173 wp_safe_redirect( $redirect_to );
159 174 exit();
160 175 }
@@ -159,8 +174,50 @@
159 174 exit();
160 175 }
161 176 }
162 177
178 +function bogo_load_texts_page() {
179 + $action = isset( $_POST['action'] ) ? $_POST['action'] : '';
180 +
181 + if ( 'save' == $action ) {
182 + check_admin_referer( 'bogo-edit-text-translation' );
183 +
184 + if ( ! current_user_can( 'bogo_edit_text_translation' ) ) {
185 + wp_die( __( "You are not allowed to edit translations.", 'bogo' ) );
186 + }
187 +
188 + $locale = isset( $_POST['locale'] ) ? $_POST['locale'] : null;
189 +
190 + $blogname =
191 + isset( $_POST['blogname'] ) ? $_POST['blogname'] : '';
192 + $blogdescription =
193 + isset( $_POST['blogdescription'] ) ? $_POST['blogdescription'] : '';
194 +
195 + $entries = array(
196 + array(
197 + 'singular' => 'blogname',
198 + 'translations' => array( $blogname ),
199 + 'context' => 'blogname' ),
200 + array(
201 + 'singular' => 'blogdescription',
202 + 'translations' => array( $blogdescription ),
203 + 'context' => 'blogdescription' ) );
204 +
205 + if ( Bogo_POMO::export( $locale, $entries ) ) {
206 + $message = 'translation_saved';
207 + } else {
208 + $message = 'translation_failed';
209 + }
210 +
211 + $redirect_to = add_query_arg(
212 + array( 'locale' => $locale, 'message' => $message ),
213 + menu_page_url( 'bogo-texts', false ) );
214 +
215 + wp_safe_redirect( $redirect_to );
216 + exit();
217 + }
218 +}
219 +
163 220 function bogo_tools_page() {
164 221 $enus_deactivated = bogo_get_prop( 'enus_deactivated' );
165 222 $can_install = wp_can_install_language_pack();
166 223
@@ -169,14 +226,12 @@
169 226
170 227 ?>
171 228 <div class="wrap">
172 229
173 -<h2><?php echo esc_html( __( 'Bogo Tools', 'bogo' ) ); ?></h2>
230 +<h1><?php echo esc_html( __( 'Available Languages', 'bogo' ) ); ?></h1>
174 231
175 232 <?php bogo_admin_notice(); ?>
176 233
177 -<h3 class="title"><?php echo esc_html( __( 'Available Languages', 'bogo' ) ); ?></h3>
178 -
179 234 <table id="bogo-languages-table" class="widefat">
180 235 <thead>
181 236 <tr><th></th><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr>
182 237 </thead>
@@ -210,9 +265,9 @@
210 265 }
211 266
212 267 if ( 'en_US' == $locale ) {
213 268 if ( $enus_deactivated ) {
214 - $activate_link = menu_page_url( 'bogo-tools', false );
269 + $activate_link = menu_page_url( 'bogo', false );
215 270 $activate_link = add_query_arg(
216 271 array( 'action' => 'activate_enus' ),
217 272 $activate_link );
218 273 $activate_link = wp_nonce_url( $activate_link, 'bogo-tools' );
@@ -225,9 +280,9 @@
225 280 '<div class="status"><span class="status">%s</span> | %s</div>',
226 281 $status, $activate_link );
227 282 $class = '';
228 283 } else {
229 - $deactivate_link = menu_page_url( 'bogo-tools', false );
284 + $deactivate_link = menu_page_url( 'bogo', false );
230 285 $deactivate_link = add_query_arg(
231 286 array( 'action' => 'deactivate_enus' ),
232 287 $deactivate_link );
233 288 $deactivate_link = wp_nonce_url( $deactivate_link, 'bogo-tools' );
@@ -240,9 +295,9 @@
240 295 '<div class="status"><span class="status">%s</span> | %s</div>',
241 296 $status, $deactivate_link );
242 297 }
243 298 } elseif ( $can_install ) {
244 - $delete_link = menu_page_url( 'bogo-tools', false );
299 + $delete_link = menu_page_url( 'bogo', false );
245 300 $delete_link = add_query_arg(
246 301 array( 'action' => 'delete_translation', 'locale' => $locale ),
247 302 $delete_link );
248 303 $delete_link = wp_nonce_url( $delete_link, 'bogo-tools' );
@@ -283,9 +338,9 @@
283 338
284 339 $install_link = '';
285 340
286 341 if ( $can_install ) {
287 - $install_link = menu_page_url( 'bogo-tools', false );
342 + $install_link = menu_page_url( 'bogo', false );
288 343 $install_link = add_query_arg(
289 344 array( 'action' => 'install_translation', 'locale' => $locale ),
290 345 $install_link );
291 346 $install_link = wp_nonce_url( $install_link, 'bogo-tools' );
@@ -308,8 +363,58 @@
308 363 </div>
309 364 <?php
310 365 }
311 366
367 +function bogo_texts_page() {
368 + $locale_to_edit = isset( $_GET['locale'] ) ? $_GET['locale'] : '';
369 + Bogo_POMO::import( $locale_to_edit );
370 +
371 +?>
372 +<div class="wrap">
373 +
374 +<h1><?php echo esc_html( __( 'Translatable Text Strings', 'bogo' ) ); ?></h1>
375 +
376 +<?php bogo_admin_notice(); ?>
377 +
378 +<form action="" method="post" id="bogo-translatable-text-strings">
379 +<input type="hidden" name="action" value="save" />
380 +<?php wp_nonce_field( 'bogo-edit-text-translation' ); ?>
381 +
382 +<p>
383 +<select name="locale" id="select-locale">
384 + <option value=""><?php echo esc_html( __( '-- Select Language to Edit --', 'bogo' ) ); ?></option>
385 +<?php
386 + foreach ( bogo_available_locales() as $locale ) {
387 + echo sprintf( '<option value="%1$s"%3$s>%2$s</option>',
388 + esc_attr( $locale ),
389 + esc_html( bogo_get_language( $locale ) ),
390 + $locale == $locale_to_edit ? ' selected="selected"' : '' );
391 + }
392 +?>
393 +</select>
394 +</p>
395 +
396 +<?php if ( bogo_is_available_locale( $locale_to_edit ) ) : ?>
397 +<table class="form-table">
398 +<tbody>
399 + <tr>
400 + <th scope="row"><label for="blogname"><?php echo esc_html( __( 'Site Title' ) ); ?></label></th>
401 + <td><input name="blogname" type="text" id="blogname" value="<?php echo esc_attr( bogo_translate( 'blogname', 'blogname', get_option( 'blogname' ) ) ); ?>" class="regular-text" /></td>
402 + </tr>
403 + <tr>
404 + <th scope="row"><label for="blogdescription"><?php echo esc_html( __( 'Tagline' ) ); ?></label></th>
405 + <td><input name="blogdescription" type="text" id="blogdescription" value="<?php echo esc_attr( bogo_translate( 'blogdescription', 'blogdescription', get_option( 'blogdescription' ) ) ); ?>" class="regular-text" /></td>
406 + </tr>
407 +</tbody>
408 +</table>
409 +
410 +<?php submit_button(); ?>
411 +<?php endif; ?>
412 +</form>
413 +</div>
414 +<?php
415 +}
416 +
312 417 function bogo_admin_notice( $reason = '' ) {
313 418 if ( empty( $reason ) && isset( $_GET['message'] ) ) {
314 419 $reason = $_GET['message'];
315 420 }
@@ -325,13 +430,17 @@
325 430 } elseif ( 'enus_deactivated' == $reason ) {
326 431 $message = __( "English (United States) deactivated.", 'bogo' );
327 432 } elseif ( 'enus_activated' == $reason ) {
328 433 $message = __( "English (United States) activated.", 'bogo' );
434 + } elseif ( 'translation_saved' == $reason ) {
435 + $message = __( "Translation saved.", 'bogo' );
436 + } elseif ( 'translation_failed' == $reason ) {
437 + $message = __( "Saving translation failed.", 'bogo' );
329 438 } else {
330 439 return false;
331 440 }
332 441
333 - if ( 'install_failed' == $reason || 'delete_failed' == $reason ) {
442 + if ( '_failed' == substr( $reason, -7 ) ) {
334 443 echo sprintf(
335 444 '<div class="error notice notice-error is-dismissible"><p>%s</p></div>',
336 445 esc_html( $message ) );
337 446 } else {