PluginProbe
Polylang / 2.0.12
Polylang v2.0.12
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
← All changes | admin/admin-filters.php +59 -93 2.7.32.0.12 View file →
@@ -25,9 +25,9 @@
25 25 add_action( 'personal_options_update', array( $this, 'personal_options_update' ) );
26 26 add_action( 'edit_user_profile_update', array( $this, 'personal_options_update' ) );
27 27 add_action( 'personal_options', array( $this, 'personal_options' ) );
28 28
29 - // Upgrades languages files after a core upgrade ( timing is important )
29 + // Ugrades languages files after a core upgrade ( timing is important )
30 30 // Backward compatibility WP < 4.0 *AND* Polylang < 1.6
31 31 add_action( '_core_updated_successfully', array( $this, 'upgrade_languages' ), 1 ); // since WP 3.3
32 32
33 33 // Upgrades plugins and themes translations files
@@ -34,57 +34,39 @@
34 34 add_filter( 'themes_update_check_locales', array( $this, 'update_check_locales' ) );
35 35 add_filter( 'plugins_update_check_locales', array( $this, 'update_check_locales' ) );
36 36
37 37 // We need specific filters for German and Danish
38 - $specific_locales = array( 'da_DK', 'de_DE', 'de_DE_formal', 'de_CH', 'de_CH_informal', 'ca', 'sr_RS', 'bs_BA' );
38 + $specific_locales = array( 'da_DK', 'de_DE', 'de_DE_formal', 'de_CH', 'de_CH_informal' );
39 39 if ( array_intersect( $this->model->get_languages_list( array( 'fields' => 'locale' ) ), $specific_locales ) ) {
40 40 add_filter( 'sanitize_title', array( $this, 'sanitize_title' ), 10, 3 );
41 41 add_filter( 'sanitize_user', array( $this, 'sanitize_user' ), 10, 3 );
42 42 }
43 -
44 - add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
45 -
46 - // Add post state for translations of the privacy policy page
47 - add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 );
48 43 }
49 44
50 45 /**
51 - * Modifies the widgets forms to add our language dropdown list
46 + * Modifies the widgets forms to add our language dropdwown list
52 47 *
53 48 * @since 0.3
54 49 *
55 - * @param object $widget Widget instance
56 - * @param null $return Not used
57 - * @param array $instance Widget settings
50 + * @param object $widget
58 51 */
59 52 public function in_widget_form( $widget, $return, $instance ) {
60 - $screen = get_current_screen();
61 -
62 - // Test the Widgets screen and the Customizer to avoid displaying the option in page builders
63 - // Saving the widget reloads the form. And curiously the action is in $_REQUEST but neither in $_POST, nor in $_GET.
64 - if ( ( isset( $screen ) && 'widgets' === $screen->base ) || ( isset( $_REQUEST['action'] ) && 'save-widget' === $_REQUEST['action'] ) || isset( $GLOBALS['wp_customize'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
65 - $dropdown = new PLL_Walker_Dropdown();
66 -
67 - $dropdown_html = $dropdown->walk(
53 + $dropdown = new PLL_Walker_Dropdown();
54 + printf( '<p><label for="%1$s">%2$s %3$s</label></p>',
55 + esc_attr( $widget->id.'_lang_choice' ),
56 + esc_html__( 'The widget is displayed for:', 'polylang' ),
57 + $dropdown->walk(
68 58 array_merge(
69 59 array( (object) array( 'slug' => 0, 'name' => __( 'All languages', 'polylang' ) ) ),
70 60 $this->model->get_languages_list()
71 61 ),
72 - -1,
73 62 array(
74 - 'name' => $widget->id . '_lang_choice',
75 - 'class' => 'tags-input pll-lang-choice',
76 - 'selected' => empty( $instance['pll_lang'] ) ? '' : $instance['pll_lang'],
63 + 'name' => $widget->id.'_lang_choice',
64 + 'class' => 'tags-input',
65 + 'selected' => empty( $instance['pll_lang'] ) ? '' : $instance['pll_lang'],
77 66 )
78 - );
79 -
80 - printf(
81 - '<p><label for="%1$s">%2$s %3$s</label></p>',
82 - esc_attr( $widget->id . '_lang_choice' ),
83 - esc_html__( 'The widget is displayed for:', 'polylang' ),
84 - $dropdown_html // phpcs:ignore WordPress.Security.EscapeOutput
85 - );
86 - }
67 + )
68 + );
87 69 }
88 70
89 71 /**
90 72 * Called when widget options are saved
@@ -98,12 +80,10 @@
98 80 * @param object $widget WP_Widget object
99 81 * @return array Widget options
100 82 */
101 83 public function widget_update_callback( $instance, $new_instance, $old_instance, $widget ) {
102 - $key = $widget->id . '_lang_choice';
103 -
104 - if ( ! empty( $_POST[ $key ] ) && $lang = $this->model->get_language( sanitize_key( $_POST[ $key ] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
105 - $instance['pll_lang'] = $lang->slug;
84 + if ( ! empty( $_POST[ $key = $widget->id.'_lang_choice' ] ) && in_array( $_POST[ $key ], $this->model->get_languages_list( array( 'fields' => 'slug' ) ) ) ) {
85 + $instance['pll_lang'] = $_POST[ $key ];
106 86 } else {
107 87 unset( $instance['pll_lang'] );
108 88 }
109 89
@@ -117,12 +97,19 @@
117 97 *
118 98 * @param int $user_id
119 99 */
120 100 public function personal_options_update( $user_id ) {
101 + // Admin language
102 + // FIXME Backward compatibility with WP < 4.7
103 + if ( version_compare( $GLOBALS['wp_version'], '4.7alpha', '<' ) ) {
104 + $user_lang = in_array( $_POST['user_lang'], $this->model->get_languages_list( array( 'fields' => 'locale' ) ) ) ? $_POST['user_lang'] : 0;
105 + update_user_meta( $user_id, 'locale', $user_lang );
106 + }
107 +
121 108 // Biography translations
122 109 foreach ( $this->model->get_languages_list() as $lang ) {
123 110 $meta = $lang->slug == $this->options['default_lang'] ? 'description' : 'description_' . $lang->slug;
124 - $description = empty( $_POST[ 'description_' . $lang->slug ] ) ? '' : trim( $_POST[ 'description_' . $lang->slug ] ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput
111 + $description = empty( $_POST[ 'description_' . $lang->slug ] ) ? '' : trim( $_POST[ 'description_' . $lang->slug ] );
125 112
126 113 /** This filter is documented in wp-includes/user.php */
127 114 $description = apply_filters( 'pre_user_description', $description ); // Applies WP default filter wp_filter_kses
128 115 update_user_meta( $user_id, $meta, $description );
@@ -129,9 +116,9 @@
129 116 }
130 117 }
131 118
132 119 /**
133 - * Outputs hidden information to modify the biography form with js
120 + * Form for language user preference in user profile
134 121 *
135 122 * @since 0.4
136 123 *
137 124 * @param object $profileuser
@@ -136,8 +123,32 @@
136 123 *
137 124 * @param object $profileuser
138 125 */
139 126 public function personal_options( $profileuser ) {
127 + // FIXME: Backward compatibility with WP < 4.7
128 + if ( version_compare( $GLOBALS['wp_version'], '4.7alpha', '<' ) ) {
129 + $dropdown = new PLL_Walker_Dropdown();
130 + printf( '
131 + <tr>
132 + <th><label for="user_lang">%s</label></th>
133 + <td>%s</td>
134 + </tr>',
135 + esc_html__( 'Admin language', 'polylang' ),
136 + $dropdown->walk(
137 + array_merge(
138 + array( (object) array( 'locale' => 0, 'name' => __( 'WordPress default', 'polylang' ) ) ),
139 + $this->model->get_languages_list()
140 + ),
141 + array(
142 + 'name' => 'user_lang',
143 + 'value' => 'locale',
144 + 'selected' => get_user_meta( $profileuser->ID, 'locale', true ),
145 + )
146 + )
147 + );
148 + }
149 +
150 + // Hidden informations to modify the biography form with js
140 151 foreach ( $this->model->get_languages_list() as $lang ) {
141 152 $meta = $lang->slug == $this->options['default_lang'] ? 'description' : 'description_' . $lang->slug;
142 153
143 154 /** This filter is documented in wp-includes/user.php */
@@ -142,10 +153,9 @@
142 153
143 154 /** This filter is documented in wp-includes/user.php */
144 155 $description = apply_filters( 'user_description', get_user_meta( $profileuser->ID, $meta, true ) ); // Applies WP default filter wp_kses_data
145 156
146 - printf(
147 - '<input type="hidden" class="biography" name="%s___%s" value="%s" />',
157 + printf( '<input type="hidden" class="biography" name="%s___%s" value="%s" />',
148 158 esc_attr( $lang->slug ),
149 159 esc_attr( $lang->name ),
150 160 esc_attr( $description )
151 161 );
@@ -152,9 +162,9 @@
152 162 }
153 163 }
154 164
155 165 /**
156 - * Upgrades languages files after a core upgrade
166 + * Ugprades languages files after a core upgrade
157 167 * only for backward compatibility WP < 4.0 *AND* Polylang < 1.6
158 168 *
159 169 * @since 0.6
160 170 *
@@ -174,12 +184,12 @@
174 184 * Allows to update translations files for plugins and themes
175 185 *
176 186 * @since 1.6
177 187 *
178 - * @param array $locales Not used
188 + * @param array $locale not used
179 189 * @return array list of locales to update
180 190 */
181 - public function update_check_locales( $locales ) {
191 + function update_check_locales( $locales ) {
182 192 return $this->model->get_languages_list( array( 'fields' => 'locale' ) );
183 193 }
184 194
185 195 /**
@@ -191,19 +201,9 @@
191 201 * @param string $locale
192 202 * @return string
193 203 */
194 204 public function get_locale( $locale ) {
195 - if ( isset( $_POST['post_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['post_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
196 - $locale = $lang->locale;
197 - } elseif ( isset( $_POST['term_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['term_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
198 - $locale = $lang->locale;
199 - } elseif ( isset( $_POST['inline_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
200 - $locale = $lang->locale;
201 - } elseif ( ! empty( $this->curlang ) ) {
202 - $locale = $this->curlang->locale;
203 - }
204 -
205 - return $locale;
205 + return $this->curlang->locale;
206 206 }
207 207
208 208 /**
209 209 * Maybe fix the result of sanitize_title() in case the languages include German or Danish
@@ -220,9 +220,9 @@
220 220 */
221 221 public function sanitize_title( $title, $raw_title, $context ) {
222 222 static $once = false;
223 223
224 - if ( ! $once && 'save' == $context && ! empty( $title ) ) {
224 + if ( ! $once && 'save' == $context && ! empty( $this->curlang ) && ! empty( $title ) ) {
225 225 $once = true;
226 226 add_filter( 'locale', array( $this, 'get_locale' ), 20 ); // After the filter for the admin interface
227 227 $title = sanitize_title( $raw_title, '', $context );
228 228 remove_filter( 'locale', array( $this, 'get_locale' ), 20 );
@@ -235,56 +235,22 @@
235 235 * Maybe fix the result of sanitize_user() in case the languages include German or Danish
236 236 *
237 237 * @since 2.0
238 238 *
239 - * @param string $username Sanitized username.
239 + * @param string $username Sanitized username.
240 240 * @param string $raw_username The username prior to sanitization.
241 - * @param bool $strict Whether to limit the sanitization to specific characters. Default false.
241 + * @param bool $strict Whether to limit the sanitization to specific characters. Default false.
242 242 * @return string
243 243 */
244 244 public function sanitize_user( $username, $raw_username, $strict ) {
245 245 static $once = false;
246 246
247 - if ( ! $once ) {
247 + if ( ! $once && ! empty( $this->curlang ) ) {
248 248 $once = true;
249 249 add_filter( 'locale', array( $this, 'get_locale' ), 20 ); // After the filter for the admin interface
250 - $username = sanitize_user( $raw_username, '', $strict );
250 + $title = sanitize_title( $raw_username, '', $strict );
251 251 remove_filter( 'locale', array( $this, 'get_locale' ), 20 );
252 252 $once = false;
253 253 }
254 254 return $username;
255 - }
256 -
257 - /**
258 - * Adds a text direction dependent class to the body
259 - *
260 - * @since 2.2
261 - *
262 - * @param string $classes Space-separated list of CSS classes.
263 - * @return string
264 - */
265 - public function admin_body_class( $classes ) {
266 - if ( ! empty( $this->curlang ) ) {
267 - $classes .= ' pll-dir-' . ( $this->curlang->is_rtl ? 'rtl' : 'ltr' );
268 - }
269 - return $classes;
270 - }
271 -
272 - /**
273 - * Add post state for translations of the privacy policy page
274 - *
275 - * @since 2.7
276 - *
277 - * @param array $post_states An array of post display states.
278 - * @param object $post The current post object.
279 - * @return array
280 - */
281 - public function display_post_states( $post_states, $post ) {
282 - $page_for_privacy_policy = get_option( 'wp_page_for_privacy_policy' );
283 -
284 - if ( $page_for_privacy_policy && in_array( $post->ID, $this->model->post->get_translations( $page_for_privacy_policy ) ) ) {
285 - $post_states['page_for_privacy_policy'] = __( 'Privacy Policy Page', 'polylang' );
286 - }
287 -
288 - return $post_states;
289 255 }
290 256 }