PluginProbe
Polylang / 3.7.7
Polylang v3.7.7
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 +23 -110 2.93.7.7 View file →
@@ -10,30 +10,22 @@
10 10 */
11 11 class PLL_Admin_Filters extends PLL_Filters {
12 12
13 13 /**
14 - * Constructor: setups filters and actions
14 + * Constructor: setups filters and actions.
15 15 *
16 16 * @since 1.2
17 17 *
18 - * @param object $polylang
18 + * @param object $polylang The Polylang object.
19 19 */
20 20 public function __construct( &$polylang ) {
21 21 parent::__construct( $polylang );
22 22
23 - // Widgets languages filter
24 - add_action( 'in_widget_form', array( $this, 'in_widget_form' ), 10, 3 );
25 - add_filter( 'widget_update_callback', array( $this, 'widget_update_callback' ), 10, 4 );
26 -
27 23 // Language management for users
28 24 add_action( 'personal_options_update', array( $this, 'personal_options_update' ) );
29 25 add_action( 'edit_user_profile_update', array( $this, 'personal_options_update' ) );
30 26 add_action( 'personal_options', array( $this, 'personal_options' ) );
31 27
32 - // Upgrades languages files after a core upgrade ( timing is important )
33 - // Backward compatibility WP < 4.0 *AND* Polylang < 1.6
34 - add_action( '_core_updated_successfully', array( $this, 'upgrade_languages' ), 1 ); // since WP 3.3
35 -
36 28 // Upgrades plugins and themes translations files
37 29 add_filter( 'themes_update_check_locales', array( $this, 'update_check_locales' ) );
38 30 add_filter( 'plugins_update_check_locales', array( $this, 'update_check_locales' ) );
39 31
@@ -43,82 +35,20 @@
43 35 add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 );
44 36 }
45 37
46 38 /**
47 - * Modifies the widgets forms to add our language dropdown list
39 + * Updates the user biographies.
48 40 *
49 - * @since 0.3
50 - *
51 - * @param object $widget Widget instance
52 - * @param null $return Not used
53 - * @param array $instance Widget settings
54 - */
55 - public function in_widget_form( $widget, $return, $instance ) {
56 - $screen = get_current_screen();
57 -
58 - // Test the Widgets screen and the Customizer to avoid displaying the option in page builders
59 - // Saving the widget reloads the form. And curiously the action is in $_REQUEST but neither in $_POST, nor in $_GET.
60 - if ( ( isset( $screen ) && 'widgets' === $screen->base ) || ( isset( $_REQUEST['action'] ) && 'save-widget' === $_REQUEST['action'] ) || isset( $GLOBALS['wp_customize'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
61 - $dropdown = new PLL_Walker_Dropdown();
62 -
63 - $dropdown_html = $dropdown->walk(
64 - array_merge(
65 - array( (object) array( 'slug' => 0, 'name' => __( 'All languages', 'polylang' ) ) ),
66 - $this->model->get_languages_list()
67 - ),
68 - -1,
69 - array(
70 - 'name' => $widget->id . '_lang_choice',
71 - 'class' => 'tags-input pll-lang-choice',
72 - 'selected' => empty( $instance['pll_lang'] ) ? '' : $instance['pll_lang'],
73 - )
74 - );
75 -
76 - printf(
77 - '<p><label for="%1$s">%2$s %3$s</label></p>',
78 - esc_attr( $widget->id . '_lang_choice' ),
79 - esc_html__( 'The widget is displayed for:', 'polylang' ),
80 - $dropdown_html // phpcs:ignore WordPress.Security.EscapeOutput
81 - );
82 - }
83 - }
84 -
85 - /**
86 - * Called when widget options are saved
87 - * saves the language associated to the widget
88 - *
89 - * @since 0.3
90 - *
91 - * @param array $instance Widget options
92 - * @param array $new_instance Not used
93 - * @param array $old_instance Not used
94 - * @param object $widget WP_Widget object
95 - * @return array Widget options
96 - */
97 - public function widget_update_callback( $instance, $new_instance, $old_instance, $widget ) {
98 - $key = $widget->id . '_lang_choice';
99 -
100 - if ( ! empty( $_POST[ $key ] ) && $lang = $this->model->get_language( sanitize_key( $_POST[ $key ] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification
101 - $instance['pll_lang'] = $lang->slug;
102 - } else {
103 - unset( $instance['pll_lang'] );
104 - }
105 -
106 - return $instance;
107 - }
108 -
109 - /**
110 - * Updates language user preference set in user profile
111 - *
112 41 * @since 0.4
113 42 *
114 - * @param int $user_id
43 + * @param int $user_id User ID.
44 + * @return void
115 45 */
116 46 public function personal_options_update( $user_id ) {
117 47 // Biography translations
118 48 foreach ( $this->model->get_languages_list() as $lang ) {
119 - $meta = $lang->slug == $this->options['default_lang'] ? 'description' : 'description_' . $lang->slug;
120 - $description = empty( $_POST[ 'description_' . $lang->slug ] ) ? '' : trim( $_POST[ 'description_' . $lang->slug ] ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput
49 + $meta = $lang->is_default ? 'description' : 'description_' . $lang->slug;
50 + $description = empty( $_POST[ 'description_' . $lang->slug ] ) ? '' : trim( $_POST[ 'description_' . $lang->slug ] ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput
121 51
122 52 /** This filter is documented in wp-includes/user.php */
123 53 $description = apply_filters( 'pre_user_description', $description ); // Applies WP default filter wp_filter_kses
124 54 update_user_meta( $user_id, $meta, $description );
@@ -125,55 +55,36 @@
125 55 }
126 56 }
127 57
128 58 /**
129 - * Outputs hidden information to modify the biography form with js
59 + * Outputs hidden information to modify the biography form with js.
130 60 *
131 61 * @since 0.4
132 62 *
133 - * @param object $profileuser
63 + * @param WP_User $profileuser The current WP_User object.
64 + * @return void
134 65 */
135 66 public function personal_options( $profileuser ) {
136 67 foreach ( $this->model->get_languages_list() as $lang ) {
137 - $meta = $lang->slug == $this->options['default_lang'] ? 'description' : 'description_' . $lang->slug;
68 + $meta = $lang->is_default ? 'description' : 'description_' . $lang->slug;
69 + $description = get_user_meta( $profileuser->ID, $meta, true );
138 70
139 - /** This filter is documented in wp-includes/user.php */
140 - $description = apply_filters( 'user_description', get_user_meta( $profileuser->ID, $meta, true ) ); // Applies WP default filter wp_kses_data
141 -
142 71 printf(
143 72 '<input type="hidden" class="biography" name="%s___%s" value="%s" />',
144 73 esc_attr( $lang->slug ),
145 74 esc_attr( $lang->name ),
146 - esc_attr( $description )
75 + sanitize_user_field( 'description', $description, $profileuser->ID, 'edit' )
147 76 );
148 77 }
149 78 }
150 79
151 80 /**
152 - * Upgrades languages files after a core upgrade
153 - * only for backward compatibility WP < 4.0 *AND* Polylang < 1.6
154 - *
155 - * @since 0.6
156 - *
157 - * @param string $version new WP version
158 - */
159 - public function upgrade_languages( $version ) {
160 - // $GLOBALS['wp_version'] is the old WP version
161 - if ( version_compare( $version, '4.0', '>=' ) && version_compare( $GLOBALS['wp_version'], '4.0', '<' ) ) {
162 -
163 - /** This filter is documented in wp-admin/includes/update-core.php */
164 - apply_filters( 'update_feedback', __( 'Upgrading language files&#8230;', 'polylang' ) );
165 - PLL_Upgrade::download_language_packs();
166 - }
167 - }
168 -
169 - /**
170 81 * Allows to update translations files for plugins and themes.
171 82 *
172 83 * @since 1.6
173 84 *
174 - * @param array $locales List of locales to update for plugins and themes.
175 - * @return array
85 + * @param string[] $locales List of locales to update for plugins and themes.
86 + * @return string[]
176 87 */
177 88 public function update_check_locales( $locales ) {
178 89 return array_merge( $locales, $this->model->get_languages_list( array( 'fields' => 'locale' ) ) );
179 90 }
@@ -178,11 +89,12 @@
178 89 return array_merge( $locales, $this->model->get_languages_list( array( 'fields' => 'locale' ) ) );
179 90 }
180 91
181 92 /**
182 - * Adds a text direction dependent class to the body
93 + * Adds custom classes to the body
183 94 *
184 - * @since 2.2
95 + * @since 2.2 Adds a text direction dependent class to the body.
96 + * @since 3.4 Adds a language dependent class to the body.
185 97 *
186 98 * @param string $classes Space-separated list of CSS classes.
187 99 * @return string
188 100 */
@@ -188,20 +100,21 @@
188 100 */
189 101 public function admin_body_class( $classes ) {
190 102 if ( ! empty( $this->curlang ) ) {
191 103 $classes .= ' pll-dir-' . ( $this->curlang->is_rtl ? 'rtl' : 'ltr' );
104 + $classes .= ' pll-lang-' . $this->curlang->slug;
192 105 }
193 106 return $classes;
194 107 }
195 108
196 109 /**
197 - * Add post state for translations of the privacy policy page
110 + * Adds post state for translations of the privacy policy page.
198 111 *
199 112 * @since 2.7
200 113 *
201 - * @param array $post_states An array of post display states.
202 - * @param object $post The current post object.
203 - * @return array
114 + * @param string[] $post_states An array of post display states.
115 + * @param WP_Post $post The current post object.
116 + * @return string[]
204 117 */
205 118 public function display_post_states( $post_states, $post ) {
206 119 $page_for_privacy_policy = get_option( 'wp_page_for_privacy_policy' );
207 120