| @@ -4,46 +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 | - 'saveAlert' => __( | |
| 40 | - "The changes you made will be lost if you navigate away from this page.", | |
| 41 | - 'bogo' ), | |
| 42 | - 'rest_api' => array( | |
| 43 | - 'url' => trailingslashit( rest_url( 'bogo/v1' ) ), | |
| 44 | - 'nonce' => wp_create_nonce( 'wp_rest' ) ) ); | |
| 45 | - | |
| 46 | 21 | if ( 'nav-menus.php' == $hook_suffix ) { |
| 47 | 22 | $nav_menu_id = absint( get_user_option( 'nav_menu_recently_edited' ) ); |
| 48 | 23 | $nav_menu_items = wp_get_nav_menu_items( $nav_menu_id ); |
| 49 | 24 | $locales = array(); |
| @@ -51,51 +26,37 @@ | ||
| 51 | 26 | foreach ( (array) $nav_menu_items as $item ) { |
| 52 | 27 | $locales[$item->db_id] = $item->bogo_locales; |
| 53 | 28 | } |
| 54 | 29 | |
| 55 | - $local_args = array_merge( $local_args, array( | |
| 56 | - 'availableLanguages' => bogo_available_languages( array( | |
| 57 | - 'exclude_enus_if_inactive' => true, | |
| 58 | - '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' ), | |
| 59 | 39 | 'locales' => $locales, |
| 60 | 40 | 'selectorLegend' => __( 'Displayed on pages in', 'bogo' ), |
| 61 | - 'cbPrefix' => 'menu-item-bogo-locale' ) ); | |
| 62 | - } | |
| 41 | + 'cbPrefix' => $prefix ) ); | |
| 63 | 42 | |
| 64 | - if ( 'options-general.php' == $hook_suffix ) { | |
| 65 | - $local_args = array_merge( $local_args, array( | |
| 66 | - 'defaultLocale' => bogo_get_default_locale() ) ); | |
| 67 | - } | |
| 43 | + wp_enqueue_style( 'bogo-admin', | |
| 44 | + plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ), | |
| 45 | + array(), BOGO_VERSION, 'all' ); | |
| 68 | 46 | |
| 69 | - if ( 'post.php' == $hook_suffix && ! empty( $GLOBALS['post'] ) ) { | |
| 70 | - $post = $GLOBALS['post']; | |
| 71 | - $local_args = array_merge( $local_args, array( | |
| 72 | - 'post_id' => $post->ID ) ); | |
| 47 | + return; | |
| 73 | 48 | } |
| 74 | - | |
| 75 | - wp_localize_script( 'bogo-admin', '_bogo', $local_args ); | |
| 76 | 49 | } |
| 77 | 50 | |
| 78 | 51 | add_action( 'admin_menu', 'bogo_admin_menu' ); |
| 79 | 52 | |
| 80 | 53 | function bogo_admin_menu() { |
| 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) | |
| 54 | + $tools = add_management_page( | |
| 55 | + __( 'Bogo Tools', 'bogo' ), __( 'Bogo', 'bogo' ), | |
| 56 | + 'update_core', 'bogo-tools', 'bogo_tools_page' ); | |
| 84 | 57 | |
| 85 | - $tools = add_submenu_page( 'bogo', | |
| 86 | - __( 'Installed Languages', 'bogo' ), | |
| 87 | - __( 'Installed Languages', 'bogo' ), | |
| 88 | - 'bogo_manage_language_packs', 'bogo', 'bogo_tools_page' ); | |
| 89 | - | |
| 90 | 58 | 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' ); | |
| 98 | 59 | } |
| 99 | 60 | |
| 100 | 61 | function bogo_load_tools_page() { |
| 101 | 62 | require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); |
| @@ -104,10 +65,10 @@ | ||
| 104 | 65 | |
| 105 | 66 | if ( 'install_translation' == $action ) { |
| 106 | 67 | check_admin_referer( 'bogo-tools' ); |
| 107 | 68 | |
| 108 | - if ( ! current_user_can( 'bogo_manage_language_packs' ) ) { | |
| 109 | - wp_die( __( "You are not allowed to install translations.", 'bogo' ) ); | |
| 69 | + if ( ! current_user_can( 'update_core' ) ) { | |
| 70 | + wp_die( __( 'You are not allowed to install translations.', 'bogo' ) ); | |
| 110 | 71 | } |
| 111 | 72 | |
| 112 | 73 | $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null; |
| 113 | 74 | |
| @@ -112,378 +73,104 @@ | ||
| 112 | 73 | $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null; |
| 113 | 74 | |
| 114 | 75 | if ( wp_download_language_pack( $locale ) ) { |
| 115 | 76 | $redirect_to = add_query_arg( |
| 116 | - array( 'locale' => $locale, 'message' => 'install_success' ), | |
| 117 | - menu_page_url( 'bogo', false ) ); | |
| 77 | + array( 'locale' => $locale, 'message' => 'success' ), | |
| 78 | + menu_page_url( 'bogo-tools', false ) ); | |
| 118 | 79 | } else { |
| 119 | 80 | $redirect_to = add_query_arg( |
| 120 | - array( 'locale' => $locale, 'message' => 'install_failed' ), | |
| 121 | - menu_page_url( 'bogo', false ) ); | |
| 81 | + array( 'locale' => $locale, 'message' => 'failed' ), | |
| 82 | + menu_page_url( 'bogo-tools', false ) ); | |
| 122 | 83 | } |
| 123 | 84 | |
| 124 | 85 | wp_safe_redirect( $redirect_to ); |
| 125 | 86 | exit(); |
| 126 | 87 | } |
| 127 | - | |
| 128 | - if ( 'delete_translation' == $action ) { | |
| 129 | - check_admin_referer( 'bogo-tools' ); | |
| 130 | - | |
| 131 | - if ( ! current_user_can( 'bogo_manage_language_packs' ) ) { | |
| 132 | - wp_die( __( "You are not allowed to delete translations.", 'bogo' ) ); | |
| 133 | - } | |
| 134 | - | |
| 135 | - $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null; | |
| 136 | - | |
| 137 | - if ( bogo_delete_language_pack( $locale ) ) { | |
| 138 | - $redirect_to = add_query_arg( | |
| 139 | - array( 'locale' => $locale, 'message' => 'delete_success' ), | |
| 140 | - menu_page_url( 'bogo', false ) ); | |
| 141 | - } else { | |
| 142 | - $redirect_to = add_query_arg( | |
| 143 | - array( 'locale' => $locale, 'message' => 'delete_failed' ), | |
| 144 | - menu_page_url( 'bogo', false ) ); | |
| 145 | - } | |
| 146 | - | |
| 147 | - wp_safe_redirect( $redirect_to ); | |
| 148 | - exit(); | |
| 149 | - } | |
| 150 | - | |
| 151 | - if ( 'deactivate_enus' == $action ) { | |
| 152 | - check_admin_referer( 'bogo-tools' ); | |
| 153 | - | |
| 154 | - bogo_set_prop( 'enus_deactivated', true ); | |
| 155 | - | |
| 156 | - $redirect_to = add_query_arg( | |
| 157 | - array( 'message' => 'enus_deactivated' ), | |
| 158 | - menu_page_url( 'bogo', false ) ); | |
| 159 | - | |
| 160 | - wp_safe_redirect( $redirect_to ); | |
| 161 | - exit(); | |
| 162 | - } | |
| 163 | - | |
| 164 | - if ( 'activate_enus' == $action ) { | |
| 165 | - check_admin_referer( 'bogo-tools' ); | |
| 166 | - | |
| 167 | - bogo_set_prop( 'enus_deactivated', false ); | |
| 168 | - | |
| 169 | - $redirect_to = add_query_arg( | |
| 170 | - array( 'message' => 'enus_activated' ), | |
| 171 | - menu_page_url( 'bogo', false ) ); | |
| 172 | - | |
| 173 | - wp_safe_redirect( $redirect_to ); | |
| 174 | - exit(); | |
| 175 | - } | |
| 176 | 88 | } |
| 177 | 89 | |
| 178 | -function bogo_load_texts_page() { | |
| 179 | - $action = isset( $_POST['action'] ) ? $_POST['action'] : ''; | |
| 90 | +function bogo_tools_page() { | |
| 91 | + $message = ""; | |
| 180 | 92 | |
| 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' ) ); | |
| 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' ); | |
| 186 | 98 | } |
| 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 | 99 | } |
| 218 | -} | |
| 219 | 100 | |
| 220 | -function bogo_tools_page() { | |
| 221 | - $enus_deactivated = bogo_get_prop( 'enus_deactivated' ); | |
| 222 | - $can_install = wp_can_install_language_pack(); | |
| 223 | - | |
| 224 | - $default_locale = bogo_get_default_locale(); | |
| 225 | - $available_locales = bogo_available_locales(); | |
| 226 | - | |
| 227 | 101 | ?> |
| 228 | 102 | <div class="wrap"> |
| 229 | 103 | |
| 230 | -<h1><?php echo esc_html( __( 'Available Languages', 'bogo' ) ); ?></h1> | |
| 104 | +<h2><?php echo esc_html( __( 'Bogo Tools', 'bogo' ) ); ?></h2> | |
| 231 | 105 | |
| 232 | -<?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; ?> | |
| 233 | 109 | |
| 234 | -<table id="bogo-languages-table" class="widefat"> | |
| 235 | -<thead> | |
| 236 | - <tr><th></th><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr> | |
| 237 | -</thead> | |
| 238 | -<tfoot> | |
| 239 | - <tr><th></th><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr> | |
| 240 | -</tfoot> | |
| 241 | -<tbody id="translations"> | |
| 242 | - <tr class="active"><th>1</th><td> | |
| 243 | - <strong><?php echo esc_html( bogo_get_language( $default_locale ) ); ?></strong> | |
| 244 | - [<?php echo esc_html( $default_locale ); ?>] | |
| 245 | - <div class="status"><span class="status"><?php echo esc_html( __( 'Site Default Language', 'bogo' ) ); ?></span></div> | |
| 246 | - </td></tr> | |
| 247 | - | |
| 248 | 110 | <?php |
| 249 | - $count = 1; | |
| 250 | - | |
| 251 | - foreach ( $available_locales as $locale ) { | |
| 252 | - if ( $locale == $default_locale ) { | |
| 253 | - continue; | |
| 254 | - } | |
| 255 | - | |
| 256 | - $count += 1; | |
| 257 | - $class = 'active'; | |
| 258 | - | |
| 259 | - if ( 'en_US' == $locale ) { | |
| 260 | - $status = $enus_deactivated | |
| 261 | - ? esc_html( __( 'Inactive', 'bogo' ) ) | |
| 262 | - : esc_html( __( 'Active', 'bogo' ) ); | |
| 263 | - } else { | |
| 264 | - $status = esc_html( __( 'Installed', 'bogo' ) ); | |
| 265 | - } | |
| 266 | - | |
| 267 | - if ( 'en_US' == $locale ) { | |
| 268 | - if ( $enus_deactivated ) { | |
| 269 | - $activate_link = menu_page_url( 'bogo', false ); | |
| 270 | - $activate_link = add_query_arg( | |
| 271 | - array( 'action' => 'activate_enus' ), | |
| 272 | - $activate_link ); | |
| 273 | - $activate_link = wp_nonce_url( $activate_link, 'bogo-tools' ); | |
| 274 | - $activate_link = sprintf( | |
| 275 | - '<a href="%1$s" class="activate">%2$s</a>', | |
| 276 | - $activate_link, | |
| 277 | - esc_html( __( 'Activate', 'bogo' ) ) ); | |
| 278 | - | |
| 279 | - $status = sprintf( | |
| 280 | - '<div class="status"><span class="status">%s</span> | %s</div>', | |
| 281 | - $status, $activate_link ); | |
| 282 | - $class = ''; | |
| 283 | - } else { | |
| 284 | - $deactivate_link = menu_page_url( 'bogo', false ); | |
| 285 | - $deactivate_link = add_query_arg( | |
| 286 | - array( 'action' => 'deactivate_enus' ), | |
| 287 | - $deactivate_link ); | |
| 288 | - $deactivate_link = wp_nonce_url( $deactivate_link, 'bogo-tools' ); | |
| 289 | - $deactivate_link = sprintf( | |
| 290 | - '<a href="%1$s" class="deactivate">%2$s</a>', | |
| 291 | - $deactivate_link, | |
| 292 | - esc_html( __( 'Deactivate', 'bogo' ) ) ); | |
| 293 | - | |
| 294 | - $status = sprintf( | |
| 295 | - '<div class="status"><span class="status">%s</span> | %s</div>', | |
| 296 | - $status, $deactivate_link ); | |
| 297 | - } | |
| 298 | - } elseif ( $can_install ) { | |
| 299 | - $delete_link = menu_page_url( 'bogo', false ); | |
| 300 | - $delete_link = add_query_arg( | |
| 301 | - array( 'action' => 'delete_translation', 'locale' => $locale ), | |
| 302 | - $delete_link ); | |
| 303 | - $delete_link = wp_nonce_url( $delete_link, 'bogo-tools' ); | |
| 304 | - | |
| 305 | - if ( ! $delete_language = bogo_get_language( $locale ) ) { | |
| 306 | - $delete_language = $locale; | |
| 307 | - } | |
| 308 | - | |
| 309 | - $delete_confirm = sprintf( __( "You are about to delete %s language pack.\n 'Cancel' to stop, 'OK' to delete.", 'bogo' ), $delete_language ); | |
| 310 | - | |
| 311 | - $delete_link = sprintf( '<a href="%1$s" class="delete" onclick="if (confirm(\'%3$s\')){return true;} return false;">%2$s</a>', | |
| 312 | - $delete_link, | |
| 313 | - esc_html( __( 'Delete', 'bogo' ) ), | |
| 314 | - esc_js( $delete_confirm ) ); | |
| 315 | - | |
| 316 | - $status = sprintf( | |
| 317 | - '<div class="status"><span class="status">%s</span> | %s</div>', | |
| 318 | - $status, $delete_link ); | |
| 319 | - } | |
| 111 | + bogo_toolbox_installed_translations(); | |
| 112 | + bogo_toolbox_add_translations(); | |
| 320 | 113 | ?> |
| 321 | - <tr class="<?php echo esc_attr( $class ); ?>"> | |
| 322 | - <th><?php echo $count; ?></th> | |
| 323 | - <td> | |
| 324 | - <strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong> | |
| 325 | - [<?php echo esc_html( $locale ); ?>] | |
| 326 | - <?php echo $status; ?> | |
| 327 | - </td> | |
| 328 | - </tr> | |
| 329 | -<?php | |
| 330 | - } | |
| 331 | 114 | |
| 332 | - foreach ( wp_get_available_translations() as $locale => $translation ) { | |
| 333 | - if ( in_array( $locale, $available_locales ) ) { | |
| 334 | - continue; | |
| 335 | - } | |
| 336 | - | |
| 337 | - $count += 1; | |
| 338 | - | |
| 339 | - $install_link = ''; | |
| 340 | - | |
| 341 | - if ( $can_install ) { | |
| 342 | - $install_link = menu_page_url( 'bogo', false ); | |
| 343 | - $install_link = add_query_arg( | |
| 344 | - array( 'action' => 'install_translation', 'locale' => $locale ), | |
| 345 | - $install_link ); | |
| 346 | - $install_link = wp_nonce_url( $install_link, 'bogo-tools' ); | |
| 347 | - $install_link = sprintf( '<a href="%1$s" class="install">%2$s</a>', | |
| 348 | - $install_link, esc_html( __( 'Install', 'bogo' ) ) ); | |
| 349 | - } | |
| 350 | -?> | |
| 351 | - <tr><th><?php echo $count; ?></th><td> | |
| 352 | - <strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong> | |
| 353 | - [<?php echo esc_html( $locale ); ?>] | |
| 354 | - <?php echo $install_link; ?> | |
| 355 | - </td></tr> | |
| 356 | -<?php | |
| 357 | - } | |
| 358 | -?> | |
| 359 | - | |
| 360 | -</tbody> | |
| 361 | -</table> | |
| 362 | - | |
| 363 | 115 | </div> |
| 364 | 116 | <?php |
| 365 | 117 | } |
| 366 | 118 | |
| 367 | -function bogo_texts_page() { | |
| 368 | - $locale_to_edit = isset( $_GET['locale'] ) ? $_GET['locale'] : ''; | |
| 369 | - Bogo_POMO::import( $locale_to_edit ); | |
| 119 | +function bogo_toolbox_installed_translations() { | |
| 120 | + $title = __( 'Available Languages', 'bogo' ); | |
| 370 | 121 | |
| 122 | + $default_locale = bogo_get_default_locale(); | |
| 123 | + $languages = array( $default_locale => bogo_get_language( $default_locale ) ) | |
| 124 | + + bogo_available_languages(); | |
| 371 | 125 | ?> |
| 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> | |
| 126 | +<div class="tool-box"> | |
| 127 | +<h3 class="title"><?php echo esc_html( $title ); ?></h3> | |
| 128 | +<ul id="translations"> | |
| 385 | 129 | <?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"' : '' ); | |
| 130 | + foreach ( $languages as $locale => $language ) { | |
| 131 | + echo sprintf( '<li>%s</li>', esc_html( $language ) ); | |
| 391 | 132 | } |
| 392 | 133 | ?> |
| 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> | |
| 134 | +</ul> | |
| 413 | 135 | </div> |
| 414 | 136 | <?php |
| 415 | 137 | } |
| 416 | 138 | |
| 417 | -function bogo_admin_notice( $reason = '' ) { | |
| 418 | - if ( empty( $reason ) && isset( $_GET['message'] ) ) { | |
| 419 | - $reason = $_GET['message']; | |
| 139 | +function bogo_toolbox_add_translations() { | |
| 140 | + if ( ! wp_can_install_language_pack() ) { | |
| 141 | + return; | |
| 420 | 142 | } |
| 421 | 143 | |
| 422 | - if ( 'install_success' == $reason ) { | |
| 423 | - $message = __( "Translation installed successfully.", 'bogo' ); | |
| 424 | - } elseif ( 'install_failed' == $reason ) { | |
| 425 | - $message = __( "Translation install failed.", 'bogo' ); | |
| 426 | - } elseif ( 'delete_success' == $reason ) { | |
| 427 | - $message = __( "Translation uninstalled successfully.", 'bogo' ); | |
| 428 | - } elseif ( 'delete_failed' == $reason ) { | |
| 429 | - $message = __( "Translation uninstall failed.", 'bogo' ); | |
| 430 | - } elseif ( 'enus_deactivated' == $reason ) { | |
| 431 | - $message = __( "English (United States) deactivated.", 'bogo' ); | |
| 432 | - } elseif ( 'enus_activated' == $reason ) { | |
| 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' ); | |
| 438 | - } else { | |
| 439 | - return false; | |
| 440 | - } | |
| 144 | + $title = __( 'Add Languages', 'bogo' ); | |
| 441 | 145 | |
| 442 | - if ( '_failed' == substr( $reason, -7 ) ) { | |
| 443 | - echo sprintf( | |
| 444 | - '<div class="error notice notice-error is-dismissible"><p>%s</p></div>', | |
| 445 | - esc_html( $message ) ); | |
| 446 | - } else { | |
| 447 | - echo sprintf( | |
| 448 | - '<div class="updated notice notice-success is-dismissible"><p>%s</p></div>', | |
| 449 | - esc_html( $message ) ); | |
| 450 | - } | |
| 451 | -} | |
| 146 | + $available_translations = wp_get_available_translations(); | |
| 147 | + $languages = array_diff( bogo_languages(), bogo_available_languages() ); | |
| 452 | 148 | |
| 453 | -function bogo_delete_language_pack( $locale ) { | |
| 454 | - if ( 'en_US' == $locale | |
| 455 | - || ! bogo_is_available_locale( $locale ) | |
| 456 | - || bogo_is_default_locale( $locale ) ) { | |
| 457 | - return false; | |
| 458 | - } | |
| 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] ) ) { | |
| 156 | + $install_link = menu_page_url( 'bogo-tools', false ); | |
| 157 | + $install_link = add_query_arg( | |
| 158 | + array( 'action' => 'install_translation', 'locale' => $locale ), | |
| 159 | + $install_link ); | |
| 160 | + $install_link = wp_nonce_url( $install_link, 'bogo-tools' ); | |
| 161 | + $install_link = sprintf( '<a href="%1$s" class="install">%2$s</a>', | |
| 162 | + $install_link, __( 'Install', 'bogo' ) ); | |
| 459 | 163 | |
| 460 | - if ( ! is_dir( WP_LANG_DIR ) || ! $files = scandir( WP_LANG_DIR ) ) { | |
| 461 | - return false; | |
| 462 | - } | |
| 463 | - | |
| 464 | - $target_files = array( | |
| 465 | - sprintf( '%s.mo', $locale ), | |
| 466 | - sprintf( '%s.po', $locale ), | |
| 467 | - sprintf( 'admin-%s.mo', $locale ), | |
| 468 | - sprintf( 'admin-%s.po', $locale ), | |
| 469 | - sprintf( 'admin-network-%s.mo', $locale ), | |
| 470 | - sprintf( 'admin-network-%s.po', $locale ), | |
| 471 | - sprintf( 'continents-cities-%s.mo', $locale ), | |
| 472 | - sprintf( 'continents-cities-%s.po', $locale ) ); | |
| 473 | - | |
| 474 | - foreach ( $files as $file ) { | |
| 475 | - if ( '.' === $file[0] || is_dir( $file ) ) { | |
| 476 | - continue; | |
| 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 ) ); | |
| 477 | 168 | } |
| 478 | - | |
| 479 | - if ( in_array( $file, $target_files ) ) { | |
| 480 | - $result = @unlink( path_join( WP_LANG_DIR, $file ) ); | |
| 481 | - | |
| 482 | - if ( ! $result ) { | |
| 483 | - return false; | |
| 484 | - } | |
| 485 | - } | |
| 486 | 169 | } |
| 170 | +?> | |
| 171 | +</ul> | |
| 172 | +</div> | |
| 173 | +<?php | |
| 174 | +} | |
| 487 | 175 | |
| 488 | - return true; | |
| 489 | -} | |
| 176 | +?> | |