| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -add_action( 'personal_options_update', 'bogo_update_user_option', 10, 1 ); | |
| 4 | -add_action( 'edit_user_profile_update', 'bogo_update_user_option', 10, 1 ); | |
| 3 | +add_action( 'personal_options_update', 'bogo_update_user_option' ); | |
| 4 | +add_action( 'edit_user_profile_update', 'bogo_update_user_option' ); | |
| 5 | 5 | |
| 6 | 6 | function bogo_update_user_option( $user_id ) { |
| 7 | 7 | global $wpdb; |
| 8 | 8 | |
| @@ -34,28 +34,31 @@ | ||
| 34 | 34 | } |
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | +add_action( 'personal_options', 'bogo_set_locale_options' ); | |
| 38 | 39 | |
| 39 | -add_action( 'personal_options', 'bogo_set_locale_options', 10, 1 ); | |
| 40 | - | |
| 41 | 40 | function bogo_set_locale_options( $profileuser ) { |
| 42 | - if ( is_network_admin() or IS_PROFILE_PAGE ) { | |
| 41 | + if ( is_network_admin() ) { | |
| 43 | 42 | return; |
| 44 | 43 | } |
| 45 | 44 | |
| 46 | - if ( ! user_can( $profileuser, 'bogo_access_all_locales' ) ) { | |
| 45 | + if ( defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) { | |
| 46 | + bogo_select_own_locale( $profileuser ); | |
| 47 | + } elseif ( ! user_can( $profileuser, 'bogo_access_all_locales' ) ) { | |
| 47 | 48 | bogo_set_accessible_locales( $profileuser ); |
| 48 | 49 | } |
| 49 | 50 | } |
| 50 | 51 | |
| 51 | - | |
| 52 | 52 | function bogo_set_accessible_locales( $profileuser ) { |
| 53 | - $available_languages = bogo_available_languages( array( | |
| 54 | - 'orderby' => 'value', | |
| 55 | - ) ); | |
| 53 | + $available_languages = bogo_available_languages( 'orderby=value' ); | |
| 54 | + $accessible_locales = bogo_get_user_accessible_locales( $profileuser->ID ); | |
| 56 | 55 | |
| 57 | - $accessible_locales = bogo_get_user_accessible_locales( $profileuser->ID ); | |
| 56 | + if ( empty( $accessible_locales ) ) { | |
| 57 | + $accessible_locales = array_keys( $available_languages ); | |
| 58 | + } else { | |
| 59 | + $accessible_locales = bogo_filter_locales( $accessible_locales ); | |
| 60 | + } | |
| 58 | 61 | |
| 59 | 62 | ?> |
| 60 | 63 | |
| 61 | 64 | <!-- Bogo plugin --> |
| @@ -66,35 +69,46 @@ | ||
| 66 | 69 | <span class="description"><?php echo esc_html( __( 'This user is allowed to access the following locales:', 'bogo' ) ); ?></span><br /> |
| 67 | 70 | <fieldset class="bogo-locale-options"> |
| 68 | 71 | |
| 69 | 72 | <?php |
| 73 | + foreach ( $available_languages as $locale => $language ) : | |
| 74 | + $checked = in_array( $locale, $accessible_locales ); | |
| 75 | + $id_attr = 'bogo_accessible_locale-' . $locale; | |
| 76 | +?> | |
| 77 | +<label class="bogo-locale-option<?php echo $checked ? ' checked' : ''; ?>" for="<?php echo $id_attr; ?>"> | |
| 78 | +<input type="checkbox" id="<?php echo $id_attr; ?>" name="bogo_accessible_locales[]" value="<?php echo esc_attr( $locale ); ?>"<?php echo $checked ? ' checked="checked"' : ''; ?> /><?php echo esc_html( $language ); ?> | |
| 79 | +</label> | |
| 80 | +<?php | |
| 81 | + endforeach; | |
| 82 | +?> | |
| 83 | +</fieldset> | |
| 84 | +</td> | |
| 85 | +</tr> | |
| 70 | 86 | |
| 71 | - foreach ( $available_languages as $locale => $language ) { | |
| 72 | - $checked = in_array( $locale, $accessible_locales ); | |
| 73 | - $id_attr = sprintf( 'bogo_accessible_locale-%s', $locale ); | |
| 87 | +<?php | |
| 88 | +} | |
| 74 | 89 | |
| 75 | - $checkbox = sprintf( | |
| 76 | - '<label %1$s><input %2$s />%3$s</label>', | |
| 77 | - bogo_format_atts( array( | |
| 78 | - 'class' => 'bogo-locale-option' . ( $checked ? ' checked' : '' ), | |
| 79 | - 'for' => $id_attr, | |
| 80 | - ) ), | |
| 81 | - bogo_format_atts( array( | |
| 82 | - 'type' => 'checkbox', | |
| 83 | - 'id' => $id_attr, | |
| 84 | - 'name' => 'bogo_accessible_locales[]', | |
| 85 | - 'value' => $locale, | |
| 86 | - 'checked' => $checked, | |
| 87 | - ) ), | |
| 88 | - $language | |
| 89 | - ); | |
| 90 | +function bogo_select_own_locale( $profileuser ) { | |
| 91 | + $available_languages = bogo_available_languages( array( | |
| 92 | + 'orderby' => 'value', | |
| 93 | + 'current_user_can_access' => true ) ); | |
| 90 | 94 | |
| 91 | - echo wp_kses( $checkbox, 'bogo_form_inside' ) . "\n"; | |
| 92 | - } | |
| 95 | + $selected = bogo_get_user_locale( $profileuser->ID ); | |
| 93 | 96 | |
| 94 | 97 | ?> |
| 95 | -</fieldset> | |
| 98 | + | |
| 99 | +<!-- Bogo plugin --> | |
| 100 | +<tr> | |
| 101 | +<th scope="row"><?php echo esc_html( __( 'Locale', 'bogo' ) ); ?></th> | |
| 102 | +<td> | |
| 103 | +<select name="bogo_own_locale"> | |
| 104 | +<?php foreach ( $available_languages as $locale => $lang ) : ?> | |
| 105 | +<option value="<?php echo esc_attr( $locale ); ?>" <?php selected( $locale, $selected ); ?>><?php echo esc_html( $lang ); ?></option> | |
| 106 | +<?php endforeach; ?> | |
| 107 | +</select> | |
| 96 | 108 | </td> |
| 97 | 109 | </tr> |
| 98 | 110 | |
| 99 | 111 | <?php |
| 100 | 112 | } |
| 113 | + | |
| 114 | +?> | |