__('Option', 'advanced-database-cleaner'), //singular name of the listed records 'plural' => __('Options', '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_options(); $this->aDBc_print_page_content(); } /** Prepare options to display and count options for each category */ function aDBc_prepare_and_count_options(){ // Process bulk action if any before preparing options to display if(!isset($_POST['aDBc_new_search_button'])){ $this->process_bulk_action(); } // Prepare data aDBc_prepare_items_to_display($this->aDBc_options_to_display, $this->aDBc_options_categories_info, "options"); // Call WP prepare_items function $this->prepare_items(); } /** WP: Get columns */ function get_columns(){ $aDBc_belongs_to_toolip = " " . __('Indicates the creator of the option. It can be a plugin name, a theme name or WordPress itself.','advanced-database-cleaner') ." "; $columns = array( 'cb' => '', 'option_name' => __('Option name','advanced-database-cleaner'), 'option_value' => __('Value','advanced-database-cleaner'), 'option_autoload' => __('Autoload','advanced-database-cleaner'), 'site_id' => __('Site id','advanced-database-cleaner'), 'option_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 options to display $display_data = array_slice($this->aDBc_options_to_display,(($current_page-1) * $per_page), $per_page); $this->set_pagination_args( array( 'total_items' => count($this->aDBc_options_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 'option_name': case 'option_value': case 'option_autoload': case 'site_id': case 'option_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['site_id']."|".$item['option_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 options he/she selected if(isset($_POST['aDBc_options_to_delete'])){ if(function_exists('is_multisite') && is_multisite()){ // Prepare options to delete in organized array to minimize switching from blogs $options_to_delete = array(); foreach($_POST['aDBc_options_to_delete'] as $option){ $option_info = explode("|", $option); if(empty($options_to_delete[$option_info[0]])){ $options_to_delete[$option_info[0]] = array(); } array_push($options_to_delete[$option_info[0]], $option_info[1]); } // Delete options foreach($options_to_delete as $site_id => $options){ switch_to_blog($site_id); foreach($options as $option) { delete_option($option); } restore_current_blog(); } }else{ foreach($_POST['aDBc_options_to_delete'] as $option) { $aDBc_option_info = explode("|", $option); delete_option($aDBc_option_info[1]); } } // Update the message to show to the user $this->aDBc_message = __('Selected options cleaned successfully!', 'advanced-database-cleaner'); } } } /** Print the page content */ function aDBc_print_page_content(){ // Print a message if any if($this->aDBc_message != ""){ echo '

' . $this->aDBc_message . '

'; } ?>
aDBc_options_categories_info as $abreviation => $category_info){ $iterations++; $aDBc_new_URI = add_query_arg('aDBc_cat', $abreviation, $aDBc_new_URI);?> : '; } }?>
aDBc_options_categories_info['all']['count'] > 0){ echo '
' . __('Below the list of all your options. Please do not delete any option unless you really know what you are doing!','advanced-database-cleaner') . '
'; } if($_GET['aDBc_cat'] != 'all'){ echo '

' . __('This feature is available in Pro version only.', 'advanced-database-cleaner') . ' ' . __('Please upgrade to pro version', 'advanced-database-cleaner') . "" . '

'; } // Print the options $this->display(); ?>