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*/ sanitize_title($button->title) . '<br><code>[podlove-subscribe-button button="' . sanitize_text_field($button->name) . '"]</code>', |
|
|
|
|
30
|
|
|
/*$3%s*/ $this->row_actions( $actions ) |
31
|
|
|
); |
32
|
|
|
} |
|
|
|
|
33
|
|
|
|
34
|
|
|
function column_button_preview( $button ) { |
|
|
|
|
35
|
|
|
|
36
|
|
|
if ( ! $button->feeds ) { |
37
|
|
|
return '<code>' . __( 'No preview. Please set a feed.', 'podlove-subscribe-button' ) . '</code>'; |
38
|
|
|
} else { |
39
|
|
|
|
40
|
|
|
$preview = "<div class='podlove-button-preview-container'>"; |
|
|
|
|
41
|
|
|
$preview .= $button->render( |
42
|
|
|
'big', |
43
|
|
|
'false', |
44
|
|
|
get_option( 'podlove_subscribe_button_default_style', 'filled' ), |
45
|
|
|
'rectangle' |
46
|
|
|
); |
47
|
|
|
$preview .= "</div>"; |
|
|
|
|
48
|
|
|
|
49
|
|
|
return $preview; |
50
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
function column_id( $button ) { |
|
|
|
|
57
|
|
|
return $button->id; |
58
|
|
|
} |
|
|
|
|
59
|
|
|
|
60
|
|
|
function get_columns(){ |
|
|
|
|
61
|
|
|
return array( |
62
|
|
|
'name' => __( 'Title & Shortcode', 'podlove-subscribe-button' ), |
|
|
|
|
63
|
|
|
'button_preview' => __( 'Preview', 'podlove-subscribe-button' ), |
|
|
|
|
64
|
|
|
); |
65
|
|
|
} |
|
|
|
|
66
|
|
|
|
67
|
|
|
function prepare_items() { |
|
|
|
|
68
|
|
|
// number of items per page |
|
|
|
|
69
|
|
|
$per_page = 1000; |
70
|
|
|
|
71
|
|
|
// define column headers |
|
|
|
|
72
|
|
|
$columns = $this->get_columns(); |
|
|
|
|
73
|
|
|
$hidden = array(); |
|
|
|
|
74
|
|
|
$sortable = $this->get_sortable_columns(); |
|
|
|
|
75
|
|
|
$this->_column_headers = array( $columns, $hidden, $sortable ); |
76
|
|
|
|
77
|
|
|
// retrieve data |
78
|
|
|
// TODO select data for current page only |
|
|
|
|
79
|
|
|
$data = ( is_network_admin() ? \PodloveSubscribeButton\Model\NetworkButton::all() : \PodloveSubscribeButton\Model\Button::all() ); |
80
|
|
|
|
81
|
|
|
// get current page |
|
|
|
|
82
|
|
|
$current_page = $this->get_pagenum(); |
83
|
|
|
// get total items |
|
|
|
|
84
|
|
|
$total_items = count( $data ); |
85
|
|
|
// extrage page for current page only |
|
|
|
|
86
|
|
|
$data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ) , $per_page ); |
|
|
|
|
87
|
|
|
// add items to table |
|
|
|
|
88
|
|
|
$this->items = $data; |
89
|
|
|
|
90
|
|
|
// register pagination options & calculations |
|
|
|
|
91
|
|
|
$this->set_pagination_args( array( |
|
|
|
|
92
|
|
|
'total_items' => $total_items, |
93
|
|
|
'per_page' => $per_page, |
94
|
|
|
'total_pages' => ceil( $total_items / $per_page ) |
|
|
|
|
95
|
|
|
) ); |
|
|
|
|
96
|
|
|
} |
|
|
|
|
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|