PluginProbe
Polylang / 0.3
Polylang v0.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
polylang / list-table.php

list-table.php in Polylang 0.3, at list-table.php

103 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Thanks to Matt Van Andel (http://www.mattvanandel.com) for most of this code !
4
5 if(!class_exists('WP_List_Table')){
6 require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
7 }
8
9 class Polylang_List_Table extends WP_List_Table {
10 function __construct() {
11 parent::__construct( array(
12 'singular' => __('Language','polylang'),
13 'plural' => __('Languages','polylang'),
14 'ajax'=> false)
15 );
16 }
17
18 function column_default( $item, $column_name){
19 switch($column_name){
20 case 'description':
21 case 'slug':
22 case 'count':
23 return $item[$column_name];
24 default:
25 }
26 }
27
28 function column_name($item){
29 $edit_link = esc_url(admin_url('admin.php?page=mlang&amp;action=edit&amp;lang='.$item['term_id']));
30 $delete_link = wp_nonce_url('?page=mlang&amp;action=delete&amp;noheader=true&amp;lang=' . $item['term_id'], 'delete-lang');
31 $actions = array(
32 'edit' => '<a href="' . $edit_link . '">' . __('Edit','polylang') . '</a>',
33 'delete' => '<a href="' . $delete_link .'">' . __('Delete','polylang') .'</a>'
34 );
35
36 return $item['name'].$this->row_actions($actions);
37 }
38
39 function column_cb($item){
40 return sprintf(
41 '<input type="checkbox" name="%1$s[]" value="%2$s" />',
42 /*$1%s*/ esc_attr($this->_args['singular']),
43 /*$2%s*/ esc_attr($item['term_id'])
44 );
45 }
46
47 function get_columns(){
48 $columns = array(
49 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
50 'name' => __('Full name', 'polylang'),
51 'description' => __('Locale', 'polylang'),
52 'slug' => __('Code', 'polylang'),
53 'count' => __('Posts', 'polylang')
54 );
55 return $columns;
56 }
57
58 function get_sortable_columns() {
59 $sortable_columns = array(
60 'name' => array('name',true), // sorted by name by default
61 'description' => array('description',false),
62 'slug' => array('slug',false),
63 'count' => array('count',false)
64 );
65 return $sortable_columns;
66 }
67
68 /*
69 function get_bulk_actions() {
70 return array('delete' => 'Delete');
71 }
72 */
73
74 function prepare_items($data = array()) {
75 $per_page = 5; // 5 languages per page
76 $columns = $this->get_columns();
77 $hidden = array();
78 $sortable = $this->get_sortable_columns();
79
80 $this->_column_headers = array($columns, $hidden, $sortable);
81
82 function usort_reorder($a,$b){
83 $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'name'; //If no sort, default to title
84 $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; //If no order, default to asc
85 $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
86 return ($order==='asc') ? $result : -$result; //Send final sort direction to usort
87 }
88 usort($data, 'usort_reorder');
89
90 $current_page = $this->get_pagenum();
91 $total_items = count($data);
92 $data = array_slice($data,(($current_page-1)*$per_page),$per_page);
93 $this->items = $data;
94
95 $this->set_pagination_args( array(
96 'total_items' => $total_items, //WE have to calculate the total number of items
97 'per_page' => $per_page, //WE have to determine how many items to show on a page
98 'total_pages' => ceil($total_items/$per_page) //WE have to calculate the total number of pages
99 ) );
100 }
101 }
102 ?>
103