PluginProbe
Polylang / 2.5.2
Polylang v2.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
← All changes | admin/admin-filters.php +19 -50 2.82.5.2 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Setup miscellaneous admin filters as well as filters common to admin and frontend
8 5 *
@@ -44,11 +41,8 @@
44 41 add_filter( 'sanitize_user', array( $this, 'sanitize_user' ), 10, 3 );
45 42 }
46 43
47 44 add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
48 -
49 - // Add post state for translations of the privacy policy page
50 - add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 );
51 45 }
52 46
53 47 /**
54 48 * Modifies the widgets forms to add our language dropdown list
@@ -62,30 +56,26 @@
62 56 public function in_widget_form( $widget, $return, $instance ) {
63 57 $screen = get_current_screen();
64 58
65 59 // Test the Widgets screen and the Customizer to avoid displaying the option in page builders
66 - // Saving the widget reloads the form. And curiously the action is in $_REQUEST but neither in $_POST, nor in $_GET.
67 - if ( ( isset( $screen ) && 'widgets' === $screen->base ) || ( isset( $_REQUEST['action'] ) && 'save-widget' === $_REQUEST['action'] ) || isset( $GLOBALS['wp_customize'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
60 + // Saving the widget reloads the form. And curiously the action is in $_REQUEST but neither in $_POST, not in $_GET.
61 + if ( ( isset( $screen ) && 'widgets' === $screen->base ) || ( isset( $_REQUEST['action'] ) && 'save-widget' === $_REQUEST['action'] ) || isset( $GLOBALS['wp_customize'] ) ) {
68 62 $dropdown = new PLL_Walker_Dropdown();
69 -
70 - $dropdown_html = $dropdown->walk(
71 - array_merge(
72 - array( (object) array( 'slug' => 0, 'name' => __( 'All languages', 'polylang' ) ) ),
73 - $this->model->get_languages_list()
74 - ),
75 - -1,
76 - array(
77 - 'name' => $widget->id . '_lang_choice',
78 - 'class' => 'tags-input pll-lang-choice',
79 - 'selected' => empty( $instance['pll_lang'] ) ? '' : $instance['pll_lang'],
80 - )
81 - );
82 -
83 63 printf(
84 64 '<p><label for="%1$s">%2$s %3$s</label></p>',
85 65 esc_attr( $widget->id . '_lang_choice' ),
86 66 esc_html__( 'The widget is displayed for:', 'polylang' ),
87 - $dropdown_html // phpcs:ignore WordPress.Security.EscapeOutput
67 + $dropdown->walk(
68 + array_merge(
69 + array( (object) array( 'slug' => 0, 'name' => __( 'All languages', 'polylang' ) ) ),
70 + $this->model->get_languages_list()
71 + ),
72 + array(
73 + 'name' => $widget->id . '_lang_choice',
74 + 'class' => 'tags-input pll-lang-choice',
75 + 'selected' => empty( $instance['pll_lang'] ) ? '' : $instance['pll_lang'],
76 + )
77 + )
88 78 );
89 79 }
90 80 }
91 81
@@ -101,12 +91,10 @@
101 91 * @param object $widget WP_Widget object
102 92 * @return array Widget options
103 93 */
104 94 public function widget_update_callback( $instance, $new_instance, $old_instance, $widget ) {
105 - $key = $widget->id . '_lang_choice';
106 -
107 - if ( ! empty( $_POST[ $key ] ) && $lang = $this->model->get_language( sanitize_key( $_POST[ $key ] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
108 - $instance['pll_lang'] = $lang->slug;
95 + if ( ! empty( $_POST[ $key = $widget->id . '_lang_choice' ] ) && in_array( $_POST[ $key ], $this->model->get_languages_list( array( 'fields' => 'slug' ) ) ) ) {
96 + $instance['pll_lang'] = $_POST[ $key ];
109 97 } else {
110 98 unset( $instance['pll_lang'] );
111 99 }
112 100
@@ -123,9 +111,9 @@
123 111 public function personal_options_update( $user_id ) {
124 112 // Biography translations
125 113 foreach ( $this->model->get_languages_list() as $lang ) {
126 114 $meta = $lang->slug == $this->options['default_lang'] ? 'description' : 'description_' . $lang->slug;
127 - $description = empty( $_POST[ 'description_' . $lang->slug ] ) ? '' : trim( $_POST[ 'description_' . $lang->slug ] ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput
115 + $description = empty( $_POST[ 'description_' . $lang->slug ] ) ? '' : trim( $_POST[ 'description_' . $lang->slug ] );
128 116
129 117 /** This filter is documented in wp-includes/user.php */
130 118 $description = apply_filters( 'pre_user_description', $description ); // Applies WP default filter wp_filter_kses
131 119 update_user_meta( $user_id, $meta, $description );
@@ -194,13 +182,13 @@
194 182 * @param string $locale
195 183 * @return string
196 184 */
197 185 public function get_locale( $locale ) {
198 - if ( isset( $_POST['post_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['post_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
186 + if ( isset( $_POST['post_lang_choice'] ) && $lang = $this->model->get_language( $_POST['post_lang_choice'] ) ) {
199 187 $locale = $lang->locale;
200 - } elseif ( isset( $_POST['term_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['term_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
188 + } elseif ( isset( $_POST['term_lang_choice'] ) && $lang = $this->model->get_language( $_POST['term_lang_choice'] ) ) {
201 189 $locale = $lang->locale;
202 - } elseif ( isset( $_POST['inline_lang_choice'] ) && $lang = $this->model->get_language( sanitize_key( $_POST['inline_lang_choice'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
190 + } elseif ( isset( $_POST['inline_lang_choice'] ) && $lang = $this->model->get_language( $_POST['inline_lang_choice'] ) ) {
203 191 $locale = $lang->locale;
204 192 } elseif ( ! empty( $this->curlang ) ) {
205 193 $locale = $this->curlang->locale;
206 194 }
@@ -269,25 +257,6 @@
269 257 if ( ! empty( $this->curlang ) ) {
270 258 $classes .= ' pll-dir-' . ( $this->curlang->is_rtl ? 'rtl' : 'ltr' );
271 259 }
272 260 return $classes;
273 - }
274 -
275 - /**
276 - * Add post state for translations of the privacy policy page
277 - *
278 - * @since 2.7
279 - *
280 - * @param array $post_states An array of post display states.
281 - * @param object $post The current post object.
282 - * @return array
283 - */
284 - public function display_post_states( $post_states, $post ) {
285 - $page_for_privacy_policy = get_option( 'wp_page_for_privacy_policy' );
286 -
287 - if ( $page_for_privacy_policy && in_array( $post->ID, $this->model->post->get_translations( $page_for_privacy_policy ) ) ) {
288 - $post_states['page_for_privacy_policy'] = __( 'Privacy Policy Page', 'polylang' );
289 - }
290 -
291 - return $post_states;
292 261 }
293 262 }