| @@ -7,18 +7,22 @@ | ||
| 7 | 7 | function bogo_admin_bar_menu( $wp_admin_bar ) { |
| 8 | 8 | $current_locale = bogo_get_user_locale(); |
| 9 | 9 | $current_language = bogo_get_language( $current_locale ); |
| 10 | 10 | |
| 11 | - if ( ! $current_language ) | |
| 11 | + if ( ! $current_language ) { | |
| 12 | 12 | $current_language = $current_locale; |
| 13 | + } | |
| 13 | 14 | |
| 14 | 15 | $wp_admin_bar->add_menu( array( |
| 15 | 16 | 'parent' => 'top-secondary', |
| 16 | 17 | 'id' => 'bogo-user-locale', |
| 17 | - 'title' => '✔ ' . $current_language ) ); | |
| 18 | + 'title' => sprintf( | |
| 19 | + '<span class="ab-icon"></span><span class="ab-label">%s</span>', | |
| 20 | + esc_html( $current_language ) ) ) ); | |
| 18 | 21 | |
| 19 | 22 | $available_languages = bogo_available_languages( array( |
| 20 | 23 | 'exclude' => array( $current_locale ), |
| 24 | + 'exclude_enus_if_inactive' => true, | |
| 21 | 25 | 'current_user_can_access' => true ) ); |
| 22 | 26 | |
| 23 | 27 | foreach ( $available_languages as $locale => $lang ) { |
| 24 | 28 | $url = admin_url( 'profile.php?action=bogo-switch-locale&locale=' . $locale ); |
| @@ -39,17 +43,21 @@ | ||
| 39 | 43 | |
| 40 | 44 | add_action( 'admin_init', 'bogo_switch_user_locale' ); |
| 41 | 45 | |
| 42 | 46 | function bogo_switch_user_locale() { |
| 43 | - if ( empty( $_REQUEST['action'] ) || 'bogo-switch-locale' != $_REQUEST['action'] ) | |
| 47 | + if ( empty( $_REQUEST['action'] ) | |
| 48 | + || 'bogo-switch-locale' != $_REQUEST['action'] ) { | |
| 44 | 49 | return; |
| 50 | + } | |
| 45 | 51 | |
| 46 | 52 | check_admin_referer( 'bogo-switch-locale' ); |
| 47 | 53 | |
| 48 | 54 | $locale = isset( $_REQUEST['locale'] ) ? $_REQUEST['locale'] : ''; |
| 49 | 55 | |
| 50 | - if ( ! bogo_is_available_locale( $locale ) || $locale == bogo_get_user_locale() ) | |
| 56 | + if ( ! bogo_is_available_locale( $locale ) | |
| 57 | + || $locale == bogo_get_user_locale() ) { | |
| 51 | 58 | return; |
| 59 | + } | |
| 52 | 60 | |
| 53 | 61 | update_user_option( get_current_user_id(), 'locale', $locale, true ); |
| 54 | 62 | |
| 55 | 63 | if ( ! empty( $_REQUEST['redirect_to'] ) ) { |
| @@ -58,25 +66,37 @@ | ||
| 58 | 66 | } |
| 59 | 67 | } |
| 60 | 68 | |
| 61 | 69 | function bogo_get_user_locale( $user_id = 0 ) { |
| 62 | - if ( ! $user_id = absint( $user_id ) ) { | |
| 63 | - $user_id = get_current_user_id(); | |
| 70 | + global $current_user; | |
| 71 | + | |
| 72 | + $default_locale = bogo_get_default_locale(); | |
| 73 | + $user_id = absint( $user_id ); | |
| 74 | + | |
| 75 | + if ( ! $user_id ) { | |
| 76 | + if ( function_exists( 'wp_get_current_user' ) && ! empty( $current_user ) ) { | |
| 77 | + $user_id = get_current_user_id(); | |
| 78 | + } elseif ( ! $user_id = apply_filters( 'determine_current_user', false ) ) { | |
| 79 | + return $default_locale; | |
| 80 | + } | |
| 64 | 81 | } |
| 65 | 82 | |
| 66 | 83 | $locale = get_user_option( 'locale', $user_id ); |
| 67 | 84 | |
| 68 | - if ( user_can( $user_id, 'bogo_access_locale', $locale ) ) { | |
| 85 | + if ( bogo_is_available_locale( $locale ) | |
| 86 | + && ( 'en_US' != $locale || ! bogo_get_prop( 'enus_deactivated' ) ) | |
| 87 | + && user_can( $user_id, 'bogo_access_locale', $locale ) ) { | |
| 69 | 88 | return $locale; |
| 70 | 89 | } |
| 71 | 90 | |
| 72 | - $default_locale = bogo_get_default_locale(); | |
| 73 | - | |
| 74 | 91 | if ( user_can( $user_id, 'bogo_access_locale', $default_locale ) ) { |
| 75 | 92 | return $default_locale; |
| 76 | 93 | } |
| 77 | 94 | |
| 78 | - foreach ( (array) bogo_available_locales() as $locale ) { | |
| 95 | + $available_locales = bogo_available_locales( array( | |
| 96 | + 'exclude_enus_if_inactive' => true ) ); | |
| 97 | + | |
| 98 | + foreach ( $available_locales as $locale ) { | |
| 79 | 99 | if ( user_can( $user_id, 'bogo_access_locale', $locale ) ) { |
| 80 | 100 | return $locale; |
| 81 | 101 | } |
| 82 | 102 | } |
| @@ -89,8 +109,12 @@ | ||
| 89 | 109 | |
| 90 | 110 | $user_id = absint( $user_id ); |
| 91 | 111 | $meta_key = $wpdb->get_blog_prefix() . 'accessible_locale'; |
| 92 | 112 | |
| 93 | - return get_user_meta( $user_id, $meta_key ); | |
| 113 | + $locales = get_user_meta( $user_id, $meta_key ); | |
| 114 | + | |
| 115 | + if ( bogo_get_prop( 'enus_deactivated' ) ) { | |
| 116 | + $locales = array_diff( $locales, array( 'en_US' ) ); | |
| 117 | + } | |
| 118 | + | |
| 119 | + return $locales; | |
| 94 | 120 | } |
| 95 | - | |
| 96 | -?> | |