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