PluginProbe
Polylang / 2.1
Polylang v2.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-languages.php +50 -58 3.02.1 View file →
@@ -1,11 +1,8 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 if ( ! class_exists( 'WP_List_Table' ) ) {
7 - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; // since WP 3.1
4 + require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); // since WP 3.1
8 5 }
9 6
10 7 /**
11 8 * A class to create the languages table in Polylang settings
@@ -19,24 +16,21 @@
19 16 * Constructor
20 17 *
21 18 * @since 0.1
22 19 */
23 - public function __construct() {
24 - parent::__construct(
25 - array(
26 - 'plural' => 'Languages', // Do not translate ( used for css class )
27 - 'ajax' => false,
28 - )
29 - );
20 + function __construct() {
21 + parent::__construct( array(
22 + 'plural' => 'Languages', // Do not translate ( used for css class )
23 + 'ajax' => false,
24 + ) );
30 25 }
31 26
32 27 /**
33 - * Generates content for a single row of the table.
28 + * Generates content for a single row of the table
34 29 *
35 30 * @since 1.8
36 31 *
37 - * @param PLL_Language $item The language item.
38 - * @return void
32 + * @param object $item The current item
39 33 */
40 34 public function single_row( $item ) {
41 35 /**
42 36 * Filter the list of classes assigned a row in the languages list table
@@ -42,10 +36,10 @@
42 36 * Filter the list of classes assigned a row in the languages list table
43 37 *
44 38 * @since 1.8
45 39 *
46 - * @param array $classes The list of class names.
47 - * @param PLL_Language $item The language item.
40 + * @param array $classes list of class names
41 + * @param object $item the current item
48 42 */
49 43 $classes = apply_filters( 'pll_languages_row_classes', array(), $item );
50 44 echo '<tr' . ( empty( $classes ) ? '>' : ' class="' . esc_attr( implode( ' ', $classes ) ) . '">' );
51 45 $this->single_row_columns( $item );
@@ -52,17 +46,17 @@
52 46 echo '</tr>';
53 47 }
54 48
55 49 /**
56 - * Displays the item information in a column ( default case ).
50 + * Displays the item information in a column ( default case )
57 51 *
58 52 * @since 0.1
59 53 *
60 - * @param PLL_Language $item The language item.
61 - * @param string $column_name The column name.
62 - * @return string|int
54 + * @param object $item
55 + * @param string $column_name
56 + * @return string
63 57 */
64 - public function column_default( $item, $column_name ) {
58 + function column_default( $item, $column_name ) {
65 59 switch ( $column_name ) {
66 60 case 'locale':
67 61 case 'slug':
68 62 return esc_html( $item->$column_name );
@@ -71,9 +65,9 @@
71 65 case 'count':
72 66 return (int) $item->$column_name;
73 67
74 68 default:
75 - return $item->$column_name; // Flag.
69 + return $item->$column_name; // flag
76 70 }
77 71 }
78 72
79 73 /**
@@ -81,12 +75,12 @@
81 75 * Displays the edit and delete action links
82 76 *
83 77 * @since 0.1
84 78 *
85 - * @param PLL_Language $item The language item.
79 + * @param object $item
86 80 * @return string
87 81 */
88 - public function column_name( $item ) {
82 + function column_name( $item ) {
89 83 return sprintf(
90 84 '<a title="%s" href="%s">%s</a>',
91 85 esc_attr__( 'Edit this language', 'polylang' ),
92 86 esc_url( admin_url( 'admin.php?page=mlang&amp;pll_action=edit&amp;lang=' . $item->term_id ) ),
@@ -99,17 +93,17 @@
99 93 * Displays the 'make default' action link
100 94 *
101 95 * @since 1.8
102 96 *
103 - * @param PLL_Language $item The language item.
97 + * @param object $item
104 98 * @return string
105 99 */
106 - public function column_default_lang( $item ) {
100 + function column_default_lang( $item ) {
107 101 $options = get_option( 'polylang' );
108 102
109 103 if ( $options['default_lang'] != $item->slug ) {
110 - $s = sprintf(
111 - '<div class="row-actions"><span class="default-lang">
104 + $s = sprintf('
105 + <div class="row-actions"><span class="default-lang">
112 106 <a class="icon-default-lang" title="%1$s" href="%2$s"><span class="screen-reader-text">%3$s</span></a>
113 107 </span></div>',
114 108 esc_attr__( 'Select as default language', 'polylang' ),
115 109 wp_nonce_url( '?page=mlang&amp;pll_action=default-lang&amp;noheader=true&amp;lang=' . $item->term_id, 'default-lang' ),
@@ -117,14 +111,14 @@
117 111 esc_html( sprintf( __( 'Choose %s as default language', 'polylang' ), $item->name ) )
118 112 );
119 113
120 114 /**
121 - * Filters the default language row action in the languages list table.
115 + * Filter the default language row action in the languages list table
122 116 *
123 117 * @since 1.8
124 118 *
125 - * @param string $s The html markup of the action.
126 - * @param PLL_Language $item The language item.
119 + * @param string $s html markup of the action
120 + * @param object $item
127 121 */
128 122 $s = apply_filters( 'pll_default_lang_row_action', $s, $item );
129 123 } else {
130 124 $s = sprintf(
@@ -131,8 +125,9 @@
131 125 '<span class="icon-default-lang"><span class="screen-reader-text">%1$s</span></span>',
132 126 /* translators: accessibility text */
133 127 esc_html__( 'Default language', 'polylang' )
134 128 );
129 + $actions = array();
135 130 }
136 131
137 132 return $s;
138 133 }
@@ -141,11 +136,11 @@
141 136 * Gets the list of columns
142 137 *
143 138 * @since 0.1
144 139 *
145 - * @return string[] The list of column titles.
140 + * @return array the list of column titles
146 141 */
147 - public function get_columns() {
142 + function get_columns() {
148 143 return array(
149 144 'name' => esc_html__( 'Full name', 'polylang' ),
150 145 'locale' => esc_html__( 'Locale', 'polylang' ),
151 146 'slug' => esc_html__( 'Code', 'polylang' ),
@@ -162,15 +157,15 @@
162 157 * @since 0.1
163 158 *
164 159 * @return array
165 160 */
166 - public function get_sortable_columns() {
161 + function get_sortable_columns() {
167 162 return array(
168 - 'name' => array( 'name', true ), // sorted by name by default
169 - 'locale' => array( 'locale', false ),
170 - 'slug' => array( 'slug', false ),
171 - 'term_group' => array( 'term_group', false ),
172 - 'count' => array( 'count', false ),
163 + 'name' => array( 'name', true ), // sorted by name by default
164 + 'locale' => array( 'locale', false ),
165 + 'slug' => array( 'slug', false ),
166 + 'term_group' => array( 'term_group', false ),
167 + 'count' => array( 'count', false ),
173 168 );
174 169 }
175 170
176 171 /**
@@ -188,11 +183,11 @@
188 183 * Generates and display row actions links for the list table.
189 184 *
190 185 * @since 1.8
191 186 *
192 - * @param PLL_Language $item The language item being acted upon.
193 - * @param string $column_name Current column name.
194 - * @param string $primary Primary column name.
187 + * @param object $item The item being acted upon.
188 + * @param string $column_name Current column name.
189 + * @param string $primary Primary column name.
195 190 * @return string The row actions output.
196 191 */
197 192 protected function handle_row_actions( $item, $column_name, $primary ) {
198 193 if ( $primary !== $column_name ) {
@@ -203,9 +198,9 @@
203 198 'edit' => sprintf(
204 199 '<a title="%s" href="%s">%s</a>',
205 200 esc_attr__( 'Edit this language', 'polylang' ),
206 201 esc_url( admin_url( 'admin.php?page=mlang&amp;pll_action=edit&amp;lang=' . $item->term_id ) ),
207 - esc_html__( 'Edit', 'polylang' )
202 + esc_html__( 'Edit','polylang' )
208 203 ),
209 204 'delete' => sprintf(
210 205 '<a title="%s" href="%s" onclick = "return confirm( \'%s\' );">%s</a>',
211 206 esc_attr__( 'Delete this language and all its associated data', 'polylang' ),
@@ -210,19 +205,19 @@
210 205 '<a title="%s" href="%s" onclick = "return confirm( \'%s\' );">%s</a>',
211 206 esc_attr__( 'Delete this language and all its associated data', 'polylang' ),
212 207 wp_nonce_url( '?page=mlang&amp;pll_action=delete&amp;noheader=true&amp;lang=' . $item->term_id, 'delete-lang' ),
213 208 esc_js( __( 'You are about to permanently delete this language. Are you sure?', 'polylang' ) ),
214 - esc_html__( 'Delete', 'polylang' )
209 + esc_html__( 'Delete','polylang' )
215 210 ),
216 211 );
217 212
218 213 /**
219 - * Filters the list of row actions in the languages list table.
214 + * Filter the list of row actions in the languages list table
220 215 *
221 216 * @since 1.8
222 217 *
223 - * @param array $actions A list of html markup actions.
224 - * @param PLL_Language $item The language item.
218 + * @param array $actions list of html markup actions
219 + * @param object $item
225 220 */
226 221 $actions = apply_filters( 'pll_languages_row_actions', $actions, $item );
227 222
228 223 return $this->row_actions( $actions );
@@ -237,9 +232,9 @@
237 232 * @param object $b The second object to compare
238 233 * @return int -1 or 1 if $a is considered to be respectively less than or greater than $b.
239 234 */
240 235 protected function usort_reorder( $a, $b ) {
241 - $orderby = ! empty( $_GET['orderby'] ) ? sanitize_key( $_GET['orderby'] ) : 'name'; // phpcs:ignore WordPress.Security.NonceVerification
236 + $orderby = ! empty( $_GET['orderby'] ) ? $_GET['orderby'] : 'name';
242 237 // Determine sort order
243 238 if ( is_numeric( $a->$orderby ) ) {
244 239 $result = $a->$orderby > $b->$orderby ? 1 : -1;
245 240 } else {
@@ -245,9 +240,9 @@
245 240 } else {
246 241 $result = strcmp( $a->$orderby, $b->$orderby );
247 242 }
248 243 // Send final sort direction to usort
249 - return ( empty( $_GET['order'] ) || 'asc' === $_GET['order'] ) ? $result : -$result; // phpcs:ignore WordPress.Security.NonceVerification
244 + return ( empty( $_GET['order'] ) || 'asc' == $_GET['order'] ) ? $result : -$result;
250 245 }
251 246
252 247 /**
253 248 * Prepares the list of items for displaying
@@ -254,11 +249,10 @@
254 249 *
255 250 * @since 0.1
256 251 *
257 252 * @param array $data
258 - * @return void
259 253 */
260 - public function prepare_items( $data = array() ) {
254 + function prepare_items( $data = array() ) {
261 255 $per_page = $this->get_items_per_page( 'pll_lang_per_page' );
262 256 $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() );
263 257
264 258 usort( $data, array( $this, 'usort_reorder' ) );
@@ -265,13 +259,11 @@
265 259
266 260 $total_items = count( $data );
267 261 $this->items = array_slice( $data, ( $this->get_pagenum() - 1 ) * $per_page, $per_page );
268 262
269 - $this->set_pagination_args(
270 - array(
271 - 'total_items' => $total_items,
272 - 'per_page' => $per_page,
273 - 'total_pages' => ceil( $total_items / $per_page ),
274 - )
275 - );
263 + $this->set_pagination_args( array(
264 + 'total_items' => $total_items,
265 + 'per_page' => $per_page,
266 + 'total_pages' => ceil( $total_items / $per_page ),
267 + ) );
276 268 }
277 269 }