| @@ -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,16 +75,16 @@ | ||
| 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 | - esc_url( admin_url( 'admin.php?page=mlang&pll_action=edit&lang=' . $item->term_id ) ), | |
| 86 | + esc_url( admin_url( 'options-general.php?page=mlang&pll_action=edit&lang=' . $item->term_id ) ), | |
| 93 | 87 | esc_html( $item->name ) |
| 94 | 88 | ); |
| 95 | 89 | } |
| 96 | 90 | |
| @@ -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&pll_action=default-lang&noheader=true&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,37 +157,26 @@ | ||
| 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 | /** |
| 177 | - * Gets the name of the default primary column. | |
| 178 | - * | |
| 179 | - * @since 2.1 | |
| 180 | - * | |
| 181 | - * @return string Name of the default primary column, in this case, 'name'. | |
| 182 | - */ | |
| 183 | - protected function get_default_primary_column_name() { | |
| 184 | - return 'name'; | |
| 185 | - } | |
| 186 | - | |
| 187 | - /** | |
| 188 | 172 | * Generates and display row actions links for the list table. |
| 189 | 173 | * |
| 190 | 174 | * @since 1.8 |
| 191 | 175 | * |
| 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. | |
| 176 | + * @param object $item The item being acted upon. | |
| 177 | + * @param string $column_name Current column name. | |
| 178 | + * @param string $primary Primary column name. | |
| 195 | 179 | * @return string The row actions output. |
| 196 | 180 | */ |
| 197 | 181 | protected function handle_row_actions( $item, $column_name, $primary ) { |
| 198 | 182 | if ( $primary !== $column_name ) { |
| @@ -202,10 +186,10 @@ | ||
| 202 | 186 | $actions = array( |
| 203 | 187 | 'edit' => sprintf( |
| 204 | 188 | '<a title="%s" href="%s">%s</a>', |
| 205 | 189 | esc_attr__( 'Edit this language', 'polylang' ), |
| 206 | - esc_url( admin_url( 'admin.php?page=mlang&pll_action=edit&lang=' . $item->term_id ) ), | |
| 207 | - esc_html__( 'Edit', 'polylang' ) | |
| 190 | + esc_url( admin_url( 'options-general.php?page=mlang&pll_action=edit&lang=' . $item->term_id ) ), | |
| 191 | + esc_html__( 'Edit','polylang' ) | |
| 208 | 192 | ), |
| 209 | 193 | 'delete' => sprintf( |
| 210 | 194 | '<a title="%s" href="%s" onclick = "return confirm( \'%s\' );">%s</a>', |
| 211 | 195 | esc_attr__( 'Delete this language and all its associated data', 'polylang' ), |
| @@ -210,19 +194,19 @@ | ||
| 210 | 194 | '<a title="%s" href="%s" onclick = "return confirm( \'%s\' );">%s</a>', |
| 211 | 195 | esc_attr__( 'Delete this language and all its associated data', 'polylang' ), |
| 212 | 196 | wp_nonce_url( '?page=mlang&pll_action=delete&noheader=true&lang=' . $item->term_id, 'delete-lang' ), |
| 213 | 197 | esc_js( __( 'You are about to permanently delete this language. Are you sure?', 'polylang' ) ), |
| 214 | - esc_html__( 'Delete', 'polylang' ) | |
| 198 | + esc_html__( 'Delete','polylang' ) | |
| 215 | 199 | ), |
| 216 | 200 | ); |
| 217 | 201 | |
| 218 | 202 | /** |
| 219 | - * Filters the list of row actions in the languages list table. | |
| 203 | + * Filter the list of row actions in the languages list table | |
| 220 | 204 | * |
| 221 | 205 | * @since 1.8 |
| 222 | 206 | * |
| 223 | - * @param array $actions A list of html markup actions. | |
| 224 | - * @param PLL_Language $item The language item. | |
| 207 | + * @param array $actions list of html markup actions | |
| 208 | + * @param object $item | |
| 225 | 209 | */ |
| 226 | 210 | $actions = apply_filters( 'pll_languages_row_actions', $actions, $item ); |
| 227 | 211 | |
| 228 | 212 | return $this->row_actions( $actions ); |
| @@ -237,9 +221,9 @@ | ||
| 237 | 221 | * @param object $b The second object to compare |
| 238 | 222 | * @return int -1 or 1 if $a is considered to be respectively less than or greater than $b. |
| 239 | 223 | */ |
| 240 | 224 | protected function usort_reorder( $a, $b ) { |
| 241 | - $orderby = ! empty( $_GET['orderby'] ) ? sanitize_key( $_GET['orderby'] ) : 'name'; // phpcs:ignore WordPress.Security.NonceVerification | |
| 225 | + $orderby = ! empty( $_GET['orderby'] ) ? $_GET['orderby'] : 'name'; | |
| 242 | 226 | // Determine sort order |
| 243 | 227 | if ( is_numeric( $a->$orderby ) ) { |
| 244 | 228 | $result = $a->$orderby > $b->$orderby ? 1 : -1; |
| 245 | 229 | } else { |
| @@ -245,9 +229,9 @@ | ||
| 245 | 229 | } else { |
| 246 | 230 | $result = strcmp( $a->$orderby, $b->$orderby ); |
| 247 | 231 | } |
| 248 | 232 | // Send final sort direction to usort |
| 249 | - return ( empty( $_GET['order'] ) || 'asc' === $_GET['order'] ) ? $result : -$result; // phpcs:ignore WordPress.Security.NonceVerification | |
| 233 | + return ( empty( $_GET['order'] ) || 'asc' == $_GET['order'] ) ? $result : -$result; | |
| 250 | 234 | } |
| 251 | 235 | |
| 252 | 236 | /** |
| 253 | 237 | * Prepares the list of items for displaying |
| @@ -254,11 +238,10 @@ | ||
| 254 | 238 | * |
| 255 | 239 | * @since 0.1 |
| 256 | 240 | * |
| 257 | 241 | * @param array $data |
| 258 | - * @return void | |
| 259 | 242 | */ |
| 260 | - public function prepare_items( $data = array() ) { | |
| 243 | + function prepare_items( $data = array() ) { | |
| 261 | 244 | $per_page = $this->get_items_per_page( 'pll_lang_per_page' ); |
| 262 | 245 | $this->_column_headers = array( $this->get_columns(), array(), $this->get_sortable_columns() ); |
| 263 | 246 | |
| 264 | 247 | usort( $data, array( $this, 'usort_reorder' ) ); |
| @@ -265,13 +248,11 @@ | ||
| 265 | 248 | |
| 266 | 249 | $total_items = count( $data ); |
| 267 | 250 | $this->items = array_slice( $data, ( $this->get_pagenum() - 1 ) * $per_page, $per_page ); |
| 268 | 251 | |
| 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 | - ); | |
| 252 | + $this->set_pagination_args( array( | |
| 253 | + 'total_items' => $total_items, | |
| 254 | + 'per_page' => $per_page, | |
| 255 | + 'total_pages' => ceil( $total_items / $per_page ), | |
| 256 | + ) ); | |
| 276 | 257 | } |
| 277 | 258 | } |