PluginProbe
Polylang / 3.1.4
Polylang v3.1.4
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 | settings/table-string.php +49 -14 2.73.1.4 View file →
@@ -1,5 +1,8 @@
1 1 <?php
2 +/**
3 + * @package Polylang
4 + */
2 5
3 6 if ( ! class_exists( 'WP_List_Table' ) ) {
4 7 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; // since WP 3.1
5 8 }
@@ -10,16 +13,42 @@
10 13 *
11 14 * @since 0.6
12 15 */
13 16 class PLL_Table_String extends WP_List_Table {
14 - protected $languages, $strings, $groups, $selected_group;
17 + /**
18 + * The list of languages.
19 + *
20 + * @var PLL_Language[]
21 + */
22 + protected $languages;
15 23
16 24 /**
17 - * Constructor
25 + * Registered strings.
18 26 *
27 + * @var array
28 + */
29 + protected $strings;
30 +
31 + /**
32 + * The string groups.
33 + *
34 + * @var string[]
35 + */
36 + protected $groups;
37 +
38 + /**
39 + * The selected string group or -1 if none is selected.
40 + *
41 + * @var string|int
42 + */
43 + protected $selected_group;
44 +
45 + /**
46 + * Constructor.
47 + *
19 48 * @since 0.6
20 49 *
21 - * @param array $languages list of languages
50 + * @param PLL_Language[] $languages List of languages.
22 51 */
23 52 public function __construct( $languages ) {
24 53 parent::__construct(
25 54 array(
@@ -115,17 +144,17 @@
115 144 return $out;
116 145 }
117 146
118 147 /**
119 - * Gets the list of columns
148 + * Gets the list of columns.
120 149 *
121 150 * @since 0.6
122 151 *
123 - * @return array the list of column titles
152 + * @return string[] The list of column titles.
124 153 */
125 154 public function get_columns() {
126 155 return array(
127 - 'cb' => '<input type="checkbox" />', // Checkbox
156 + 'cb' => '<input type="checkbox" />', // Checkbox.
128 157 'string' => esc_html__( 'String', 'polylang' ),
129 158 'name' => esc_html__( 'Name', 'polylang' ),
130 159 'context' => esc_html__( 'Group', 'polylang' ),
131 160 'translations' => esc_html__( 'Translations', 'polylang' ),
@@ -162,11 +191,11 @@
162 191 * Search for a string in translations. Case insensitive.
163 192 *
164 193 * @since 2.6
165 194 *
166 - * @param array $mos An array of PLL_MO objects
167 - * @param string $s Searched string
168 - * @return array Found strings
195 + * @param PLL_MO[] $mos An array of PLL_MO objects.
196 + * @param string $s Searched string.
197 + * @return string[] Found strings.
169 198 */
170 199 protected function search_in_translations( $mos, $s ) {
171 200 $founds = array();
172 201
@@ -205,8 +234,10 @@
205 234 /**
206 235 * Prepares the list of items for displaying
207 236 *
208 237 * @since 0.6
238 + *
239 + * @return void
209 240 */
210 241 public function prepare_items() {
211 242 // Is admin language filter active?
212 243 if ( $lg = get_user_meta( get_current_user_id(), 'pll_filter_content', true ) ) {
@@ -271,13 +302,13 @@
271 302 }
272 303 }
273 304
274 305 /**
275 - * Get the list of possible bulk actions
306 + * Get the list of possible bulk actions.
276 307 *
277 308 * @since 1.1
278 309 *
279 - * @return array
310 + * @return string[] Array of bulk actions.
280 311 */
281 312 public function get_bulk_actions() {
282 313 return array( 'delete' => __( 'Delete', 'polylang' ) );
283 314 }
@@ -299,8 +330,9 @@
299 330 *
300 331 * @since 1.1
301 332 *
302 333 * @param string $which only 'top' is supported
334 + * @return void
303 335 */
304 336 public function extra_tablenav( $which ) {
305 337 if ( 'top' !== $which ) {
306 338 return;
@@ -314,9 +346,9 @@
314 346 );
315 347 echo '<select id="select-group" name="group">' . "\n";
316 348 printf(
317 349 '<option value="-1"%s>%s</option>' . "\n",
318 - selected( $this->group_selected, -1, false ),
350 + selected( $this->selected_group, -1, false ),
319 351 esc_html__( 'View all groups', 'polylang' )
320 352 );
321 353
322 354 foreach ( $this->groups as $group ) {
@@ -337,8 +369,10 @@
337 369 * Saves the strings translations in DB
338 370 * Optionaly clean the DB
339 371 *
340 372 * @since 1.9
373 + *
374 + * @return void
341 375 */
342 376 public function save_translations() {
343 377 check_admin_referer( 'string-translation', '_wpnonce_string-translation' );
344 378
@@ -343,16 +377,17 @@
343 377 check_admin_referer( 'string-translation', '_wpnonce_string-translation' );
344 378
345 379 if ( ! empty( $_POST['submit'] ) ) {
346 380 foreach ( $this->languages as $language ) {
347 - if ( empty( $_POST['translation'][ $language->slug ] ) ) { // In case the language filter is active ( thanks to John P. Bloch )
381 + if ( empty( $_POST['translation'][ $language->slug ] ) || ! is_array( $_POST['translation'][ $language->slug ] ) ) { // In case the language filter is active ( thanks to John P. Bloch )
348 382 continue;
349 383 }
350 384
385 + $translations = array_map( 'trim', wp_unslash( $_POST['translation'][ $language->slug ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
386 +
351 387 $mo = new PLL_MO();
352 388 $mo->import_from_db( $language );
353 389
354 - $translations = array_map( 'trim', wp_unslash( $_POST['translation'][ $language->slug ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
355 390 foreach ( $translations as $key => $translation ) {
356 391 /**
357 392 * Filter the string translation before it is saved in DB
358 393 * Allows to sanitize strings registered with pll_register_string