| @@ -7,22 +7,18 @@ | ||
| 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 | - } | |
| 14 | 13 | |
| 15 | 14 | $wp_admin_bar->add_menu( array( |
| 16 | 15 | 'parent' => 'top-secondary', |
| 17 | 16 | 'id' => 'bogo-user-locale', |
| 18 | - 'title' => sprintf( | |
| 19 | - '<span class="ab-icon"></span><span class="ab-label">%s</span>', | |
| 20 | - esc_html( $current_language ) ) ) ); | |
| 17 | + 'title' => '✔ ' . $current_language ) ); | |
| 21 | 18 | |
| 22 | 19 | $available_languages = bogo_available_languages( array( |
| 23 | 20 | 'exclude' => array( $current_locale ), |
| 24 | - 'exclude_enus_if_inactive' => true, | |
| 25 | 21 | 'current_user_can_access' => true ) ); |
| 26 | 22 | |
| 27 | 23 | foreach ( $available_languages as $locale => $lang ) { |
| 28 | 24 | $url = admin_url( 'profile.php?action=bogo-switch-locale&locale=' . $locale ); |
| @@ -43,21 +39,17 @@ | ||
| 43 | 39 | |
| 44 | 40 | add_action( 'admin_init', 'bogo_switch_user_locale' ); |
| 45 | 41 | |
| 46 | 42 | function bogo_switch_user_locale() { |
| 47 | - if ( empty( $_REQUEST['action'] ) | |
| 48 | - || 'bogo-switch-locale' != $_REQUEST['action'] ) { | |
| 43 | + if ( empty( $_REQUEST['action'] ) || 'bogo-switch-locale' != $_REQUEST['action'] ) | |
| 49 | 44 | return; |
| 50 | - } | |
| 51 | 45 | |
| 52 | 46 | check_admin_referer( 'bogo-switch-locale' ); |
| 53 | 47 | |
| 54 | 48 | $locale = isset( $_REQUEST['locale'] ) ? $_REQUEST['locale'] : ''; |
| 55 | 49 | |
| 56 | - if ( ! bogo_is_available_locale( $locale ) | |
| 57 | - || $locale == bogo_get_user_locale() ) { | |
| 50 | + if ( ! bogo_is_available_locale( $locale ) || $locale == bogo_get_user_locale() ) | |
| 58 | 51 | return; |
| 59 | - } | |
| 60 | 52 | |
| 61 | 53 | update_user_option( get_current_user_id(), 'locale', $locale, true ); |
| 62 | 54 | |
| 63 | 55 | if ( ! empty( $_REQUEST['redirect_to'] ) ) { |
| @@ -66,37 +58,25 @@ | ||
| 66 | 58 | } |
| 67 | 59 | } |
| 68 | 60 | |
| 69 | 61 | function bogo_get_user_locale( $user_id = 0 ) { |
| 70 | - global $current_user; | |
| 71 | - | |
| 72 | - $default_locale = bogo_get_default_locale(); | |
| 73 | - $user_id = absint( $user_id ); | |
| 74 | - | |
| 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 ) ) { | |
| 79 | - return $default_locale; | |
| 80 | - } | |
| 62 | + if ( ! $user_id = absint( $user_id ) ) { | |
| 63 | + $user_id = get_current_user_id(); | |
| 81 | 64 | } |
| 82 | 65 | |
| 83 | 66 | $locale = get_user_option( 'locale', $user_id ); |
| 84 | 67 | |
| 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 ) ) { | |
| 68 | + if ( user_can( $user_id, 'bogo_access_locale', $locale ) ) { | |
| 88 | 69 | return $locale; |
| 89 | 70 | } |
| 90 | 71 | |
| 72 | + $default_locale = bogo_get_default_locale(); | |
| 73 | + | |
| 91 | 74 | if ( user_can( $user_id, 'bogo_access_locale', $default_locale ) ) { |
| 92 | 75 | return $default_locale; |
| 93 | 76 | } |
| 94 | 77 | |
| 95 | - $available_locales = bogo_available_locales( array( | |
| 96 | - 'exclude_enus_if_inactive' => true ) ); | |
| 97 | - | |
| 98 | - foreach ( $available_locales as $locale ) { | |
| 78 | + foreach ( (array) bogo_available_locales() as $locale ) { | |
| 99 | 79 | if ( user_can( $user_id, 'bogo_access_locale', $locale ) ) { |
| 100 | 80 | return $locale; |
| 101 | 81 | } |
| 102 | 82 | } |
| @@ -109,12 +89,8 @@ | ||
| 109 | 89 | |
| 110 | 90 | $user_id = absint( $user_id ); |
| 111 | 91 | $meta_key = $wpdb->get_blog_prefix() . 'accessible_locale'; |
| 112 | 92 | |
| 113 | - $locales = get_user_meta( $user_id, $meta_key ); | |
| 93 | + return get_user_meta( $user_id, $meta_key ); | |
| 94 | +} | |
| 114 | 95 | |
| 115 | - if ( bogo_get_prop( 'enus_deactivated' ) ) { | |
| 116 | - $locales = array_diff( $locales, array( 'en_US' ) ); | |
| 117 | - } | |
| 118 | - | |
| 119 | - return $locales; | |
| 120 | -} | |
| 96 | +?> | |