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