PluginProbe
Polylang / 1.5.2
Polylang v1.5.2
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
polylang / admin / admin-filters.php

admin-filters.php in Polylang 1.5.2, at admin/admin-filters.php

157 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * setup miscellaneous admin filters as well as filters common to admin and frontend
5 *
6 * @since 1.2
7 */
8 class PLL_Admin_Filters extends PLL_Filters {
9
10 /*
11 * constructor: setups filters and actions
12 *
13 * @since 1.2
14 *
15 * @param object $polylang
16 */
17 public function __construct(&$polylang) {
18 parent::__construct($polylang);
19
20 // widgets languages filter
21 add_action('in_widget_form', array(&$this, 'in_widget_form'), 10, 3);
22 add_filter('widget_update_callback', array(&$this, 'widget_update_callback'), 10, 4);
23
24 // language management for users
25 add_action('personal_options_update', array(&$this, 'personal_options_update'));
26 add_action('edit_user_profile_update', array(&$this, 'personal_options_update'));
27 add_action('personal_options', array(&$this, 'personal_options'));
28
29 // ugrades languages files after a core upgrade (timing is important)
30 // FIXME private action ? is there a better way to do this ?
31 add_action( '_core_updated_successfully', array(&$this, 'upgrade_languages'), 1); // since WP 3.3
32 }
33
34 /*
35 * modifies the widgets forms to add our language dropdwown list
36 *
37 * @since 0.3
38 *
39 * @param object $widget
40 */
41 public function in_widget_form($widget, $return, $instance) {
42 $dropdown = new PLL_Walker_Dropdown();
43 printf('<p><label for="%1$s">%2$s %3$s</label></p>',
44 esc_attr( $widget->id.'_lang_choice'),
45 __('The widget is displayed for:', 'polylang'),
46 $dropdown->walk(
47 array_merge(
48 array((object) array('slug' => 0, 'name' => __('All languages', 'polylang'))),
49 $this->model->get_languages_list()
50 ),
51 array(
52 'name' => $widget->id.'_lang_choice',
53 'class' => 'tags-input',
54 'selected' => empty($instance['pll_lang']) ? '' : $instance['pll_lang']
55 )
56 )
57 );
58 }
59
60 /*
61 * called when widget options are saved
62 * saves the language associated to the widget
63 *
64 * @since 0.3
65 *
66 * @param array $instance widget options
67 * @param array $new_instance not used
68 * @param array $old_instance not used
69 * @param object $widget WP_Widget object
70 * @return array widget options
71 */
72 public function widget_update_callback($instance, $new_instance, $old_instance, $widget) {
73 if (!empty($_POST[$widget->id.'_lang_choice']))
74 $instance['pll_lang'] = $_POST[$widget->id.'_lang_choice'];
75 else
76 unset($instance['pll_lang']);
77
78 return $instance;
79 }
80
81 /*
82 * updates language user preference set in user profile
83 *
84 * @since 0.4
85 *
86 * @param int $user_id
87 */
88 public function personal_options_update($user_id) {
89 // admin language
90 $user_lang = in_array($_POST['user_lang'], $this->model->get_languages_list(array('fields' => 'locale'))) ? $_POST['user_lang'] : 0;
91 update_user_meta($user_id, 'user_lang', $_POST['user_lang']);
92
93 // biography translations
94 foreach ($this->model->get_languages_list() as $lang) {
95 $meta = $lang->slug == $this->options['default_lang'] ? 'description' : 'description_'.$lang->slug;
96 $description = empty($_POST['description_'.$lang->slug]) ? '' : trim($_POST['description_'.$lang->slug]);
97 $description = apply_filters('pre_user_description', $description); // applies WP default filter wp_filter_kses
98 update_user_meta($user_id, $meta, $description);
99 }
100 }
101
102 /*
103 * form for language user preference in user profile
104 *
105 * @since 0.4
106 *
107 * @param object $profileuser
108 */
109 public function personal_options($profileuser) {
110 $dropdown = new PLL_Walker_Dropdown();
111 printf('
112 <tr>
113 <th><label for="user_lang">%s</label></th>
114 <td>%s</td>
115 </tr>',
116 __('Admin language', 'polylang'),
117 $dropdown->walk(
118 array_merge(
119 array((object) array('locale' => 0, 'name' => __('Wordpress default', 'polylang'))),
120 $this->model->get_languages_list()
121 ),
122 array(
123 'name' => 'user_lang',
124 'value' => 'locale',
125 'selected' => get_user_meta($profileuser->ID, 'user_lang', true),
126 )
127 )
128 );
129
130 // hidden informations to modify the biography form with js
131 foreach ($this->model->get_languages_list() as $lang) {
132 $meta = $lang->slug == $this->options['default_lang'] ? 'description' : 'description_'.$lang->slug;
133 $description = apply_filters('user_description', get_user_meta($profileuser->ID, $meta, true)); // applies WP default filter wp_kses_data
134
135 printf('<input type="hidden" class="biography" name="%s-%s" value="%s" />',
136 esc_attr($lang->slug),
137 esc_attr($lang->name),
138 esc_attr($description)
139 );
140 }
141 }
142
143 /*
144 * ugprades languages files after a core upgrade
145 *
146 * @since 0.6
147 *
148 * @param string $version WP version
149 */
150 public function upgrade_languages($version) {
151 apply_filters('update_feedback', __('Upgrading language files&#8230;', 'polylang'));
152 foreach ($this->model->get_languages_list() as $language)
153 if (!empty($_POST['locale']) && $language->locale != $_POST['locale']) // do not (re)update the language files of a localized WordPress
154 PLL_Admin::download_mo($language->locale, $version);
155 }
156 }
157