__('Table', 'advanced-database-cleaner'), //singular name of the listed records
'plural' => __('Tables', 'advanced-database-cleaner'), //plural name of the listed records
'ajax' => false //does this table support ajax?
));
if(isset($_POST['aDBc_new_search_button']) && $_GET['aDBc_cat'] == "all"){
$this->aDBc_message = __('This feature is available in Pro version only.', 'advanced-database-cleaner');
$this->aDBc_message .= " " . __('Please upgrade to pro version', 'advanced-database-cleaner') . "";
$this->aDBc_class_message = "aDBc-upgrade-msg";
}
$this->aDBc_prepare_and_count_tables();
$this->aDBc_print_page_content();
}
/** Prepare tables to display and count tables for each category */
function aDBc_prepare_and_count_tables(){
// Process bulk action if any before preparing tables to display
if(!isset($_POST['aDBc_new_search_button'])){
$this->process_bulk_action();
}
// Prepare data
aDBc_prepare_items_to_display($this->aDBc_tables_to_display, $this->aDBc_tables_categories_info, "tables");
// Call WP prepare_items function
$this->prepare_items();
}
/** WP: Get columns */
function get_columns(){
$aDBc_belongs_to_toolip = "
" . __('Indicates the creator of the table. It can be a plugin name, a theme name or WordPress itself.','advanced-database-cleaner') ."
";
$columns = array(
'cb' => '',
'table_prefix' => __('Prefix','advanced-database-cleaner'),
'table_name' => __('Table name','advanced-database-cleaner'),
'table_rows' => __('Rows','advanced-database-cleaner'),
'table_size' => __('Size','advanced-database-cleaner'),
'site_id' => __('Site id','advanced-database-cleaner'),
'table_belongs_to' => __('Belongs to','advanced-database-cleaner') . $aDBc_belongs_to_toolip
);
return $columns;
}
/** WP: Prepare items to display */
function prepare_items() {
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = array();
$this->_column_headers = array($columns, $hidden, $sortable);
$per_page = 50;
$current_page = $this->get_pagenum();
// Prepare sequence of tables to display
$display_data = array_slice($this->aDBc_tables_to_display,(($current_page-1) * $per_page), $per_page);
$this->set_pagination_args( array(
'total_items' => count($this->aDBc_tables_to_display),
'per_page' => $per_page
));
$this->items = $display_data;
}
/** WP: Get columns that should be hidden */
function get_hidden_columns(){
// If MU, nothing to hide, else hide Side ID column
if(function_exists('is_multisite') && is_multisite()){
return array();
}else{
return array('site_id');
}
}
/** WP: Column default */
function column_default($item, $column_name){
switch($column_name){
case 'table_prefix':
case 'table_name':
case 'table_rows':
case 'table_size':
case 'site_id':
case 'table_belongs_to':
return $item[$column_name];
default:
return print_r($item, true) ; //Show the whole array for troubleshooting purposes
}
}
/** WP: Column cb for check box */
function column_cb($item) {
return sprintf('', $item['table_prefix']."|".$item['table_name']);
}
/** WP: Get bulk actions */
function get_bulk_actions() {
$actions = array(
'delete' => __('Delete','advanced-database-cleaner')
);
return $actions;
}
/** WP: Message to display when no items found */
function no_items() {
if($_GET['aDBc_cat'] == "all"){
_e('No tasks found!','advanced-database-cleaner');
}else{
_e('Available in Pro version!', 'advanced-database-cleaner');
}
}
/** WP: Process bulk actions */
public function process_bulk_action() {
// security check!
if (isset($_POST['_wpnonce']) && !empty($_POST['_wpnonce'])){
$nonce = filter_input(INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING);
$action = 'bulk-' . $this->_args['plural'];
if (!wp_verify_nonce( $nonce, $action))
wp_die('Security check failed!');
}
$action = $this->current_action();
if($action == 'delete'){
// If the user wants to clean the tables he/she selected
if(isset($_POST['aDBc_tables_to_delete'])){
global $wpdb;
foreach($_POST['aDBc_tables_to_delete'] as $table) {
$table_info = explode("|", $table);
$wpdb->query("DROP TABLE " . $table_info[0].$table_info[1]);
}
// Update the message to show to the user
$this->aDBc_message = __('Selected tables cleaned successfully!', 'advanced-database-cleaner');
}
}
}
/** Print the page content */
function aDBc_print_page_content(){
// Print a message if any
if($this->aDBc_message != ""){
echo '