| @@ -3,229 +3,98 @@ | ||
| 3 | 3 | require_once BOGO_PLUGIN_DIR . '/admin/includes/user.php'; |
| 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 | -require_once BOGO_PLUGIN_DIR . '/admin/includes/language-packs.php'; | |
| 8 | -require_once BOGO_PLUGIN_DIR . '/admin/includes/terms-translation.php'; | |
| 9 | 7 | |
| 10 | -add_action( 'admin_init', 'bogo_upgrade', 10, 0 ); | |
| 8 | +add_action( 'admin_enqueue_scripts', 'bogo_admin_enqueue_scripts' ); | |
| 11 | 9 | |
| 12 | -function bogo_upgrade() { | |
| 13 | - $old_ver = bogo_get_prop( 'version' ); | |
| 14 | - $new_ver = BOGO_VERSION; | |
| 15 | - | |
| 16 | - if ( $old_ver !== $new_ver ) { | |
| 17 | - require_once BOGO_PLUGIN_DIR . '/admin/includes/upgrade.php'; | |
| 18 | - do_action( 'bogo_upgrade', $new_ver, $old_ver ); | |
| 19 | - bogo_set_prop( 'version', $new_ver ); | |
| 20 | - } | |
| 21 | -} | |
| 22 | - | |
| 23 | -add_action( 'admin_enqueue_scripts', 'bogo_admin_enqueue_scripts', 10, 1 ); | |
| 24 | - | |
| 25 | 10 | function bogo_admin_enqueue_scripts( $hook_suffix ) { |
| 26 | - wp_enqueue_style( 'bogo-admin', | |
| 27 | - plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ), | |
| 28 | - array(), BOGO_VERSION, 'all' | |
| 29 | - ); | |
| 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' ); | |
| 30 | 17 | |
| 31 | - if ( is_rtl() ) { | |
| 32 | - wp_enqueue_style( 'bogo-admin-rtl', | |
| 33 | - plugins_url( 'admin/includes/css/admin-rtl.css', BOGO_PLUGIN_BASENAME ), | |
| 34 | - array(), BOGO_VERSION, 'all' | |
| 35 | - ); | |
| 18 | + return; | |
| 36 | 19 | } |
| 37 | 20 | |
| 38 | - $assets = include BOGO_PLUGIN_DIR . '/admin/includes/js/index.asset.php'; | |
| 21 | + if ( 'nav-menus.php' == $hook_suffix ) { | |
| 22 | + $nav_menu_id = absint( get_user_option( 'nav_menu_recently_edited' ) ); | |
| 23 | + $nav_menu_items = wp_get_nav_menu_items( $nav_menu_id ); | |
| 24 | + $locales = array(); | |
| 39 | 25 | |
| 40 | - wp_enqueue_script( 'bogo-admin', | |
| 41 | - plugins_url( 'admin/includes/js/index.js', BOGO_PLUGIN_BASENAME ), | |
| 42 | - $assets['dependencies'], | |
| 43 | - $assets['version'], | |
| 44 | - array( 'in_footer' => true ) | |
| 45 | - ); | |
| 26 | + foreach ( (array) $nav_menu_items as $item ) { | |
| 27 | + $locales[$item->db_id] = $item->bogo_locales; | |
| 28 | + } | |
| 46 | 29 | |
| 47 | - wp_set_script_translations( 'bogo-admin', 'bogo' ); | |
| 30 | + $prefix = 'menu-item-bogo-locale'; | |
| 48 | 31 | |
| 49 | - $available_languages = array(); | |
| 32 | + wp_enqueue_script( 'bogo-admin', | |
| 33 | + plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ), | |
| 34 | + array( 'jquery' ), | |
| 35 | + BOGO_VERSION, true ); | |
| 50 | 36 | |
| 51 | - foreach ( bogo_available_languages() as $locale => $language ) { | |
| 52 | - $native_name = bogo_get_language_native_name( $locale ); | |
| 37 | + wp_localize_script( 'bogo-admin', '_bogo', array( | |
| 38 | + 'availableLanguages' => bogo_available_languages( array( | |
| 39 | + 'exclude_enus_if_inactive' => true, | |
| 40 | + 'orderby' => 'value' ) ), | |
| 41 | + 'locales' => $locales, | |
| 42 | + 'selectorLegend' => __( 'Displayed on pages in', 'bogo' ), | |
| 43 | + 'cbPrefix' => $prefix ) ); | |
| 53 | 44 | |
| 54 | - if ( bogo_locale_is_alone( $locale ) ) { | |
| 55 | - $native_name = bogo_get_short_name( $native_name ); | |
| 56 | - } | |
| 45 | + wp_enqueue_style( 'bogo-admin', | |
| 46 | + plugins_url( 'admin/includes/css/admin.css', BOGO_PLUGIN_BASENAME ), | |
| 47 | + array(), BOGO_VERSION, 'all' ); | |
| 57 | 48 | |
| 58 | - $tags = array( | |
| 59 | - bogo_language_tag( $locale ), | |
| 60 | - bogo_lang_slug( $locale ), | |
| 61 | - ); | |
| 62 | - | |
| 63 | - $available_languages[$locale] = array( | |
| 64 | - 'name' => $language, | |
| 65 | - 'nativename' => trim( $native_name ), | |
| 66 | - 'country' => bogo_get_country_code( $locale ), | |
| 67 | - 'tags' => array_unique( array_filter( $tags ) ), | |
| 68 | - ); | |
| 49 | + return; | |
| 69 | 50 | } |
| 70 | 51 | |
| 71 | - $bogo_obj = array( | |
| 72 | - 'availableLanguages' => $available_languages, | |
| 73 | - 'defaultLocale' => bogo_get_default_locale(), | |
| 74 | - 'currentPost' => array(), | |
| 75 | - 'localizablePostTypes' => bogo_localizable_post_types(), | |
| 76 | - 'showFlags' => apply_filters( 'bogo_use_flags', true ), | |
| 77 | - ); | |
| 52 | + if ( 'options-general.php' == $hook_suffix ) { | |
| 53 | + wp_enqueue_script( 'bogo-admin', | |
| 54 | + plugins_url( 'admin/includes/js/admin.js', BOGO_PLUGIN_BASENAME ), | |
| 55 | + array( 'jquery' ), | |
| 56 | + BOGO_VERSION, true ); | |
| 78 | 57 | |
| 79 | - if ( in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) ) ) { | |
| 80 | - if ( $screen = get_current_screen() and $screen->is_block_editor() ) { | |
| 81 | - wp_enqueue_script( 'bogo-block-editor' ); | |
| 82 | - } | |
| 58 | + wp_localize_script( 'bogo-admin', '_bogo', array( | |
| 59 | + 'defaultLocale' => bogo_get_default_locale() ) ); | |
| 83 | 60 | |
| 84 | - $user_locale = bogo_get_user_locale(); | |
| 85 | - | |
| 86 | - $current_post = array( | |
| 87 | - 'locale' => $user_locale, | |
| 88 | - 'lang' => bogo_lang_slug( $user_locale ), | |
| 89 | - 'translations' => array(), | |
| 90 | - ); | |
| 91 | - | |
| 92 | - if ( $post = get_post() ) { | |
| 93 | - $current_post['postId'] = $post->ID; | |
| 94 | - $post_type_object = get_post_type_object( $post->post_type ); | |
| 95 | - $edit_post_cap = $post_type_object->cap->edit_post; | |
| 96 | - | |
| 97 | - if ( $locale = get_post_meta( $post->ID, '_locale', true ) ) { | |
| 98 | - $current_post['locale'] = $locale; | |
| 99 | - $current_post['lang'] = bogo_lang_slug( $locale ); | |
| 100 | - } | |
| 101 | - | |
| 102 | - $available_locales = bogo_available_locales( array( | |
| 103 | - 'exclude' => array( $current_post['locale'] ), | |
| 104 | - ) ); | |
| 105 | - | |
| 106 | - foreach ( $available_locales as $locale ) { | |
| 107 | - $current_post['translations'][$locale] = array(); | |
| 108 | - | |
| 109 | - $translation = bogo_get_post_translation( $post->ID, $locale ); | |
| 110 | - | |
| 111 | - if ( $translation ) { | |
| 112 | - $current_post['translations'][$locale] = array( | |
| 113 | - 'postId' => $translation->ID, | |
| 114 | - 'postTitle' => $translation->post_title, | |
| 115 | - 'editLink' => current_user_can( $edit_post_cap, $translation->ID ) | |
| 116 | - ? get_edit_post_link( $translation, 'raw' ) | |
| 117 | - : '', | |
| 118 | - ); | |
| 119 | - } | |
| 120 | - } | |
| 121 | - } | |
| 122 | - | |
| 123 | - $bogo_obj['currentPost'] = $current_post; | |
| 61 | + return; | |
| 124 | 62 | } |
| 125 | - | |
| 126 | - wp_add_inline_script( 'bogo-admin', | |
| 127 | - sprintf( | |
| 128 | - 'var bogo = %s;', | |
| 129 | - wp_json_encode( $bogo_obj, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE ) | |
| 130 | - ), | |
| 131 | - 'before' | |
| 132 | - ); | |
| 133 | 63 | } |
| 134 | 64 | |
| 135 | -add_action( 'admin_menu', 'bogo_admin_menu', 10, 0 ); | |
| 65 | +add_action( 'admin_menu', 'bogo_admin_menu' ); | |
| 136 | 66 | |
| 137 | 67 | function bogo_admin_menu() { |
| 138 | - add_menu_page( | |
| 139 | - __( 'Languages', 'bogo' ), | |
| 140 | - __( 'Languages', 'bogo' ), | |
| 141 | - 'bogo_manage_language_packs', | |
| 142 | - 'bogo', | |
| 143 | - 'bogo_tools_page', | |
| 144 | - 'dashicons-translation', | |
| 145 | - 73 // between Users (70) and Tools (75) | |
| 146 | - ); | |
| 68 | + $tools = add_management_page( | |
| 69 | + __( 'Bogo Tools', 'bogo' ), __( 'Bogo', 'bogo' ), | |
| 70 | + 'update_core', 'bogo-tools', 'bogo_tools_page' ); | |
| 147 | 71 | |
| 148 | - $tools = add_submenu_page( | |
| 149 | - 'bogo', | |
| 150 | - __( 'Language Packs', 'bogo' ), | |
| 151 | - __( 'Language Packs', 'bogo' ), | |
| 152 | - 'bogo_manage_language_packs', | |
| 153 | - 'bogo', | |
| 154 | - 'bogo_tools_page' | |
| 155 | - ); | |
| 156 | - | |
| 157 | - add_action( 'load-' . $tools, 'bogo_load_tools_page', 10, 0 ); | |
| 158 | - | |
| 159 | - $available_locales = bogo_available_locales( array( | |
| 160 | - 'current_user_can_access' => true, | |
| 161 | - 'exclude' => array( bogo_get_default_locale() ), | |
| 162 | - ) ); | |
| 163 | - | |
| 164 | - if ( 0 < count( $available_locales ) ) { | |
| 165 | - $texts = add_submenu_page( | |
| 166 | - 'bogo', | |
| 167 | - __( 'Terms Translation', 'bogo' ), | |
| 168 | - __( 'Terms Translation', 'bogo' ), | |
| 169 | - 'bogo_edit_terms_translation', | |
| 170 | - 'bogo-texts', | |
| 171 | - 'bogo_texts_page' | |
| 172 | - ); | |
| 173 | - | |
| 174 | - add_action( 'load-' . $texts, 'bogo_load_texts_page', 10, 0 ); | |
| 175 | - } | |
| 72 | + add_action( 'load-' . $tools, 'bogo_load_tools_page' ); | |
| 176 | 73 | } |
| 177 | 74 | |
| 178 | -add_filter( | |
| 179 | - 'set_screen_option_bogo_texts_per_page', | |
| 180 | - 'bogo_set_screen_options', | |
| 181 | - 10, 3 | |
| 182 | -); | |
| 183 | - | |
| 184 | -function bogo_set_screen_options( $result, $option, $value ) { | |
| 185 | - $bogo_screens = array( | |
| 186 | - 'bogo_texts_per_page', | |
| 187 | - ); | |
| 188 | - | |
| 189 | - if ( in_array( $option, $bogo_screens ) ) { | |
| 190 | - $result = $value; | |
| 191 | - } | |
| 192 | - | |
| 193 | - return $result; | |
| 194 | -} | |
| 195 | - | |
| 196 | 75 | function bogo_load_tools_page() { |
| 197 | 76 | require_once( ABSPATH . 'wp-admin/includes/translation-install.php' ); |
| 198 | 77 | |
| 199 | - $action = $_GET['action'] ?? ''; | |
| 200 | - $locale = $_GET['locale'] ?? null; | |
| 78 | + $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; | |
| 201 | 79 | |
| 202 | - if ( 'activate' === $action ) { | |
| 80 | + if ( 'install_translation' == $action ) { | |
| 203 | 81 | check_admin_referer( 'bogo-tools' ); |
| 204 | 82 | |
| 205 | - if ( ! current_user_can( 'bogo_manage_language_packs' ) ) { | |
| 206 | - wp_die( wp_kses_data( __( 'You are not allowed to manage translations.', 'bogo' ) ) ); | |
| 83 | + if ( ! current_user_can( 'update_core' ) ) { | |
| 84 | + wp_die( __( 'You are not allowed to install translations.', 'bogo' ) ); | |
| 207 | 85 | } |
| 208 | 86 | |
| 209 | - if ( 'en_US' === $locale ) { | |
| 210 | - bogo_set_prop( 'enus_deactivated', false ); | |
| 87 | + $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null; | |
| 211 | 88 | |
| 89 | + if ( wp_download_language_pack( $locale ) ) { | |
| 212 | 90 | $redirect_to = add_query_arg( |
| 213 | - array( 'message' => 'enus_activated' ), | |
| 214 | - menu_page_url( 'bogo', false ) | |
| 215 | - ); | |
| 91 | + array( 'locale' => $locale, 'message' => 'install_success' ), | |
| 92 | + menu_page_url( 'bogo-tools', false ) ); | |
| 216 | 93 | } else { |
| 217 | - if ( wp_download_language_pack( $locale ) ) { | |
| 218 | - $redirect_to = add_query_arg( | |
| 219 | - array( 'locale' => $locale, 'message' => 'install_success' ), | |
| 220 | - menu_page_url( 'bogo', false ) | |
| 221 | - ); | |
| 222 | - } else { | |
| 223 | - $redirect_to = add_query_arg( | |
| 224 | - array( 'locale' => $locale, 'message' => 'install_failed' ), | |
| 225 | - menu_page_url( 'bogo', false ) | |
| 226 | - ); | |
| 227 | - } | |
| 94 | + $redirect_to = add_query_arg( | |
| 95 | + array( 'locale' => $locale, 'message' => 'install_failed' ), | |
| 96 | + menu_page_url( 'bogo-tools', false ) ); | |
| 228 | 97 | } |
| 229 | 98 | |
| 230 | 99 | wp_safe_redirect( $redirect_to ); |
| 231 | 100 | exit(); |
| @@ -230,34 +99,25 @@ | ||
| 230 | 99 | wp_safe_redirect( $redirect_to ); |
| 231 | 100 | exit(); |
| 232 | 101 | } |
| 233 | 102 | |
| 234 | - if ( 'deactivate' === $action ) { | |
| 103 | + if ( 'delete_translation' == $action ) { | |
| 235 | 104 | check_admin_referer( 'bogo-tools' ); |
| 236 | 105 | |
| 237 | - if ( ! current_user_can( 'bogo_manage_language_packs' ) ) { | |
| 238 | - wp_die( wp_kses_data( __( 'You are not allowed to manage translations.', 'bogo' ) ) ); | |
| 106 | + if ( ! current_user_can( 'update_core' ) ) { | |
| 107 | + wp_die( __( 'You are not allowed to delete translations.', 'bogo' ) ); | |
| 239 | 108 | } |
| 240 | 109 | |
| 241 | - if ( 'en_US' === $locale ) { | |
| 242 | - bogo_set_prop( 'enus_deactivated', true ); | |
| 110 | + $locale = isset( $_GET['locale'] ) ? $_GET['locale'] : null; | |
| 243 | 111 | |
| 112 | + if ( bogo_delete_language_pack( $locale ) ) { | |
| 244 | 113 | $redirect_to = add_query_arg( |
| 245 | - array( 'message' => 'enus_deactivated' ), | |
| 246 | - menu_page_url( 'bogo', false ) | |
| 247 | - ); | |
| 114 | + array( 'locale' => $locale, 'message' => 'delete_success' ), | |
| 115 | + menu_page_url( 'bogo-tools', false ) ); | |
| 248 | 116 | } else { |
| 249 | - if ( bogo_delete_language_pack( $locale ) ) { | |
| 250 | - $redirect_to = add_query_arg( | |
| 251 | - array( 'locale' => $locale, 'message' => 'delete_success' ), | |
| 252 | - menu_page_url( 'bogo', false ) | |
| 253 | - ); | |
| 254 | - } else { | |
| 255 | - $redirect_to = add_query_arg( | |
| 256 | - array( 'locale' => $locale, 'message' => 'delete_failed' ), | |
| 257 | - menu_page_url( 'bogo', false ) | |
| 258 | - ); | |
| 259 | - } | |
| 117 | + $redirect_to = add_query_arg( | |
| 118 | + array( 'locale' => $locale, 'message' => 'delete_failed' ), | |
| 119 | + menu_page_url( 'bogo-tools', false ) ); | |
| 260 | 120 | } |
| 261 | 121 | |
| 262 | 122 | wp_safe_redirect( $redirect_to ); |
| 263 | 123 | exit(); |
| @@ -262,254 +122,250 @@ | ||
| 262 | 122 | wp_safe_redirect( $redirect_to ); |
| 263 | 123 | exit(); |
| 264 | 124 | } |
| 265 | 125 | |
| 266 | - if ( 'promote' === $action ) { | |
| 126 | + if ( 'deactivate_enus' == $action ) { | |
| 267 | 127 | check_admin_referer( 'bogo-tools' ); |
| 268 | 128 | |
| 269 | - if ( ! current_user_can( 'bogo_manage_language_packs' ) ) { | |
| 270 | - wp_die( wp_kses_data( __( 'You are not allowed to manage translations.', 'bogo' ) ) ); | |
| 271 | - } | |
| 129 | + bogo_set_prop( 'enus_deactivated', true ); | |
| 272 | 130 | |
| 273 | - if ( 'en_US' === $locale or ! bogo_is_available_locale( $locale ) ) { | |
| 274 | - $locale = ''; | |
| 275 | - } | |
| 131 | + $redirect_to = add_query_arg( | |
| 132 | + array( 'message' => 'enus_deactivated' ), | |
| 133 | + menu_page_url( 'bogo-tools', false ) ); | |
| 276 | 134 | |
| 277 | - if ( update_option( 'WPLANG', $locale ) ) { | |
| 278 | - $redirect_to = add_query_arg( | |
| 279 | - array( 'locale' => $locale, 'message' => 'promote_success' ), | |
| 280 | - menu_page_url( 'bogo', false ) | |
| 281 | - ); | |
| 282 | - } else { | |
| 283 | - $redirect_to = add_query_arg( | |
| 284 | - array( 'locale' => $locale, 'message' => 'promote_failed' ), | |
| 285 | - menu_page_url( 'bogo', false ) | |
| 286 | - ); | |
| 287 | - } | |
| 288 | - | |
| 289 | 135 | wp_safe_redirect( $redirect_to ); |
| 290 | 136 | exit(); |
| 291 | 137 | } |
| 292 | 138 | |
| 293 | - if ( 'translate' === $action ) { | |
| 139 | + if ( 'activate_enus' == $action ) { | |
| 294 | 140 | check_admin_referer( 'bogo-tools' ); |
| 295 | 141 | |
| 296 | - if ( ! current_user_can( 'bogo_edit_terms_translation', $locale ) ) { | |
| 297 | - wp_die( wp_kses_data( __( 'You are not allowed to edit translations.', 'bogo' ) ) ); | |
| 298 | - } | |
| 142 | + bogo_set_prop( 'enus_deactivated', false ); | |
| 299 | 143 | |
| 300 | - $is_active = ( 'en_US' === $locale ) | |
| 301 | - ? ! bogo_is_enus_deactivated() | |
| 302 | - : bogo_is_available_locale( $locale ); | |
| 144 | + $redirect_to = add_query_arg( | |
| 145 | + array( 'message' => 'enus_activated' ), | |
| 146 | + menu_page_url( 'bogo-tools', false ) ); | |
| 303 | 147 | |
| 304 | - if ( ! bogo_is_default_locale( $locale ) and $is_active ) { | |
| 305 | - $redirect_to = add_query_arg( | |
| 306 | - array( 'locale' => $locale ), | |
| 307 | - menu_page_url( 'bogo-texts', false ) ); | |
| 308 | - | |
| 309 | - wp_safe_redirect( $redirect_to ); | |
| 310 | - exit(); | |
| 311 | - } | |
| 148 | + wp_safe_redirect( $redirect_to ); | |
| 149 | + exit(); | |
| 312 | 150 | } |
| 313 | - | |
| 314 | - $current_screen = get_current_screen(); | |
| 315 | - | |
| 316 | - add_filter( 'manage_' . $current_screen->id . '_columns', | |
| 317 | - array( 'Bogo_Language_Packs_List_Table', 'define_columns' ), | |
| 318 | - 10, 1 | |
| 319 | - ); | |
| 320 | 151 | } |
| 321 | 152 | |
| 322 | 153 | function bogo_tools_page() { |
| 323 | - $list_table = new Bogo_Language_Packs_List_Table(); | |
| 324 | - $list_table->prepare_items(); | |
| 154 | + $enus_deactivated = bogo_get_prop( 'enus_deactivated' ); | |
| 155 | + $can_install = wp_can_install_language_pack(); | |
| 325 | 156 | |
| 157 | + $default_locale = bogo_get_default_locale(); | |
| 158 | + $available_locales = bogo_available_locales(); | |
| 159 | + | |
| 326 | 160 | ?> |
| 327 | 161 | <div class="wrap"> |
| 328 | 162 | |
| 329 | -<h1 class="wp-heading-inline"><?php | |
| 330 | - echo esc_html( __( 'Language Packs', 'bogo' ) ); | |
| 331 | -?></h1> | |
| 163 | +<h2><?php echo esc_html( __( 'Bogo Tools', 'bogo' ) ); ?></h2> | |
| 332 | 164 | |
| 333 | -<?php | |
| 334 | - if ( ! empty( $_REQUEST['s'] ) ) { | |
| 335 | - echo sprintf( | |
| 336 | - '<span class="subtitle">%s</span>', | |
| 337 | - wp_kses_data( sprintf( | |
| 338 | - /* translators: %s: search query */ | |
| 339 | - __( 'Search results for: <strong>%s</strong>', 'bogo' ), | |
| 340 | - esc_html( $_REQUEST['s'] ) | |
| 341 | - ) ) | |
| 342 | - ); | |
| 343 | - } | |
| 344 | -?> | |
| 345 | - | |
| 346 | -<hr class="wp-header-end"> | |
| 347 | - | |
| 348 | 165 | <?php bogo_admin_notice(); ?> |
| 349 | 166 | |
| 350 | -<?php $list_table->views(); ?> | |
| 167 | +<h3 class="title"><?php echo esc_html( __( 'Available Languages', 'bogo' ) ); ?></h3> | |
| 351 | 168 | |
| 352 | -<form method="get" action="" id="bogo-language-packs"> | |
| 353 | - <input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" /> | |
| 354 | - <?php $list_table->search_box( __( 'Search Language', 'bogo' ), 'bogo-language-packs' ); ?> | |
| 355 | - <?php $list_table->display(); ?> | |
| 356 | -</form> | |
| 169 | +<table id="bogo-languages-table" class="widefat"> | |
| 170 | +<thead> | |
| 171 | + <tr><th></th><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr> | |
| 172 | +</thead> | |
| 173 | +<tfoot> | |
| 174 | + <tr><th></th><th><?php echo esc_html( __( 'Language', 'bogo' ) ); ?></th></tr> | |
| 175 | +</tfoot> | |
| 176 | +<tbody id="translations"> | |
| 177 | + <tr class="active"><th>1</th><td><p> | |
| 178 | + <strong><?php echo esc_html( bogo_get_language( $default_locale ) ); ?></strong> | |
| 179 | + [<?php echo esc_html( $default_locale ); ?>] | |
| 180 | + <div class="status"><span class="status"><?php echo esc_html( __( 'Site Default Language', 'bogo' ) ); ?></span></div> | |
| 181 | + </p></td></tr> | |
| 357 | 182 | |
| 358 | -</div> | |
| 359 | 183 | <?php |
| 360 | -} | |
| 184 | + $count = 1; | |
| 361 | 185 | |
| 362 | -function bogo_load_texts_page() { | |
| 363 | - $action = $_POST['action'] ?? ''; | |
| 186 | + foreach ( $available_locales as $locale ) { | |
| 187 | + if ( $locale == $default_locale ) { | |
| 188 | + continue; | |
| 189 | + } | |
| 364 | 190 | |
| 365 | - if ( 'save' === $action ) { | |
| 366 | - check_admin_referer( 'bogo-edit-text-translation' ); | |
| 191 | + $count += 1; | |
| 192 | + $class = 'active'; | |
| 367 | 193 | |
| 368 | - if ( ! current_user_can( 'bogo_edit_terms_translation' ) ) { | |
| 369 | - wp_die( wp_kses_data( __( 'You are not allowed to edit translations.', 'bogo' ) ) ); | |
| 194 | + if ( 'en_US' == $locale ) { | |
| 195 | + $status = $enus_deactivated | |
| 196 | + ? esc_html( __( 'Inactive', 'bogo' ) ) | |
| 197 | + : esc_html( __( 'Active', 'bogo' ) ); | |
| 198 | + } else { | |
| 199 | + $status = esc_html( __( 'Installed', 'bogo' ) ); | |
| 370 | 200 | } |
| 371 | 201 | |
| 372 | - $locale = $_POST['locale'] ?? null; | |
| 202 | + if ( 'en_US' == $locale ) { | |
| 203 | + if ( $enus_deactivated ) { | |
| 204 | + $activate_link = menu_page_url( 'bogo-tools', false ); | |
| 205 | + $activate_link = add_query_arg( | |
| 206 | + array( 'action' => 'activate_enus' ), | |
| 207 | + $activate_link ); | |
| 208 | + $activate_link = wp_nonce_url( $activate_link, 'bogo-tools' ); | |
| 209 | + $activate_link = sprintf( | |
| 210 | + '<a href="%1$s" class="activate">%2$s</a>', | |
| 211 | + $activate_link, | |
| 212 | + esc_html( __( 'Activate', 'bogo' ) ) ); | |
| 373 | 213 | |
| 374 | - if ( ! bogo_is_available_locale( $locale ) ) { | |
| 375 | - return; | |
| 376 | - } | |
| 214 | + $status = sprintf( | |
| 215 | + '<div class="status"><span class="status">%s</span> | %s</div>', | |
| 216 | + $status, $activate_link ); | |
| 217 | + $class = ''; | |
| 218 | + } else { | |
| 219 | + $deactivate_link = menu_page_url( 'bogo-tools', false ); | |
| 220 | + $deactivate_link = add_query_arg( | |
| 221 | + array( 'action' => 'deactivate_enus' ), | |
| 222 | + $deactivate_link ); | |
| 223 | + $deactivate_link = wp_nonce_url( $deactivate_link, 'bogo-tools' ); | |
| 224 | + $deactivate_link = sprintf( | |
| 225 | + '<a href="%1$s" class="deactivate">%2$s</a>', | |
| 226 | + $deactivate_link, | |
| 227 | + esc_html( __( 'Deactivate', 'bogo' ) ) ); | |
| 377 | 228 | |
| 378 | - if ( ! current_user_can( 'bogo_access_locale', $locale ) ) { | |
| 379 | - wp_die( wp_kses_data( __( 'You are not allowed to edit terms in this locale.', 'bogo' ) ) ); | |
| 380 | - } | |
| 229 | + $status = sprintf( | |
| 230 | + '<div class="status"><span class="status">%s</span> | %s</div>', | |
| 231 | + $status, $deactivate_link ); | |
| 232 | + } | |
| 233 | + } elseif ( $can_install ) { | |
| 234 | + $delete_link = menu_page_url( 'bogo-tools', false ); | |
| 235 | + $delete_link = add_query_arg( | |
| 236 | + array( 'action' => 'delete_translation', 'locale' => $locale ), | |
| 237 | + $delete_link ); | |
| 238 | + $delete_link = wp_nonce_url( $delete_link, 'bogo-tools' ); | |
| 381 | 239 | |
| 382 | - $entries = array(); | |
| 240 | + if ( ! $delete_language = bogo_get_language( $locale ) ) { | |
| 241 | + $delete_language = $locale; | |
| 242 | + } | |
| 383 | 243 | |
| 384 | - foreach ( (array) bogo_terms_translation( $locale ) as $item ) { | |
| 385 | - $translation = $item['translated']; | |
| 244 | + $delete_confirm = sprintf( __( "You are about to delete %s language pack.\n 'Cancel' to stop, 'OK' to delete.", 'bogo' ), $delete_language ); | |
| 386 | 245 | |
| 387 | - $cap = $item['cap'] ?? 'bogo_edit_terms_translation'; | |
| 246 | + $delete_link = sprintf( '<a href="%1$s" class="delete" onclick="if (confirm(\'%3$s\')){return true;} return false;">%2$s</a>', | |
| 247 | + $delete_link, | |
| 248 | + esc_html( __( 'Delete', 'bogo' ) ), | |
| 249 | + esc_js( $delete_confirm ) ); | |
| 388 | 250 | |
| 389 | - if ( isset( $_POST[$item['name']] ) and current_user_can( $cap ) ) { | |
| 390 | - $translation = $_POST[$item['name']]; | |
| 391 | - } | |
| 392 | - | |
| 393 | - $entries[] = array( | |
| 394 | - 'singular' => $item['name'], | |
| 395 | - 'translations' => array( $translation ), | |
| 396 | - 'context' => preg_replace( '/:.*$/', '', $item['name'] ), | |
| 397 | - ); | |
| 251 | + $status = sprintf( | |
| 252 | + '<div class="status"><span class="status">%s</span> | %s</div>', | |
| 253 | + $status, $delete_link ); | |
| 398 | 254 | } |
| 255 | +?> | |
| 256 | + <tr class="<?php echo esc_attr( $class ); ?>"> | |
| 257 | + <th><?php echo $count; ?></th> | |
| 258 | + <td><p> | |
| 259 | + <strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong> | |
| 260 | + [<?php echo esc_html( $locale ); ?>] | |
| 261 | + <?php echo $status; ?> | |
| 262 | + </p> | |
| 263 | + </td> | |
| 264 | + </tr> | |
| 265 | +<?php | |
| 266 | + } | |
| 399 | 267 | |
| 400 | - if ( Bogo_POMO::export( $locale, $entries ) ) { | |
| 401 | - $message = 'translation_saved'; | |
| 402 | - } else { | |
| 403 | - $message = 'translation_failed'; | |
| 268 | + foreach ( wp_get_available_translations() as $locale => $translation ) { | |
| 269 | + if ( in_array( $locale, $available_locales ) ) { | |
| 270 | + continue; | |
| 404 | 271 | } |
| 405 | 272 | |
| 406 | - $redirect_to = add_query_arg( | |
| 407 | - array( | |
| 408 | - 'locale' => $locale, | |
| 409 | - 'message' => $message, | |
| 410 | - 'paged' => absint( $_POST['paged'] ?? 1 ), | |
| 411 | - ), | |
| 412 | - menu_page_url( 'bogo-texts', false ) | |
| 413 | - ); | |
| 273 | + $count += 1; | |
| 414 | 274 | |
| 415 | - wp_safe_redirect( $redirect_to ); | |
| 416 | - exit(); | |
| 275 | + $install_link = ''; | |
| 417 | 276 | |
| 418 | - } else { | |
| 419 | - $current_screen = get_current_screen(); | |
| 420 | - | |
| 421 | - add_filter( 'manage_' . $current_screen->id . '_columns', | |
| 422 | - array( 'Bogo_Terms_Translation_List_Table', 'define_columns' ), | |
| 423 | - 10, 1 | |
| 424 | - ); | |
| 425 | - | |
| 426 | - add_screen_option( 'per_page', array( | |
| 427 | - 'default' => 20, | |
| 428 | - 'option' => 'bogo_texts_per_page', | |
| 429 | - ) ); | |
| 430 | - } | |
| 431 | -} | |
| 432 | - | |
| 433 | -function bogo_texts_page() { | |
| 434 | - $list_table = new Bogo_Terms_Translation_List_Table(); | |
| 435 | - $list_table->prepare_items(); | |
| 436 | - | |
| 277 | + if ( $can_install ) { | |
| 278 | + $install_link = menu_page_url( 'bogo-tools', false ); | |
| 279 | + $install_link = add_query_arg( | |
| 280 | + array( 'action' => 'install_translation', 'locale' => $locale ), | |
| 281 | + $install_link ); | |
| 282 | + $install_link = wp_nonce_url( $install_link, 'bogo-tools' ); | |
| 283 | + $install_link = sprintf( '<a href="%1$s" class="install">%2$s</a>', | |
| 284 | + $install_link, esc_html( __( 'Install', 'bogo' ) ) ); | |
| 285 | + } | |
| 437 | 286 | ?> |
| 438 | -<div class="wrap"> | |
| 439 | - | |
| 440 | -<h1 class="wp-heading-inline"><?php | |
| 441 | - echo esc_html( __( 'Terms Translation', 'bogo' ) ); | |
| 442 | -?></h1> | |
| 443 | - | |
| 287 | + <tr><th><?php echo $count; ?></th><td><p> | |
| 288 | + <strong><?php echo esc_html( bogo_get_language( $locale ) ); ?></strong> | |
| 289 | + [<?php echo esc_html( $locale ); ?>] | |
| 290 | + <?php echo $install_link; ?> | |
| 291 | + </p></td></tr> | |
| 444 | 292 | <?php |
| 445 | - if ( ! empty( $_REQUEST['s'] ) ) { | |
| 446 | - echo sprintf( | |
| 447 | - '<span class="subtitle">%s</span>', | |
| 448 | - wp_kses_data( sprintf( | |
| 449 | - /* translators: %s: search query */ | |
| 450 | - __( 'Search results for: <strong>%s</strong>', 'bogo' ), | |
| 451 | - esc_html( $_REQUEST['s'] ) | |
| 452 | - ) ) | |
| 453 | - ); | |
| 454 | 293 | } |
| 455 | 294 | ?> |
| 456 | 295 | |
| 457 | -<hr class="wp-header-end"> | |
| 296 | +</tbody> | |
| 297 | +</table> | |
| 458 | 298 | |
| 459 | -<?php bogo_admin_notice(); ?> | |
| 460 | - | |
| 461 | -<form action="" method="get"> | |
| 462 | -<input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ?? '' ); ?>" /> | |
| 463 | -<input type="hidden" name="locale" value="<?php echo esc_attr( $_REQUEST['locale'] ?? '' ); ?>" /> | |
| 464 | -<?php | |
| 465 | - $list_table->search_box( | |
| 466 | - __( 'Search Translation', 'bogo' ), 'bogo-terms-translation' | |
| 467 | - ); | |
| 468 | -?> | |
| 469 | -</form> | |
| 470 | - | |
| 471 | -<form action="" method="post" id="bogo-terms-translation"> | |
| 472 | -<input type="hidden" name="action" value="save" /> | |
| 473 | -<input type="hidden" name="paged" value="<?php echo absint( $_GET['paged'] ?? '' ); ?>" /> | |
| 474 | -<?php | |
| 475 | - wp_nonce_field( 'bogo-edit-text-translation' ); | |
| 476 | - $list_table->display(); | |
| 477 | -?> | |
| 478 | -</form> | |
| 479 | 299 | </div> |
| 480 | 300 | <?php |
| 481 | 301 | } |
| 482 | 302 | |
| 483 | 303 | function bogo_admin_notice( $reason = '' ) { |
| 484 | - if ( empty( $reason ) and isset( $_GET['message'] ) ) { | |
| 304 | + if ( empty( $reason ) && isset( $_GET['message'] ) ) { | |
| 485 | 305 | $reason = $_GET['message']; |
| 486 | 306 | } |
| 487 | 307 | |
| 488 | - if ( 'install_success' === $reason ) { | |
| 489 | - $message = __( 'Translation installed successfully.', 'bogo' ); | |
| 490 | - } elseif ( 'install_failed' === $reason ) { | |
| 491 | - $message = __( 'Translation install failed.', 'bogo' ); | |
| 492 | - } elseif ( 'promote_success' === $reason ) { | |
| 493 | - $message = __( 'Site language set successfully.', 'bogo' ); | |
| 494 | - } elseif ( 'promote_failed' === $reason ) { | |
| 495 | - $message = __( 'Setting site language failed.', 'bogo' ); | |
| 496 | - } elseif ( 'delete_success' === $reason ) { | |
| 497 | - $message = __( 'Translation uninstalled successfully.', 'bogo' ); | |
| 498 | - } elseif ( 'delete_failed' === $reason ) { | |
| 499 | - $message = __( 'Translation uninstall failed.', 'bogo' ); | |
| 500 | - } elseif ( 'enus_deactivated' === $reason ) { | |
| 501 | - $message = __( 'English (United States) deactivated.', 'bogo' ); | |
| 502 | - } elseif ( 'enus_activated' === $reason ) { | |
| 503 | - $message = __( 'English (United States) activated.', 'bogo' ); | |
| 504 | - } elseif ( 'translation_saved' === $reason ) { | |
| 505 | - $message = __( 'Translation saved.', 'bogo' ); | |
| 506 | - } elseif ( 'translation_failed' === $reason ) { | |
| 507 | - $message = __( 'Saving translation failed.', 'bogo' ); | |
| 308 | + if ( 'install_success' == $reason ) { | |
| 309 | + $message = __( "Translation installed successfully.", 'bogo' ); | |
| 310 | + } elseif ( 'install_failed' == $reason ) { | |
| 311 | + $message = __( "Translation install failed.", 'bogo' ); | |
| 312 | + } elseif ( 'delete_success' == $reason ) { | |
| 313 | + $message = __( "Translation uninstalled successfully.", 'bogo' ); | |
| 314 | + } elseif ( 'delete_failed' == $reason ) { | |
| 315 | + $message = __( "Translation uninstall failed.", 'bogo' ); | |
| 316 | + } elseif ( 'enus_deactivated' == $reason ) { | |
| 317 | + $message = __( "English (United States) deactivated.", 'bogo' ); | |
| 318 | + } elseif ( 'enus_activated' == $reason ) { | |
| 319 | + $message = __( "English (United States) activated.", 'bogo' ); | |
| 508 | 320 | } else { |
| 509 | 321 | return false; |
| 510 | 322 | } |
| 511 | 323 | |
| 512 | - wp_admin_notice( $message, array( | |
| 513 | - 'type' => str_ends_with( $reason, '_failed' ) ? 'error' : 'success', | |
| 514 | - ) ); | |
| 324 | + if ( 'install_failed' == $reason || 'delete_failed' == $reason ) { | |
| 325 | + echo sprintf( | |
| 326 | + '<div class="error notice notice-error is-dismissible"><p>%s</p></div>', | |
| 327 | + esc_html( $message ) ); | |
| 328 | + } else { | |
| 329 | + echo sprintf( | |
| 330 | + '<div class="updated notice notice-success is-dismissible"><p>%s</p></div>', | |
| 331 | + esc_html( $message ) ); | |
| 332 | + } | |
| 333 | +} | |
| 334 | + | |
| 335 | +function bogo_delete_language_pack( $locale ) { | |
| 336 | + if ( 'en_US' == $locale | |
| 337 | + || ! bogo_is_available_locale( $locale ) | |
| 338 | + || bogo_is_default_locale( $locale ) ) { | |
| 339 | + return false; | |
| 340 | + } | |
| 341 | + | |
| 342 | + if ( ! is_dir( WP_LANG_DIR ) || ! $files = scandir( WP_LANG_DIR ) ) { | |
| 343 | + return false; | |
| 344 | + } | |
| 345 | + | |
| 346 | + $target_files = array( | |
| 347 | + sprintf( '%s.mo', $locale ), | |
| 348 | + sprintf( '%s.po', $locale ), | |
| 349 | + sprintf( 'admin-%s.mo', $locale ), | |
| 350 | + sprintf( 'admin-%s.po', $locale ), | |
| 351 | + sprintf( 'admin-network-%s.mo', $locale ), | |
| 352 | + sprintf( 'admin-network-%s.po', $locale ), | |
| 353 | + sprintf( 'continents-cities-%s.mo', $locale ), | |
| 354 | + sprintf( 'continents-cities-%s.po', $locale ) ); | |
| 355 | + | |
| 356 | + foreach ( $files as $file ) { | |
| 357 | + if ( '.' === $file[0] || is_dir( $file ) ) { | |
| 358 | + continue; | |
| 359 | + } | |
| 360 | + | |
| 361 | + if ( in_array( $file, $target_files ) ) { | |
| 362 | + $result = @unlink( path_join( WP_LANG_DIR, $file ) ); | |
| 363 | + | |
| 364 | + if ( ! $result ) { | |
| 365 | + return false; | |
| 366 | + } | |
| 367 | + } | |
| 368 | + } | |
| 369 | + | |
| 370 | + return true; | |
| 515 | 371 | } |