1
|
|
|
<?php |
|
|
|
|
2
|
|
|
namespace PodloveSubscribeButton; |
3
|
|
|
|
4
|
|
|
if( ! class_exists( 'WP_List_Table' ) ){ |
|
|
|
|
5
|
|
|
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ); |
|
|
|
|
6
|
|
|
} |
7
|
|
|
|
8
|
|
|
class Button_List_Table extends \WP_List_Table { |
|
|
|
|
9
|
|
|
|
10
|
|
|
function __construct(){ |
|
|
|
|
11
|
|
|
global $status, $page; |
12
|
|
|
|
13
|
|
|
// Set parent defaults |
|
|
|
|
14
|
|
|
parent::__construct( array( |
15
|
|
|
'singular' => 'feed', // singular name of the listed records |
|
|
|
|
16
|
|
|
'plural' => 'feeds', // plural name of the listed records |
|
|
|
|
17
|
|
|
'ajax' => false // does this table support ajax? |
|
|
|
|
18
|
|
|
) ); |
19
|
|
|
} |
|
|
|
|
20
|
|
|
|
21
|
|
|
function column_name( $button ) { |
|
|
|
|
22
|
|
|
|
23
|
|
|
$actions = array( |
24
|
|
|
'edit' => Settings\Buttons::get_action_link( $button, __( 'Edit', 'podlove-subscribe-button' ), 'edit' ), |
25
|
|
|
'delete' => Settings\Buttons::get_action_link( $button, __( 'Delete', 'podlove-subscribe-button' ), 'confirm_delete' ) |
|
|
|
|
26
|
|
|
); |
27
|
|
|
|
28
|
|
|
return sprintf('%1$s %2$s', |
29
|
|
|
/*$1%s*/ $button->title . '<br><code>[podlove-subscribe-button button="' . $button->name . '"]</code>', |
30
|
|
|
/*$3%s*/ $this->row_actions( $actions ) |
31
|
|
|
); |
32
|
|
|
} |
|
|
|
|
33
|
|
|
|
34
|
|
|
function column_button_preview( $button ) { |
|
|
|
|
35
|
|
|
if ( ! $button->feeds ) |
|
|
|
|
36
|
|
|
return; |
37
|
|
|
|
38
|
|
|
$is_network = is_network_admin(); |
|
|
|
|
39
|
|
|
|
40
|
|
|
return "<div class='podlove-button-preview-container'>" |
41
|
|
|
. $button->render( |
42
|
|
|
'big', |
|
|
|
|
43
|
|
|
'false', |
|
|
|
|
44
|
|
|
get_option('podlove_subscribe_button_default_style', 'filled'), |
|
|
|
|
45
|
|
|
'rectangle' |
|
|
|
|
46
|
|
|
) |
|
|
|
|
47
|
|
|
. "</div>"; |
|
|
|
|
48
|
|
|
} |
|
|
|
|
49
|
|
|
|
50
|
|
|
function column_id( $button ) { |
|
|
|
|
51
|
|
|
return $button->id; |
52
|
|
|
} |
|
|
|
|
53
|
|
|
|
54
|
|
|
function get_columns(){ |
|
|
|
|
55
|
|
|
return array( |
56
|
|
|
'name' => __( 'Title & Shortcode', 'podlove-subscribe-button' ), |
|
|
|
|
57
|
|
|
'button_preview' => __( 'Preview', 'podlove-subscribe-button' ) |
|
|
|
|
58
|
|
|
); |
59
|
|
|
} |
|
|
|
|
60
|
|
|
|
61
|
|
|
function prepare_items() { |
|
|
|
|
62
|
|
|
// number of items per page |
|
|
|
|
63
|
|
|
$per_page = 1000; |
64
|
|
|
|
65
|
|
|
// define column headers |
|
|
|
|
66
|
|
|
$columns = $this->get_columns(); |
|
|
|
|
67
|
|
|
$hidden = array(); |
|
|
|
|
68
|
|
|
$sortable = $this->get_sortable_columns(); |
|
|
|
|
69
|
|
|
$this->_column_headers = array( $columns, $hidden, $sortable ); |
70
|
|
|
|
71
|
|
|
// retrieve data |
72
|
|
|
// TODO select data for current page only |
|
|
|
|
73
|
|
|
$data = ( is_network_admin() ? \PodloveSubscribeButton\Model\NetworkButton::all() : \PodloveSubscribeButton\Model\Button::all() ); |
74
|
|
|
|
75
|
|
|
// get current page |
|
|
|
|
76
|
|
|
$current_page = $this->get_pagenum(); |
77
|
|
|
// get total items |
|
|
|
|
78
|
|
|
$total_items = count( $data ); |
79
|
|
|
// extrage page for current page only |
|
|
|
|
80
|
|
|
$data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ) , $per_page ); |
|
|
|
|
81
|
|
|
// add items to table |
|
|
|
|
82
|
|
|
$this->items = $data; |
83
|
|
|
|
84
|
|
|
// register pagination options & calculations |
|
|
|
|
85
|
|
|
$this->set_pagination_args( array( |
86
|
|
|
'total_items' => $total_items, |
87
|
|
|
'per_page' => $per_page, |
88
|
|
|
'total_pages' => ceil( $total_items / $per_page ) |
|
|
|
|
89
|
|
|
) ); |
90
|
|
|
} |
|
|
|
|
91
|
|
|
|
92
|
|
|
} |