| @@ -7,10 +7,11 @@ | ||
| 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,8 +18,9 @@ | ||
| 17 | 18 | 'title' => '✔ ' . $current_language ) ); |
| 18 | 19 | |
| 19 | 20 | $available_languages = bogo_available_languages( array( |
| 20 | 21 | 'exclude' => array( $current_locale ), |
| 22 | + 'exclude_enus_if_inactive' => true, | |
| 21 | 23 | 'current_user_can_access' => true ) ); |
| 22 | 24 | |
| 23 | 25 | foreach ( $available_languages as $locale => $lang ) { |
| 24 | 26 | $url = admin_url( 'profile.php?action=bogo-switch-locale&locale=' . $locale ); |
| @@ -58,25 +60,37 @@ | ||
| 58 | 60 | } |
| 59 | 61 | } |
| 60 | 62 | |
| 61 | 63 | function bogo_get_user_locale( $user_id = 0 ) { |
| 62 | - if ( ! $user_id = absint( $user_id ) ) { | |
| 63 | - $user_id = get_current_user_id(); | |
| 64 | + global $current_user; | |
| 65 | + | |
| 66 | + $default_locale = bogo_get_default_locale(); | |
| 67 | + $user_id = absint( $user_id ); | |
| 68 | + | |
| 69 | + if ( ! $user_id ) { | |
| 70 | + if ( function_exists( 'wp_get_current_user' ) && ! empty( $current_user ) ) { | |
| 71 | + $user_id = get_current_user_id(); | |
| 72 | + } elseif ( ! $user_id = apply_filters( 'determine_current_user', false ) ) { | |
| 73 | + return $default_locale; | |
| 74 | + } | |
| 64 | 75 | } |
| 65 | 76 | |
| 66 | 77 | $locale = get_user_option( 'locale', $user_id ); |
| 67 | 78 | |
| 68 | - if ( user_can( $user_id, 'bogo_access_locale', $locale ) ) { | |
| 79 | + if ( bogo_is_available_locale( $locale ) | |
| 80 | + && ( 'en_US' != $locale || ! bogo_get_prop( 'enus_deactivated' ) ) | |
| 81 | + && user_can( $user_id, 'bogo_access_locale', $locale ) ) { | |
| 69 | 82 | return $locale; |
| 70 | 83 | } |
| 71 | 84 | |
| 72 | - $default_locale = bogo_get_default_locale(); | |
| 73 | - | |
| 74 | 85 | if ( user_can( $user_id, 'bogo_access_locale', $default_locale ) ) { |
| 75 | 86 | return $default_locale; |
| 76 | 87 | } |
| 77 | 88 | |
| 78 | - foreach ( (array) bogo_available_locales() as $locale ) { | |
| 89 | + $available_locales = bogo_available_locales( array( | |
| 90 | + 'exclude_enus_if_inactive' => true ) ); | |
| 91 | + | |
| 92 | + foreach ( $available_locales as $locale ) { | |
| 79 | 93 | if ( user_can( $user_id, 'bogo_access_locale', $locale ) ) { |
| 80 | 94 | return $locale; |
| 81 | 95 | } |
| 82 | 96 | } |
| @@ -89,8 +103,12 @@ | ||
| 89 | 103 | |
| 90 | 104 | $user_id = absint( $user_id ); |
| 91 | 105 | $meta_key = $wpdb->get_blog_prefix() . 'accessible_locale'; |
| 92 | 106 | |
| 93 | - return get_user_meta( $user_id, $meta_key ); | |
| 107 | + $locales = get_user_meta( $user_id, $meta_key ); | |
| 108 | + | |
| 109 | + if ( bogo_get_prop( 'enus_deactivated' ) ) { | |
| 110 | + $locales = array_diff( $locales, array( 'en_US' ) ); | |
| 111 | + } | |
| 112 | + | |
| 113 | + return $locales; | |
| 94 | 114 | } |
| 95 | - | |
| 96 | -?> | |