| @@ -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', |
| @@ -15,10 +16,12 @@ | ||
| 15 | 16 | 'parent' => 'top-secondary', |
| 16 | 17 | 'id' => 'bogo-user-locale', |
| 17 | 18 | 'title' => '✔ ' . $current_language ) ); |
| 18 | 19 | |
| 19 | - $available_languages = bogo_available_languages( | |
| 20 | - array( 'exclude' => array( $current_locale ) ) ); | |
| 20 | + $available_languages = bogo_available_languages( array( | |
| 21 | + 'exclude' => array( $current_locale ), | |
| 22 | + 'exclude_enus_if_inactive' => true, | |
| 23 | + 'current_user_can_access' => true ) ); | |
| 21 | 24 | |
| 22 | 25 | foreach ( $available_languages as $locale => $lang ) { |
| 23 | 26 | $url = admin_url( 'profile.php?action=bogo-switch-locale&locale=' . $locale ); |
| 24 | 27 | |
| @@ -57,13 +60,55 @@ | ||
| 57 | 60 | } |
| 58 | 61 | } |
| 59 | 62 | |
| 60 | 63 | function bogo_get_user_locale( $user_id = 0 ) { |
| 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 | + } | |
| 75 | + } | |
| 76 | + | |
| 61 | 77 | $locale = get_user_option( 'locale', $user_id ); |
| 62 | 78 | |
| 63 | - if ( empty( $locale ) ) | |
| 64 | - $locale = bogo_get_default_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 ) ) { | |
| 82 | + return $locale; | |
| 83 | + } | |
| 65 | 84 | |
| 66 | - return $locale; | |
| 85 | + if ( user_can( $user_id, 'bogo_access_locale', $default_locale ) ) { | |
| 86 | + return $default_locale; | |
| 87 | + } | |
| 88 | + | |
| 89 | + $available_locales = bogo_available_locales( array( | |
| 90 | + 'exclude_enus_if_inactive' => true ) ); | |
| 91 | + | |
| 92 | + foreach ( $available_locales as $locale ) { | |
| 93 | + if ( user_can( $user_id, 'bogo_access_locale', $locale ) ) { | |
| 94 | + return $locale; | |
| 95 | + } | |
| 96 | + } | |
| 97 | + | |
| 98 | + return $default_locale; | |
| 67 | 99 | } |
| 68 | 100 | |
| 69 | -?> | |
| 101 | +function bogo_get_user_accessible_locales( $user_id ) { | |
| 102 | + global $wpdb; | |
| 103 | + | |
| 104 | + $user_id = absint( $user_id ); | |
| 105 | + $meta_key = $wpdb->get_blog_prefix() . 'accessible_locale'; | |
| 106 | + | |
| 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; | |
| 114 | +} | |