PluginProbe
Polylang / 0.5
Polylang v0.5
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 / include / list-table.php

list-table.php in Polylang 0.5, at include/list-table.php

106 lines 3.4 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' ); // since WP 3.1
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 'flag':
23 case 'count':
24 return $item[$column_name];
25 default:
26 }
27 }
28
29 function column_name($item){
30 $edit_link = esc_url(admin_url('admin.php?page=mlang&amp;action=edit&amp;lang='.$item['term_id']));
31 $delete_link = wp_nonce_url('?page=mlang&amp;action=delete&amp;noheader=true&amp;lang=' . $item['term_id'], 'delete-lang');
32 $actions = array(
33 'edit' => '<a href="' . $edit_link . '">' . __('Edit','polylang') . '</a>',
34 'delete' => '<a href="' . $delete_link .'">' . __('Delete','polylang') .'</a>'
35 );
36
37 return $item['name'].$this->row_actions($actions);
38 }
39
40 function column_cb($item){
41 return sprintf(
42 '<input type="checkbox" name="%1$s[]" value="%2$s" />',
43 /*$1%s*/ esc_attr($this->_args['singular']),
44 /*$2%s*/ esc_attr($item['term_id'])
45 );
46 }
47
48 function get_columns(){
49 $columns = array(
50 // FIXME checkboxes are useles for now
51 // 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
52 'name' => __('Full name', 'polylang'),
53 'description' => __('Locale', 'polylang'),
54 'slug' => __('Code', 'polylang'),
55 'flag' => __('Flag', 'polylang'),
56 'count' => __('Posts', 'polylang')
57 );
58 return $columns;
59 }
60
61 function get_sortable_columns() {
62 $sortable_columns = array(
63 'name' => array('name',true), // sorted by name by default
64 'description' => array('description',false),
65 'slug' => array('slug',false),
66 'count' => array('count',false)
67 );
68 return $sortable_columns;
69 }
70
71 /*
72 function get_bulk_actions() {
73 return array('delete' => 'Delete');
74 }
75 */
76
77 function prepare_items($data = array()) {
78 $per_page = 5; // 5 languages per page
79 $columns = $this->get_columns();
80 $hidden = array();
81 $sortable = $this->get_sortable_columns();
82
83 $this->_column_headers = array($columns, $hidden, $sortable);
84
85 function usort_reorder($a,$b){
86 $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'name'; //If no sort, default to title
87 $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; //If no order, default to asc
88 $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
89 return ($order==='asc') ? $result : -$result; //Send final sort direction to usort
90 }
91 usort($data, 'usort_reorder');
92
93 $current_page = $this->get_pagenum();
94 $total_items = count($data);
95 $data = array_slice($data,(($current_page-1)*$per_page),$per_page);
96 $this->items = $data;
97
98 $this->set_pagination_args( array(
99 'total_items' => $total_items, //WE have to calculate the total number of items
100 'per_page' => $per_page, //WE have to determine how many items to show on a page
101 'total_pages' => ceil($total_items/$per_page) //WE have to calculate the total number of pages
102 ) );
103 }
104 }
105 ?>
106