| @@ -14,11 +14,9 @@ | ||
| 14 | 14 | |
| 15 | 15 | $wp_admin_bar->add_menu( array( |
| 16 | 16 | 'parent' => 'top-secondary', |
| 17 | 17 | 'id' => 'bogo-user-locale', |
| 18 | - 'title' => sprintf( | |
| 19 | - '<span class="ab-icon"></span><span class="ab-label">%s</span>', | |
| 20 | - esc_html( $current_language ) ) ) ); | |
| 18 | + 'title' => '✔ ' . $current_language ) ); | |
| 21 | 19 | |
| 22 | 20 | $available_languages = bogo_available_languages( array( |
| 23 | 21 | 'exclude' => array( $current_locale ), |
| 24 | 22 | 'exclude_enus_if_inactive' => true, |
| @@ -43,21 +41,17 @@ | ||
| 43 | 41 | |
| 44 | 42 | add_action( 'admin_init', 'bogo_switch_user_locale' ); |
| 45 | 43 | |
| 46 | 44 | function bogo_switch_user_locale() { |
| 47 | - if ( empty( $_REQUEST['action'] ) | |
| 48 | - || 'bogo-switch-locale' != $_REQUEST['action'] ) { | |
| 45 | + if ( empty( $_REQUEST['action'] ) || 'bogo-switch-locale' != $_REQUEST['action'] ) | |
| 49 | 46 | return; |
| 50 | - } | |
| 51 | 47 | |
| 52 | 48 | check_admin_referer( 'bogo-switch-locale' ); |
| 53 | 49 | |
| 54 | 50 | $locale = isset( $_REQUEST['locale'] ) ? $_REQUEST['locale'] : ''; |
| 55 | 51 | |
| 56 | - if ( ! bogo_is_available_locale( $locale ) | |
| 57 | - || $locale == bogo_get_user_locale() ) { | |
| 52 | + if ( ! bogo_is_available_locale( $locale ) || $locale == bogo_get_user_locale() ) | |
| 58 | 53 | return; |
| 59 | - } | |
| 60 | 54 | |
| 61 | 55 | update_user_option( get_current_user_id(), 'locale', $locale, true ); |
| 62 | 56 | |
| 63 | 57 | if ( ! empty( $_REQUEST['redirect_to'] ) ) { |
| @@ -66,20 +60,17 @@ | ||
| 66 | 60 | } |
| 67 | 61 | } |
| 68 | 62 | |
| 69 | 63 | function bogo_get_user_locale( $user_id = 0 ) { |
| 64 | + global $current_user; | |
| 65 | + | |
| 70 | 66 | $default_locale = bogo_get_default_locale(); |
| 67 | + $user_id = absint( $user_id ); | |
| 71 | 68 | |
| 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() ) { | |
| 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 ) ) { | |
| 82 | 73 | return $default_locale; |
| 83 | 74 | } |
| 84 | 75 | } |
| 85 | 76 | |
| @@ -84,12 +75,27 @@ | ||
| 84 | 75 | } |
| 85 | 76 | |
| 86 | 77 | $locale = get_user_option( 'locale', $user_id ); |
| 87 | 78 | |
| 88 | - if ( bogo_is_available_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 ) ) { | |
| 89 | 82 | return $locale; |
| 90 | 83 | } |
| 91 | 84 | |
| 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 | + | |
| 92 | 98 | return $default_locale; |
| 93 | 99 | } |
| 94 | 100 | |
| 95 | 101 | function bogo_get_user_accessible_locales( $user_id ) { |
| @@ -99,9 +105,9 @@ | ||
| 99 | 105 | $meta_key = $wpdb->get_blog_prefix() . 'accessible_locale'; |
| 100 | 106 | |
| 101 | 107 | $locales = get_user_meta( $user_id, $meta_key ); |
| 102 | 108 | |
| 103 | - if ( bogo_is_enus_deactivated() ) { | |
| 109 | + if ( bogo_get_prop( 'enus_deactivated' ) ) { | |
| 104 | 110 | $locales = array_diff( $locales, array( 'en_US' ) ); |
| 105 | 111 | } |
| 106 | 112 | |
| 107 | 113 | return $locales; |