PluginProbe
Bogo / 2.4
Bogo v2.4
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 +77 -281 2.82.4 View file →
@@ -4,43 +4,21 @@
4 4 require_once BOGO_PLUGIN_DIR . '/admin/includes/post.php';
5 5 require_once BOGO_PLUGIN_DIR . '/admin/includes/nav-menu.php';
6 6 require_once BOGO_PLUGIN_DIR . '/admin/includes/widgets.php';
7 7
8 -add_action( 'admin_init', 'bogo_upgrade' );
9 -
10 -function bogo_upgrade() {
11 - $old_ver = bogo_get_prop( 'version' );
12 - $new_ver = BOGO_VERSION;
13 -
14 - if ( $old_ver != $new_ver ) {
15 - require_once BOGO_PLUGIN_DIR . '/admin/includes/upgrade.php';
16 - do_action( 'bogo_upgrade', $new_ver, $old_ver );
17 - bogo_set_prop( 'version', $new_ver );
18 - }
19 -}
20 -
21 8 add_action( 'admin_enqueue_scripts', 'bogo_admin_enqueue_scripts' );
22 9
23 10 function bogo_admin_enqueue_scripts( $hook_suffix ) {
24 - wp_enqueue_style( 'bogo-admin',
25 - plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ),
26 - array(), BOGO_VERSION, 'all' );
11 + if ( false !== strpos( $hook_suffix, 'bogo-tools' )
12 + || 'widgets.php' == $hook_suffix
13 + || 'user-edit.php' == $hook_suffix ) {
14 + wp_enqueue_style( 'bogo-admin',
15 + plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ),
16 + array(), BOGO_VERSION, 'all' );
27 17
28 - if ( is_rtl() ) {
29 - wp_enqueue_style( 'bogo-admin-rtl',
30 - plugins_url( 'admin/includes/css/admin-rtl.css', BOGO_PLUGIN_BASENAME ),
31 - array(), BOGO_VERSION, 'all' );
18 + return;
32 19 }
33 20
34 - wp_enqueue_script( 'bogo-admin',
35 - plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ),
36 - array( 'jquery' ), BOGO_VERSION, true );
37 -
38 - $local_args = array(
39 - 'rest_api' => array(
40 - 'url' => trailingslashit( rest_url( 'bogo/v1' ) ),
41 - 'nonce' => wp_create_nonce( 'wp_rest' ) ) );
42 -
43 21 if ( 'nav-menus.php' == $hook_suffix ) {
44 22 $nav_menu_id = absint( get_user_option( 'nav_menu_recently_edited' ) );
45 23 $nav_menu_items = wp_get_nav_menu_items( $nav_menu_id );
46 24 $locales = array();
@@ -48,29 +26,27 @@
48 26 foreach ( (array) $nav_menu_items as $item ) {
49 27 $locales[$item->db_id] = $item->bogo_locales;
50 28 }
51 29
52 - $local_args = array_merge( $local_args, array(
53 - 'availableLanguages' => bogo_available_languages( array(
54 - 'exclude_enus_if_inactive' => true,
55 - 'orderby' => 'value' ) ),
30 + $prefix = 'menu-item-bogo-locale';
31 +
32 + wp_enqueue_script( 'bogo-admin',
33 + plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ),
34 + array( 'jquery' ),
35 + BOGO_VERSION, true );
36 +
37 + wp_localize_script( 'bogo-admin', '_bogo', array(
38 + 'availableLanguages' => bogo_available_languages( 'orderby=value' ),
56 39 'locales' => $locales,
57 40 'selectorLegend' => __( 'Displayed on pages in', 'bogo' ),
58 - 'cbPrefix' => 'menu-item-bogo-locale' ) );
59 - }
41 + 'cbPrefix' => $prefix ) );
60 42
61 - if ( 'options-general.php' == $hook_suffix ) {
62 - $local_args = array_merge( $local_args, array(
63 - 'defaultLocale' => bogo_get_default_locale() ) );
64 - }
43 + wp_enqueue_style( 'bogo-admin',
44 + plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ),
45 + array(), BOGO_VERSION, 'all' );
65 46
66 - if ( 'post.php' == $hook_suffix && ! empty( $GLOBALS['post'] ) ) {
67 - $post = $GLOBALS['post'];
68 - $local_args = array_merge( $local_args, array(
69 - 'post_id' => $post->ID ) );
47 + return;
70 48 }
71 -
72 - wp_localize_script( 'bogo-admin', '_bogo', $local_args );
73 49 }
74 50
75 51 add_action( 'admin_menu', 'bogo_admin_menu' );
76 52
@@ -97,13 +73,13 @@
97 73 $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
98 74
99 75 if ( wp_download_language_pack( $locale ) ) {
100 76 $redirect_to = add_query_arg(
101 - array( 'locale' => $locale, 'message' => 'install_success' ),
77 + array( 'locale' => $locale, 'message' => 'success' ),
102 78 menu_page_url( 'bogo-tools', false ) );
103 79 } else {
104 80 $redirect_to = add_query_arg(
105 - array( 'locale' => $locale, 'message' => 'install_failed' ),
81 + array( 'locale' => $locale, 'message' => 'failed' ),
106 82 menu_page_url( 'bogo-tools', false ) );
107 83 }
108 84
109 85 wp_safe_redirect( $redirect_to );
@@ -108,183 +84,76 @@
108 84
109 85 wp_safe_redirect( $redirect_to );
110 86 exit();
111 87 }
88 +}
112 89
113 - if ( 'delete_translation' == $action ) {
114 - check_admin_referer( 'bogo-tools' );
90 +function bogo_tools_page() {
91 + $message = "";
115 92
116 - if ( ! current_user_can( 'update_core' ) ) {
117 - wp_die( __( 'You are not allowed to delete translations.', 'bogo' ) );
93 + if ( isset( $_GET['message'] ) ) {
94 + if ( 'success' == $_GET['message'] ) {
95 + $message = __( "Translation installed successfully.", 'bogo' );
96 + } elseif ( 'failed' == $_GET['message'] ) {
97 + $message = __( "Translation install failed.", 'bogo' );
118 98 }
119 -
120 - $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null;
121 -
122 - if ( bogo_delete_language_pack( $locale ) ) {
123 - $redirect_to = add_query_arg(
124 - array( 'locale' => $locale, 'message' => 'delete_success' ),
125 - menu_page_url( 'bogo-tools', false ) );
126 - } else {
127 - $redirect_to = add_query_arg(
128 - array( 'locale' => $locale, 'message' => 'delete_failed' ),
129 - menu_page_url( 'bogo-tools', false ) );
130 - }
131 -
132 - wp_safe_redirect( $redirect_to );
133 - exit();
134 99 }
135 100
136 - if ( 'deactivate_enus' == $action ) {
137 - check_admin_referer( 'bogo-tools' );
138 -
139 - bogo_set_prop( 'enus_deactivated', true );
140 -
141 - $redirect_to = add_query_arg(
142 - array( 'message' => 'enus_deactivated' ),
143 - menu_page_url( 'bogo-tools', false ) );
144 -
145 - wp_safe_redirect( $redirect_to );
146 - exit();
147 - }
148 -
149 - if ( 'activate_enus' == $action ) {
150 - check_admin_referer( 'bogo-tools' );
151 -
152 - bogo_set_prop( 'enus_deactivated', false );
153 -
154 - $redirect_to = add_query_arg(
155 - array( 'message' => 'enus_activated' ),
156 - menu_page_url( 'bogo-tools', false ) );
157 -
158 - wp_safe_redirect( $redirect_to );
159 - exit();
160 - }
161 -}
162 -
163 -function bogo_tools_page() {
164 - $enus_deactivated = bogo_get_prop( 'enus_deactivated' );
165 - $can_install = wp_can_install_language_pack();
166 -
167 - $default_locale = bogo_get_default_locale();
168 - $available_locales = bogo_available_locales();
169 -
170 101 ?>
171 102 <div class="wrap">
172 103
173 104 <h2><?php echo esc_html( __( 'Bogo Tools', 'bogo' ) ); ?></h2>
174 105
175 -<?php bogo_admin_notice(); ?>
106 +<?php if ( ! empty( $message ) ) : ?>
107 +<div id="message" class="updated"><p><?php echo esc_html( $message ); ?></p></div>
108 +<?php endif; ?>
176 109
177 -<h3 class="title"><?php echo esc_html( __( 'Available Languages', 'bogo' ) ); ?></h3>
110 +<?php
111 + bogo_toolbox_installed_translations();
112 + bogo_toolbox_add_translations();
113 +?>
178 114
179 -<table id="bogo-languages-table" class="widefat">
180 -<thead>
181 - <tr><th></th><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr>
182 -</thead>
183 -<tfoot>
184 - <tr><th></th><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr>
185 -</tfoot>
186 -<tbody id="translations">
187 - <tr class="active"><th>1</th><td>
188 - <strong><?php echo esc_html( bogo_get_language( $default_locale ) ); ?></strong>
189 - [<?php echo esc_html( $default_locale ); ?>]
190 - <div class="status"><span class="status"><?php echo esc_html( __( 'Site Default Language', 'bogo' ) ); ?></span></div>
191 - </td></tr>
192 -
115 +</div>
193 116 <?php
194 - $count = 1;
117 +}
195 118
196 - foreach ( $available_locales as $locale ) {
197 - if ( $locale == $default_locale ) {
198 - continue;
199 - }
119 +function bogo_toolbox_installed_translations() {
120 + $title = __( 'Available Languages', 'bogo' );
200 121
201 - $count += 1;
202 - $class = 'active';
203 -
204 - if ( 'en_US' == $locale ) {
205 - $status = $enus_deactivated
206 - ? esc_html( __( 'Inactive', 'bogo' ) )
207 - : esc_html( __( 'Active', 'bogo' ) );
208 - } else {
209 - $status = esc_html( __( 'Installed', 'bogo' ) );
210 - }
211 -
212 - if ( 'en_US' == $locale ) {
213 - if ( $enus_deactivated ) {
214 - $activate_link = menu_page_url( 'bogo-tools', false );
215 - $activate_link = add_query_arg(
216 - array( 'action' => 'activate_enus' ),
217 - $activate_link );
218 - $activate_link = wp_nonce_url( $activate_link, 'bogo-tools' );
219 - $activate_link = sprintf(
220 - '<a href="%1$s" class="activate">%2$s</a>',
221 - $activate_link,
222 - esc_html( __( 'Activate', 'bogo' ) ) );
223 -
224 - $status = sprintf(
225 - '<div class="status"><span class="status">%s</span> | %s</div>',
226 - $status, $activate_link );
227 - $class = '';
228 - } else {
229 - $deactivate_link = menu_page_url( 'bogo-tools', false );
230 - $deactivate_link = add_query_arg(
231 - array( 'action' => 'deactivate_enus' ),
232 - $deactivate_link );
233 - $deactivate_link = wp_nonce_url( $deactivate_link, 'bogo-tools' );
234 - $deactivate_link = sprintf(
235 - '<a href="%1$s" class="deactivate">%2$s</a>',
236 - $deactivate_link,
237 - esc_html( __( 'Deactivate', 'bogo' ) ) );
238 -
239 - $status = sprintf(
240 - '<div class="status"><span class="status">%s</span> | %s</div>',
241 - $status, $deactivate_link );
242 - }
243 - } elseif ( $can_install ) {
244 - $delete_link = menu_page_url( 'bogo-tools', false );
245 - $delete_link = add_query_arg(
246 - array( 'action' => 'delete_translation', 'locale' => $locale ),
247 - $delete_link );
248 - $delete_link = wp_nonce_url( $delete_link, 'bogo-tools' );
249 -
250 - if ( ! $delete_language = bogo_get_language( $locale ) ) {
251 - $delete_language = $locale;
252 - }
253 -
254 - $delete_confirm = sprintf( __( "You are about to delete %s language pack.\n 'Cancel' to stop, 'OK' to delete.", 'bogo' ), $delete_language );
255 -
256 - $delete_link = sprintf( '<a href="%1$s" class="delete" onclick="if (confirm(\'%3$s\')){return true;} return false;">%2$s</a>',
257 - $delete_link,
258 - esc_html( __( 'Delete', 'bogo' ) ),
259 - esc_js( $delete_confirm ) );
260 -
261 - $status = sprintf(
262 - '<div class="status"><span class="status">%s</span> | %s</div>',
263 - $status, $delete_link );
264 - }
122 + $default_locale = bogo_get_default_locale();
123 + $languages = array( $default_locale => bogo_get_language( $default_locale ) )
124 + + bogo_available_languages();
265 125 ?>
266 - <tr class="<?php echo esc_attr( $class ); ?>">
267 - <th><?php echo $count; ?></th>
268 - <td>
269 - <strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong>
270 - [<?php echo esc_html( $locale ); ?>]
271 - <?php echo $status; ?>
272 - </td>
273 - </tr>
126 +<div class="tool-box">
127 +<h3 class="title"><?php echo esc_html( $title ); ?></h3>
128 +<ul id="translations">
274 129 <?php
130 + foreach ( $languages as $locale => $language ) {
131 + echo sprintf( '<li>%s</li>', esc_html( $language ) );
275 132 }
133 +?>
134 +</ul>
135 +</div>
136 +<?php
137 +}
276 138
277 - foreach ( wp_get_available_translations() as $locale => $translation ) {
278 - if ( in_array( $locale, $available_locales ) ) {
279 - continue;
280 - }
139 +function bogo_toolbox_add_translations() {
140 + if ( ! wp_can_install_language_pack() ) {
141 + return;
142 + }
281 143
282 - $count += 1;
144 + $title = __( 'Add Languages', 'bogo' );
283 145
284 - $install_link = '';
146 + $available_translations = wp_get_available_translations();
147 + $languages = array_diff( bogo_languages(), bogo_available_languages() );
285 148
286 - if ( $can_install ) {
149 +?>
150 +<div class="tool-box">
151 +<h3 class="title"><?php echo esc_html( $title ); ?></h3>
152 +<ul id="translations">
153 +<?php
154 + foreach ( $languages as $locale => $language ) {
155 + if ( isset( $available_translations[$locale] ) ) {
287 156 $install_link = menu_page_url( 'bogo-tools', false );
288 157 $install_link = add_query_arg(
289 158 array( 'action' => 'install_translation', 'locale' => $locale ),
290 159 $install_link );
@@ -289,92 +158,19 @@
289 158 array( 'action' => 'install_translation', 'locale' => $locale ),
290 159 $install_link );
291 160 $install_link = wp_nonce_url( $install_link, 'bogo-tools' );
292 161 $install_link = sprintf( '<a href="%1$s" class="install">%2$s</a>',
293 - $install_link, esc_html( __( 'Install', 'bogo' ) ) );
162 + $install_link, __( 'Install', 'bogo' ) );
163 +
164 + echo sprintf( '<li>%1$s %2$s</li>',
165 + esc_html( $language ), $install_link );
166 + } else {
167 + echo sprintf( '<li>%s</li>', esc_html( $language ) );
294 168 }
295 -?>
296 - <tr><th><?php echo $count; ?></th><td>
297 - <strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong>
298 - [<?php echo esc_html( $locale ); ?>]
299 - <?php echo $install_link; ?>
300 - </td></tr>
301 -<?php
302 169 }
303 170 ?>
304 -
305 -</tbody>
306 -</table>
307 -
171 +</ul>
308 172 </div>
309 173 <?php
310 174 }
311 175
312 -function bogo_admin_notice( $reason = '' ) {
313 - if ( empty( $reason ) && isset( $_GET['message'] ) ) {
314 - $reason = $_GET['message'];
315 - }
316 -
317 - if ( 'install_success' == $reason ) {
318 - $message = __( "Translation installed successfully.", 'bogo' );
319 - } elseif ( 'install_failed' == $reason ) {
320 - $message = __( "Translation install failed.", 'bogo' );
321 - } elseif ( 'delete_success' == $reason ) {
322 - $message = __( "Translation uninstalled successfully.", 'bogo' );
323 - } elseif ( 'delete_failed' == $reason ) {
324 - $message = __( "Translation uninstall failed.", 'bogo' );
325 - } elseif ( 'enus_deactivated' == $reason ) {
326 - $message = __( "English (United States) deactivated.", 'bogo' );
327 - } elseif ( 'enus_activated' == $reason ) {
328 - $message = __( "English (United States) activated.", 'bogo' );
329 - } else {
330 - return false;
331 - }
332 -
333 - if ( 'install_failed' == $reason || 'delete_failed' == $reason ) {
334 - echo sprintf(
335 - '<div class="error notice notice-error is-dismissible"><p>%s</p></div>',
336 - esc_html( $message ) );
337 - } else {
338 - echo sprintf(
339 - '<div class="updated notice notice-success is-dismissible"><p>%s</p></div>',
340 - esc_html( $message ) );
341 - }
342 -}
343 -
344 -function bogo_delete_language_pack( $locale ) {
345 - if ( 'en_US' == $locale
346 - || ! bogo_is_available_locale( $locale )
347 - || bogo_is_default_locale( $locale ) ) {
348 - return false;
349 - }
350 -
351 - if ( ! is_dir( WP_LANG_DIR ) || ! $files = scandir( WP_LANG_DIR ) ) {
352 - return false;
353 - }
354 -
355 - $target_files = array(
356 - sprintf( '%s.mo', $locale ),
357 - sprintf( '%s.po', $locale ),
358 - sprintf( 'admin-%s.mo', $locale ),
359 - sprintf( 'admin-%s.po', $locale ),
360 - sprintf( 'admin-network-%s.mo', $locale ),
361 - sprintf( 'admin-network-%s.po', $locale ),
362 - sprintf( 'continents-cities-%s.mo', $locale ),
363 - sprintf( 'continents-cities-%s.po', $locale ) );
364 -
365 - foreach ( $files as $file ) {
366 - if ( '.' === $file[0] || is_dir( $file ) ) {
367 - continue;
368 - }
369 -
370 - if ( in_array( $file, $target_files ) ) {
371 - $result = @unlink( path_join( WP_LANG_DIR, $file ) );
372 -
373 - if ( ! $result ) {
374 - return false;
375 - }
376 - }
377 - }
378 -
379 - return true;
380 -}
176 +?>