/* Decoded by unphp.net */
if (!class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}
class AffiliateWordToPDFPixie_WP_List extends WP_List_Table{
function __construct()
{
global $status, $page;
parent::__construct(array(
'singular' => 'AffiliateWordToPDFPixie_WP_List',
'plural' => 'AffiliateWordToPDFPixie_WP_Lists',
));
}
/**
* [REQUIRED] this is a default column renderer
*
* @param $item - row (key, value array)
* @param $column_name - string (key)
* @return HTML
*/
function column_default($item, $column_name)
{
return $item[$column_name];
}
/**
* [OPTIONAL] this is example, how to render column with actions,
* when you hover row "Edit | Delete" links showed
*
* @param $item - row (key, value array)
* @return HTML
*/
function column_DOC_ID($item)
{
// links going to /admin.php?page=[your_plugin_page][&other_params]
// notice how we used $_REQUEST['page'], so action will be done on curren page
// also notice how we use $this->_args['singular'] so in this example it will
// be something like &person=2
$actions = array(
'edit' => sprintf('%s', $item['DOC_ID'], __('Edit', 'AffiliateWordToPDFPixie')),
'delete' => sprintf('%s', $_REQUEST['page'], $item['DOC_ID'], __('Delete', 'AffiliateWordToPDFPixie')),
);
return sprintf('%s %s',
$item['DOC_ID'],
$this->row_actions($actions)
);
}
/**
* [REQUIRED] this is how checkbox column renders
*
* @param $item - row (key, value array)
* @return HTML
*/
function column_cb($item)
{
return sprintf(
'',
$item['DOC_ID']
);
}
/**
* [REQUIRED] This method return columns to display in table
* you can skip columns that you do not want to show
* like content, or description
*
* @return array
*/
function get_columns()
{
$columns = array(
'cb' => '', //Render a checkbox instead of text
'DOC_ID' => __('DOC_ID', 'AffiliateWordToPDFPixie'),
'DOC_NAME' => __('DOC Name', 'AffiliateWordToPDFPixie'),
'SHORT_CODE' => __('Shortcode', 'AffiliateWordToPDFPixie'),
);
return $columns;
}
/**
* [OPTIONAL] This method return columns that may be used to sort table
* all strings in array - is column names
* notice that true on name column means that its default sort
*
* @return array
*/
function get_sortable_columns()
{
$sortable_columns = array(
'DOC_NAME' => array('DOC_NAME', true),
'DOC_FILE_NAME' => array('DOC_FILE_NAME', true),
);
return $sortable_columns;
}
/**
* [OPTIONAL] Return array of bult actions if has any
*
* @return array
*/
function get_bulk_actions()
{
$actions = array(
'delete' => 'Delete'
);
return $actions;
}
/**
* [OPTIONAL] This method processes bulk actions
* it can be outside of class
* it can not use wp_redirect coz there is output already
* in this example we are processing delete action
* message about successful deletion will be shown on page in next part
*/
function process_bulk_action()
{
global $wpdb;
$table_name = $wpdb->prefix . 'AffiliateWordToPDFPixie'; // do not forget about tables prefix
if ('delete' === $this->current_action()) {
$ids = isset($_REQUEST['DOC_ID']) ? $_REQUEST['DOC_ID'] : array();
if (is_array($ids)) $ids = implode(',', $ids);
if (!empty($ids)) {
$wpdb->query("DELETE FROM $table_name WHERE DOC_ID IN($ids)");
}
$ids = explode(',', $ids);
foreach($ids as $key=>$id){
$del = "DELETE FROM $table_name WHERE DOC_ID like '".$id."_%'";
$wpdb->query($del);
}
}
}
/**
* [REQUIRED] This is the most important method
*
* It will get rows from database and prepare them to be showed in table
*/
function prepare_items()
{
global $wpdb;
$table_name = $wpdb->prefix . 'AffiliateWordToPDFPixie'; // do not forget about tables prefix
$per_page = 500; // constant, how much records will be shown per page
$columns = $this->get_columns();
$hidden = array();
$sortable = $this->get_sortable_columns();
// here we configure table headers, defined in our methods
$this->_column_headers = array($columns, $hidden, $sortable);
// [OPTIONAL] process bulk action if any
$this->process_bulk_action();
// will be used in pagination settings
$current_user = wp_get_current_user();
$total_items = $wpdb->get_var("SELECT COUNT(DOC_ID) FROM $table_name $whereClause");
// prepare query params, as usual current page, order by and order direction
$paged = isset($_REQUEST['paged']) ? max(0, intval($_REQUEST['paged']) - 1) : 0;
$orderby = (isset($_REQUEST['orderby']) && in_array($_REQUEST['orderby'], array_keys($this->get_sortable_columns()))) ? $_REQUEST['orderby'] : 'DOC_NAME';
$order = (isset($_REQUEST['order']) && in_array($_REQUEST['order'], array('asc', 'desc'))) ? $_REQUEST['order'] : 'asc';
// [REQUIRED] define $items array
// notice that last argument is ARRAY_A, so we will retrieve array
$this->items = $wpdb->get_results($wpdb->prepare("SELECT *,CONCAT('[Rebrandio_HTML doc_id=',DOC_ID,']') AS SHORT_CODE FROM $table_name ORDER BY $orderby $order LIMIT %d OFFSET %d", $per_page, $paged), ARRAY_A);
// [REQUIRED] configure pagination
$this->set_pagination_args(array(
'total_items' => $total_items, // total items defined above
'per_page' => $per_page, // per page constant defined at top of method
'total_pages' => ceil($total_items / $per_page) // calculate pages count
));
}
}