| @@ -15,10 +15,11 @@ | ||
| 15 | 15 | 'parent' => 'top-secondary', |
| 16 | 16 | 'id' => 'bogo-user-locale', |
| 17 | 17 | 'title' => '✔ ' . $current_language ) ); |
| 18 | 18 | |
| 19 | - $available_languages = bogo_available_languages( | |
| 20 | - array( 'exclude' => array( $current_locale ) ) ); | |
| 19 | + $available_languages = bogo_available_languages( array( | |
| 20 | + 'exclude' => array( $current_locale ), | |
| 21 | + 'current_user_can_access' => true ) ); | |
| 21 | 22 | |
| 22 | 23 | foreach ( $available_languages as $locale => $lang ) { |
| 23 | 24 | $url = admin_url( 'profile.php?action=bogo-switch-locale&locale=' . $locale ); |
| 24 | 25 | |
| @@ -57,13 +58,39 @@ | ||
| 57 | 58 | } |
| 58 | 59 | } |
| 59 | 60 | |
| 60 | 61 | function bogo_get_user_locale( $user_id = 0 ) { |
| 62 | + if ( ! $user_id = absint( $user_id ) ) { | |
| 63 | + $user_id = get_current_user_id(); | |
| 64 | + } | |
| 65 | + | |
| 61 | 66 | $locale = get_user_option( 'locale', $user_id ); |
| 62 | 67 | |
| 63 | - if ( empty( $locale ) ) | |
| 64 | - $locale = bogo_get_default_locale(); | |
| 68 | + if ( user_can( $user_id, 'bogo_access_locale', $locale ) ) { | |
| 69 | + return $locale; | |
| 70 | + } | |
| 65 | 71 | |
| 66 | - return $locale; | |
| 72 | + $default_locale = bogo_get_default_locale(); | |
| 73 | + | |
| 74 | + if ( user_can( $user_id, 'bogo_access_locale', $default_locale ) ) { | |
| 75 | + return $default_locale; | |
| 76 | + } | |
| 77 | + | |
| 78 | + foreach ( (array) bogo_available_locales() as $locale ) { | |
| 79 | + if ( user_can( $user_id, 'bogo_access_locale', $locale ) ) { | |
| 80 | + return $locale; | |
| 81 | + } | |
| 82 | + } | |
| 83 | + | |
| 84 | + return $default_locale; | |
| 85 | +} | |
| 86 | + | |
| 87 | +function bogo_get_user_accessible_locales( $user_id ) { | |
| 88 | + global $wpdb; | |
| 89 | + | |
| 90 | + $user_id = absint( $user_id ); | |
| 91 | + $meta_key = $wpdb->get_blog_prefix() . 'accessible_locale'; | |
| 92 | + | |
| 93 | + return get_user_meta( $user_id, $meta_key ); | |
| 67 | 94 | } |
| 68 | 95 | |
| 69 | 96 | ?> |