Subscribe2_List_Table

The Subscribe2 Subscribe2 List Table class.

Defined (1)

The class is defined in the following location(s).

/classes/class-s2-list-table.php  
  1. class Subscribe2_List_Table extends WP_List_Table { 
  2. function __construct() { 
  3. global $status, $page; 
  4.  
  5. parent::__construct( array( 
  6. 'singular' => 'subscriber',  
  7. 'plural' => 'subscribers',  
  8. 'ajax' => false 
  9. ) ); 
  10.  
  11. function column_default($item, $column_name) { 
  12. global $current_tab; 
  13. if ( $current_tab == 'registered' ) { 
  14. switch($column_name) { 
  15. case 'email': 
  16. return $item[$column_name]; 
  17. default: 
  18. return print_r($item, true); 
  19. } else { 
  20. switch($column_name) { 
  21. case 'email': 
  22. case 'date': 
  23. return $item[$column_name]; 
  24. default: 
  25. return print_r($item, true); 
  26.  
  27. function column_email($item) { 
  28. global $current_tab; 
  29. if ( $current_tab == 'registered' ) { 
  30. $actions = array('edit' => sprintf('<a href="?page=%s&email=%s">%s</a>', 's2', urlencode($item['email']), __('Edit', 'subscribe2'))); 
  31. return sprintf('%1$s %2$s', $item['email'], $this->row_actions($actions)); 
  32. } else { 
  33. global $mysubscribe2; 
  34. if ( '0' === $mysubscribe2->is_public($item['email']) ) { 
  35. return sprintf('<span style="color:#FF0000"><abbr title="' . $mysubscribe2->signup_ip($item['email']) . '">%1$s</abbr></span>', $item['email']); 
  36. } else { 
  37. return sprintf('<abbr title="' . $mysubscribe2->signup_ip($item['email']) . '">%1$s</abbr>', $item['email']); 
  38.  
  39. function column_cb($item) { 
  40. return sprintf('<input type="checkbox" name="%1$s[]" value="%2$s" />', $this->_args['singular'], $item['email']); 
  41.  
  42. function get_columns() { 
  43. global $current_tab; 
  44. if ( $current_tab == 'registered' ) { 
  45. if (is_multisite()) { 
  46. $columns = array( 
  47. 'email' => _x('Email', 'column name', 'subscribe2') 
  48. ); 
  49. } else { 
  50. $columns = array( 
  51. 'cb' => '<input type="checkbox" />',  
  52. 'email' => _x('Email', 'column name', 'subscribe2') 
  53. ); 
  54. } else { 
  55. $columns = array( 
  56. 'cb' => '<input type="checkbox" />',  
  57. 'email' => _x('Email', 'column name', 'subscribe2'),  
  58. 'date' => _x('Date', 'column name', 'subscribe2') 
  59. ); 
  60. return $columns; 
  61.  
  62. function get_sortable_columns() { 
  63. global $current_tab; 
  64. if ( $current_tab == 'registered' ) { 
  65. $sortable_columns = array('email' => array('email', true)); 
  66. } else { 
  67. $sortable_columns = array( 
  68. 'email' => array('email', true),  
  69. 'date' => array('date', false) 
  70. ); 
  71. return $sortable_columns; 
  72.  
  73. function get_bulk_actions() { 
  74. global $current_tab; 
  75. if ( $current_tab == 'registered' ) { 
  76. if (is_multisite()) { 
  77. return array(); 
  78. } else { 
  79. return array( 
  80. 'delete' => __('Delete', 'subscribe2') 
  81. ); 
  82. } else { 
  83. $actions = array( 
  84. 'delete' => __('Delete', 'subscribe2'),  
  85. 'toggle' => __('Toggle', 'subscribe2') 
  86. ); 
  87. return $actions; 
  88.  
  89. function pagination( $which ) { 
  90. if ( empty( $this->_pagination_args ) ) 
  91. return; 
  92.  
  93. extract( $this->_pagination_args, EXTR_SKIP ); 
  94.  
  95. $output = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items, 'subscribe2' ), number_format_i18n( $total_items ) ) . '</span>'; 
  96.  
  97. if ( isset($_POST['what']) ) { 
  98. $current = 1; 
  99. } else { 
  100. $current = $this->get_pagenum(); 
  101.  
  102. if ( version_compare($GLOBALS['wp_version'], '3.5', '<') ) { 
  103. $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 
  104. } else { 
  105. $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); 
  106.  
  107. $current_url = remove_query_arg( array('hotkeys_highlight_last', 'hotkeys_highlight_first'), $current_url ); 
  108.  
  109. if ( isset($what) ) { 
  110. $current_url = add_query_arg( array('what' => $what), $current_url ); 
  111. } elseif ( isset($_REQUEST['what']) ) { 
  112. $current_url = add_query_arg( array('what' => $_REQUEST['what']), $current_url ); 
  113.  
  114. if ( isset($_POST['s']) ) { 
  115. $current_url = add_query_arg( array('s' => $_POST['s']), $current_url ); 
  116.  
  117. $page_links = array(); 
  118.  
  119. $disable_first = $disable_last = ''; 
  120. if ( $current == 1 ) 
  121. $disable_first = ' disabled'; 
  122. if ( $current == $total_pages ) 
  123. $disable_last = ' disabled'; 
  124.  
  125. $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",  
  126. 'first-page' . $disable_first,  
  127. esc_attr__('Go to the first page', 'subscribe2'),  
  128. esc_url( remove_query_arg( 'paged', $current_url ) ),  
  129. '«' 
  130. ); 
  131.  
  132. $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",  
  133. 'prev-page' . $disable_first,  
  134. esc_attr__('Go to the previous page', 'subscribe2'),  
  135. esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),  
  136. '‹' 
  137. ); 
  138.  
  139. if ( 'bottom' == $which ) 
  140. $html_current_page = $current; 
  141. else 
  142. $html_current_page = sprintf( "<input class='current-page' title='%s' type='text' name='paged' value='%s' size='%d' />",  
  143. esc_attr__('Current page', 'subscribe2'),  
  144. $current,  
  145. strlen( $total_pages ) 
  146. ); 
  147.  
  148. $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) ); 
  149. $page_links[] = '<span class="paging-input">' . sprintf( _x('%1$s of %2$s', 'paging', 'subscribe2'), $html_current_page, $html_total_pages ) . '</span>'; 
  150.  
  151. $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",  
  152. 'next-page' . $disable_last,  
  153. esc_attr__('Go to the next page', 'subscribe2'),  
  154. esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),  
  155. '›' 
  156. ); 
  157.  
  158. $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",  
  159. 'last-page' . $disable_last,  
  160. esc_attr__('Go to the last page', 'subscribe2'),  
  161. esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),  
  162. '»' 
  163. ); 
  164.  
  165. $pagination_links_class = 'pagination-links'; 
  166. if ( ! empty( $infinite_scroll ) ) 
  167. $pagination_links_class = ' hide-if-js'; 
  168. $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>'; 
  169.  
  170. if ( $total_pages ) 
  171. $page_class = $total_pages < 2 ? ' one-page' : ''; 
  172. else 
  173. $page_class = ' no-pages'; 
  174.  
  175. $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>"; 
  176.  
  177. echo $this->_pagination; 
  178.  
  179. function prepare_items() { 
  180. global $mysubscribe2, $subscribers, $current_tab; 
  181. if ( is_int($mysubscribe2->subscribe2_options['entries']) ) { 
  182. $per_page = $mysubscribe2->subscribe2_options['entries']; 
  183. } else { 
  184. $per_page = 25; 
  185.  
  186. $columns = $this->get_columns(); 
  187. $hidden = array(); 
  188. $sortable = $this->get_sortable_columns(); 
  189. $this->_column_headers = array($columns, $hidden, $sortable); 
  190.  
  191. $data = array(); 
  192. if ( $current_tab == 'public' ) { 
  193. foreach((array)$subscribers as $email) { 
  194. $data[] = array('email' => $email, 'date' => $mysubscribe2->signup_date($email)); 
  195. } else { 
  196. foreach((array)$subscribers as $email) { 
  197. $data[] = array('email' => $email); 
  198.  
  199. function usort_reorder($a, $b) { 
  200. $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'email'; 
  201. $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; 
  202. $result = strcasecmp($a[$orderby], $b[$orderby]); 
  203. return ($order==='asc') ? $result : -$result; 
  204. usort($data, 'usort_reorder'); 
  205.  
  206. if ( isset($_POST['what']) ) { 
  207. $current_page = 1; 
  208. } else { 
  209. $current_page = $this->get_pagenum(); 
  210. $total_items = count($data); 
  211. $data = array_slice($data, (($current_page-1)*$per_page), $per_page); 
  212. $this->items = $data; 
  213.  
  214. $this->set_pagination_args( array( 
  215. 'total_items' => $total_items,  
  216. 'per_page' => $per_page,  
  217. 'total_pages' => ceil($total_items/$per_page) 
  218. ) );