| @@ -66,20 +66,17 @@ | ||
| 66 | 66 | } |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | function bogo_get_user_locale( $user_id = 0 ) { |
| 70 | + global $current_user; | |
| 71 | + | |
| 70 | 72 | $default_locale = bogo_get_default_locale(); |
| 73 | + $user_id = absint( $user_id ); | |
| 71 | 74 | |
| 72 | - if ( ! $user_id = absint( $user_id ) ) { | |
| 73 | - if ( function_exists( 'wp_get_current_user' ) ) { | |
| 74 | - $current_user = wp_get_current_user(); | |
| 75 | - | |
| 76 | - if ( ! empty( $current_user->locale ) ) { | |
| 77 | - return $current_user->locale; | |
| 78 | - } | |
| 79 | - } | |
| 80 | - | |
| 81 | - if ( ! $user_id = get_current_user_id() ) { | |
| 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 ) ) { | |
| 82 | 79 | return $default_locale; |
| 83 | 80 | } |
| 84 | 81 | } |
| 85 | 82 | |
| @@ -84,12 +81,27 @@ | ||
| 84 | 81 | } |
| 85 | 82 | |
| 86 | 83 | $locale = get_user_option( 'locale', $user_id ); |
| 87 | 84 | |
| 88 | - if ( bogo_is_available_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 ) ) { | |
| 89 | 88 | return $locale; |
| 90 | 89 | } |
| 91 | 90 | |
| 91 | + if ( user_can( $user_id, 'bogo_access_locale', $default_locale ) ) { | |
| 92 | + return $default_locale; | |
| 93 | + } | |
| 94 | + | |
| 95 | + $available_locales = bogo_available_locales( array( | |
| 96 | + 'exclude_enus_if_inactive' => true ) ); | |
| 97 | + | |
| 98 | + foreach ( $available_locales as $locale ) { | |
| 99 | + if ( user_can( $user_id, 'bogo_access_locale', $locale ) ) { | |
| 100 | + return $locale; | |
| 101 | + } | |
| 102 | + } | |
| 103 | + | |
| 92 | 104 | return $default_locale; |
| 93 | 105 | } |
| 94 | 106 | |
| 95 | 107 | function bogo_get_user_accessible_locales( $user_id ) { |
| @@ -99,9 +111,9 @@ | ||
| 99 | 111 | $meta_key = $wpdb->get_blog_prefix() . 'accessible_locale'; |
| 100 | 112 | |
| 101 | 113 | $locales = get_user_meta( $user_id, $meta_key ); |
| 102 | 114 | |
| 103 | - if ( bogo_is_enus_deactivated() ) { | |
| 115 | + if ( bogo_get_prop( 'enus_deactivated' ) ) { | |
| 104 | 116 | $locales = array_diff( $locales, array( 'en_US' ) ); |
| 105 | 117 | } |
| 106 | 118 | |
| 107 | 119 | return $locales; |