PluginProbe
Bogo / 2.7
Bogo v2.7
3.9.3 trunk 1.0 1.1 2.0 2.0.1 2.1 2.1.1 2.1.2 2.1.3 2.2 2.3 2.4 2.4.1 2.4.2 2.4.3 2.5 2.6 2.6.1 2.7 2.8 2.8.1 2.9 3.0 3.0.1 All 52 releases
bogo / admin / includes / user.php

user.php in Bogo 2.7, at admin/includes/user.php

116 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 add_action( 'personal_options_update', 'bogo_update_user_option' );
4 add_action( 'edit_user_profile_update', 'bogo_update_user_option' );
5
6 function bogo_update_user_option( $user_id ) {
7 global $wpdb;
8
9 $meta_key = $wpdb->get_blog_prefix() . 'accessible_locale';
10
11 if ( ! empty( $_POST['setting_bogo_accessible_locales'] ) ) {
12 delete_user_meta( $user_id, $meta_key );
13
14 if ( isset( $_POST['bogo_accessible_locales'] ) ) {
15 $locales = (array) $_POST['bogo_accessible_locales'];
16 $locales = bogo_filter_locales( $locales );
17
18 foreach ( $locales as $locale ) {
19 add_user_meta( $user_id, $meta_key, $locale );
20 }
21 }
22
23 if ( ! metadata_exists( 'user', $user_id, $meta_key ) ) {
24 add_user_meta( $user_id, $meta_key, 'zxx' );
25 // zxx is a special code in ISO 639-2
26 }
27 }
28
29 if ( isset( $_POST['bogo_own_locale'] ) ) {
30 $locale = trim( $_POST['bogo_own_locale'] );
31
32 if ( bogo_is_available_locale( $locale ) ) {
33 update_user_option( $user_id, 'locale', $locale, true );
34 }
35 }
36 }
37
38 add_action( 'personal_options', 'bogo_set_locale_options' );
39
40 function bogo_set_locale_options( $profileuser ) {
41 if ( is_network_admin() ) {
42 return;
43 }
44
45 if ( defined( 'IS_PROFILE_PAGE' ) && IS_PROFILE_PAGE ) {
46 bogo_select_own_locale( $profileuser );
47 } elseif ( ! user_can( $profileuser, 'bogo_access_all_locales' ) ) {
48 bogo_set_accessible_locales( $profileuser );
49 }
50 }
51
52 function bogo_set_accessible_locales( $profileuser ) {
53 $available_languages = bogo_available_languages( array(
54 'exclude_enus_if_inactive' => true,
55 'orderby' => 'value' ) );
56 $accessible_locales = bogo_get_user_accessible_locales( $profileuser->ID );
57
58 if ( empty( $accessible_locales ) ) {
59 $accessible_locales = array_keys( $available_languages );
60 } else {
61 $accessible_locales = bogo_filter_locales( $accessible_locales );
62 }
63
64 ?>
65
66 <!-- Bogo plugin -->
67 <tr>
68 <th scope="row"><?php echo esc_html( __( 'Locale', 'bogo' ) ); ?></th>
69 <td>
70 <input type="hidden" name="setting_bogo_accessible_locales" value="1" />
71 <span class="description"><?php echo esc_html( __( 'This user is allowed to access the following locales:', 'bogo' ) ); ?></span><br />
72 <fieldset class="bogo-locale-options">
73
74 <?php
75 foreach ( $available_languages as $locale => $language ) :
76 $checked = in_array( $locale, $accessible_locales );
77 $id_attr = 'bogo_accessible_locale-' . $locale;
78 ?>
79 <label class="bogo-locale-option<?php echo $checked ? ' checked' : ''; ?>" for="<?php echo $id_attr; ?>">
80 <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 ); ?>
81 </label>
82 <?php
83 endforeach;
84 ?>
85 </fieldset>
86 </td>
87 </tr>
88
89 <?php
90 }
91
92 function bogo_select_own_locale( $profileuser ) {
93 $available_languages = bogo_available_languages( array(
94 'exclude_enus_if_inactive' => true,
95 'orderby' => 'value',
96 'current_user_can_access' => true ) );
97
98 $selected = bogo_get_user_locale( $profileuser->ID );
99
100 ?>
101
102 <!-- Bogo plugin -->
103 <tr>
104 <th scope="row"><?php echo esc_html( __( 'Locale', 'bogo' ) ); ?></th>
105 <td>
106 <select name="bogo_own_locale">
107 <?php foreach ( $available_languages as $locale => $lang ) : ?>
108 <option value="<?php echo esc_attr( $locale ); ?>" <?php selected( $locale, $selected ); ?>><?php echo esc_html( $lang ); ?></option>
109 <?php endforeach; ?>
110 </select>
111 </td>
112 </tr>
113
114 <?php
115 }
116