PluginProbe
Polylang / 3.3
Polylang v3.3
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 +56 -20 2.93.3 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(
@@ -98,11 +124,15 @@
98 124 * @param array $item
99 125 * @return string
100 126 */
101 127 public function column_translations( $item ) {
102 - $languages = array_combine( wp_list_pluck( $this->languages, 'slug' ), wp_list_pluck( $this->languages, 'name' ) );
103 - $out = '';
128 + $out = '';
129 + $languages = array();
104 130
131 + foreach ( $this->languages as $language ) {
132 + $languages[ $language->slug ] = $language->name;
133 + }
134 +
105 135 foreach ( $item['translations'] as $key => $translation ) {
106 136 $input_type = $item['multiline'] ?
107 137 '<textarea name="translation[%1$s][%2$s]" id="%1$s-%2$s">%4$s</textarea>' :
108 138 '<input type="text" name="translation[%1$s][%2$s]" id="%1$s-%2$s" value="%4$s" />';
@@ -118,17 +148,17 @@
118 148 return $out;
119 149 }
120 150
121 151 /**
122 - * Gets the list of columns
152 + * Gets the list of columns.
123 153 *
124 154 * @since 0.6
125 155 *
126 - * @return array the list of column titles
156 + * @return string[] The list of column titles.
127 157 */
128 158 public function get_columns() {
129 159 return array(
130 - 'cb' => '<input type="checkbox" />', // Checkbox
160 + 'cb' => '<input type="checkbox" />', // Checkbox.
131 161 'string' => esc_html__( 'String', 'polylang' ),
132 162 'name' => esc_html__( 'Name', 'polylang' ),
133 163 'context' => esc_html__( 'Group', 'polylang' ),
134 164 'translations' => esc_html__( 'Translations', 'polylang' ),
@@ -165,11 +195,11 @@
165 195 * Search for a string in translations. Case insensitive.
166 196 *
167 197 * @since 2.6
168 198 *
169 - * @param array $mos An array of PLL_MO objects
170 - * @param string $s Searched string
171 - * @return array Found strings
199 + * @param PLL_MO[] $mos An array of PLL_MO objects.
200 + * @param string $s Searched string.
201 + * @return string[] Found strings.
172 202 */
173 203 protected function search_in_translations( $mos, $s ) {
174 204 $founds = array();
175 205
@@ -184,14 +214,14 @@
184 214 return array_unique( $founds );
185 215 }
186 216
187 217 /**
188 - * Sort items
218 + * Sorts registered string items.
189 219 *
190 220 * @since 0.6
191 221 *
192 - * @param object $a The first object to compare
193 - * @param object $b The second object to compare
222 + * @param array $a The first item to compare.
223 + * @param array $b The second item to compare.
194 224 * @return int -1 or 1 if $a is considered to be respectively less than or greater than $b.
195 225 */
196 226 protected function usort_reorder( $a, $b ) {
197 227 if ( ! empty( $_GET['orderby'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
@@ -205,11 +235,13 @@
205 235 return 0;
206 236 }
207 237
208 238 /**
209 - * Prepares the list of items for displaying
239 + * Prepares the list of registered strings for display.
210 240 *
211 241 * @since 0.6
242 + *
243 + * @return void
212 244 */
213 245 public function prepare_items() {
214 246 // Is admin language filter active?
215 247 if ( $lg = get_user_meta( get_current_user_id(), 'pll_filter_content', true ) ) {
@@ -274,13 +306,13 @@
274 306 }
275 307 }
276 308
277 309 /**
278 - * Get the list of possible bulk actions
310 + * Get the list of possible bulk actions.
279 311 *
280 312 * @since 1.1
281 313 *
282 - * @return array
314 + * @return string[] Array of bulk actions.
283 315 */
284 316 public function get_bulk_actions() {
285 317 return array( 'delete' => __( 'Delete', 'polylang' ) );
286 318 }
@@ -302,8 +334,9 @@
302 334 *
303 335 * @since 1.1
304 336 *
305 337 * @param string $which only 'top' is supported
338 + * @return void
306 339 */
307 340 public function extra_tablenav( $which ) {
308 341 if ( 'top' !== $which ) {
309 342 return;
@@ -317,9 +350,9 @@
317 350 );
318 351 echo '<select id="select-group" name="group">' . "\n";
319 352 printf(
320 353 '<option value="-1"%s>%s</option>' . "\n",
321 - selected( $this->group_selected, -1, false ),
354 + selected( $this->selected_group, -1, false ),
322 355 esc_html__( 'View all groups', 'polylang' )
323 356 );
324 357
325 358 foreach ( $this->groups as $group ) {
@@ -340,8 +373,10 @@
340 373 * Saves the strings translations in DB
341 374 * Optionaly clean the DB
342 375 *
343 376 * @since 1.9
377 + *
378 + * @return void
344 379 */
345 380 public function save_translations() {
346 381 check_admin_referer( 'string-translation', '_wpnonce_string-translation' );
347 382
@@ -346,16 +381,17 @@
346 381 check_admin_referer( 'string-translation', '_wpnonce_string-translation' );
347 382
348 383 if ( ! empty( $_POST['submit'] ) ) {
349 384 foreach ( $this->languages as $language ) {
350 - if ( empty( $_POST['translation'][ $language->slug ] ) ) { // In case the language filter is active ( thanks to John P. Bloch )
385 + 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 386 continue;
352 387 }
353 388
389 + $translations = array_map( 'trim', (array) wp_unslash( $_POST['translation'][ $language->slug ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
390 +
354 391 $mo = new PLL_MO();
355 392 $mo->import_from_db( $language );
356 393
357 - $translations = array_map( 'trim', wp_unslash( $_POST['translation'][ $language->slug ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
358 394 foreach ( $translations as $key => $translation ) {
359 395 /**
360 396 * Filter the string translation before it is saved in DB
361 397 * Allows to sanitize strings registered with pll_register_string