Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7541937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:01:37+00:00 2026-05-30T08:01:37+00:00

I’m working on a WordPress plugin, and part of that plugin requires extending WP_List_Table

  • 0

I’m working on a WordPress plugin, and part of that plugin requires extending WP_List_Table and storing any of the items which are checked in that table to an option. I’ve managed to figure out how to properly setup and display the required table, but how do I handle storing the checked options?

Here’s what I’ve got so far…

class TDBar_List_Table extends WP_List_Table {

    // Reference parent constructor
    function __construct() {
        global $status, $page;

        // Set defaults
        parent::__construct( array(
            'singular' => 'theme',
            'plural' => 'themes',
            'ajax' => false
        ));
    }

    // Set table classes
    function get_table_classes() {
        return array('widefat', 'wp-list-table', 'themes');
    }

    // Setup default column
    function column_default($item, $column_name) {
        switch($column_name) {
            case 'Title':
            case 'URI':
            case'Description':
                return $item[$column_name];
            default:
                return print_r($item, true);
        }
    }

    // Displaying checkboxes!
    function column_cb($item) {
        return sprintf(
            '<input type="checkbox" name="%1$s" id="%2$s" value="checked" />',
            //$this->_args['singular'],
            $item['Stylesheet'] . '_status',
            $item['Stylesheet'] . '_status'
        );
    }

    // Display theme title
    function column_title($item) {
        return sprintf(
            '<strong>%1$s</strong>',
            $item['Title']
        );
    }

    // Display theme preview
    function column_preview($item) {
        if (file_exists(get_theme_root() . '/' . $item['Stylesheet'] . '/screenshot.png')) {
            $preview = get_theme_root_uri() . '/' . $item['Stylesheet'] . '/screenshot.png';
        } else {
            $preview = '';
        }
            return sprintf(
                '<a href="%1$s" class="thickbox" title="%2$s"><img src="%3$s" style="width: 150px;" /></a>',
                $preview,
                $item['Title'],
                $preview
            );
    }

    // Display theme description
    function column_description($item) {
        if (isset($item['Version'])) {
            $version = 'Version ' . $item['Version'];
            if (isset($item['Author']) || isset($item['URI']))
                $version .= '&nbsp;|&nbsp;';
        } else {
            $version = '';
        }
        if (isset($item['Author'])) {
            $author = 'By ' . $item['Author'];
            if (isset($item['URI']))
                $author .= '&nbsp;|&nbsp;';
        } else {
            $author = '';
        }
        if (isset($item['URI'])) {
            $uri = $item['URI'];
        } else {
            $uri = '';
        }

        return sprintf(
            '<div class="theme-description"><p>%1$s</p></div><div class="second theme-version-author-uri">%2$s%3$s%4$s',
            $item['Description'],
            $version,
            $author,
            $uri
        );
    }

    // Setup columns
    function get_columns() {
        $columns = array(
            'cb' => '<input type="checkbox" />',
            'title' => 'Theme',
            'preview' => 'Preview',
            'description' => 'Description'
        );
        return $columns;
    }

    // Make title column sortable
    function get_sortable_columns() {
        $sortable_columns = array(
            'title' => array('Title', true)
        );
        return $sortable_columns;
    }

    // Setup bulk actions
    function get_bulk_actions() {
        $actions = array(
            'update' => 'Update'
        );
        return $actions;
    }

    // Handle bulk actions
    function process_bulk_action() {
        // Define our data source
        if (defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE == true) {
            $themes = get_allowed_themes();
        } else {
            $themes = get_themes();
        }

        if ('update' === $this->current_action()) {
            foreach ($themes as $theme) {
                if ($theme['Stylesheet'] . '_status' == 'checked') {
                    // Do stuff - here's the problem
                }
            }
        }
    }

    // Handle data preparation
    function prepare_items() {

        // How many records per page?
        $per_page = 10;

        // Define column headers
        $columns = $this->get_columns();
        $hidden = array();
        $sortable = $this->get_sortable_columns();

        // Build the array
        $this->_column_headers = array($columns, $hidden, $sortable);

        // Pass off bulk action
        $this->process_bulk_action();

        // Define our data source
        if (defined('WP_ALLOW_MULTISITE') && WP_ALLOW_MULTISITE == true) {
            $themes = get_allowed_themes();
        } else {
            $themes = get_themes();
        }

        // Handle sorting
        function usort_reorder($a,$b) {
            $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'Title';
            $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc';
            $result = strcmp($a[$orderby], $b[$orderby]);
            return ($order === 'asc') ? $result : -$result;
        }
        usort($themes, 'usort_reorder');

        //MAIN STUFF HERE
        //for ($i = 0; i < count($themes); $i++) {

        //}

        // Figure out the current page and how many items there are
        $current_page = $this->get_pagenum();
        $total_items = count($themes);

        // Only show the current page
        $themes = array_slice($themes,(($current_page-1)*$per_page),$per_page);

        // Display sorted data
        $this->items = $themes;

        // Register pagination options
        $this->set_pagination_args( array(
            'total_items' => $total_items,
            'per_page' => $per_page,
            'total_pages' => ceil($total_items/$per_page)
        ));
    }
}

Problem is, I can’t get it to save properly. I select the rows I want, hit save and it just resets.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:01:38+00:00Added an answer on May 30, 2026 at 8:01 am

    I assume you are talking about the checkboxes in your table listing, so this will be how to process bulk actions.

    All you need to do is add two new methods to your class and initialize it in the prepare_items method. I use the code below in one of my plugins to delete or export, but you can just as easily run an update.

    /**
     * Define our bulk actions
     * 
     * @since 1.2
     * @returns array() $actions Bulk actions
     */
    function get_bulk_actions() {
        $actions = array(
            'delete' => __( 'Delete' , 'visual-form-builder'),
            'export-all' => __( 'Export All' , 'visual-form-builder'),
            'export-selected' => __( 'Export Selected' , 'visual-form-builder')
        );
    
        return $actions;
    }
    
    /**
     * Process our bulk actions
     * 
     * @since 1.2
     */
    function process_bulk_action() {        
        $entry_id = ( is_array( $_REQUEST['entry'] ) ) ? $_REQUEST['entry'] : array( $_REQUEST['entry'] );
    
        if ( 'delete' === $this->current_action() ) {
            global $wpdb;
    
            foreach ( $entry_id as $id ) {
                $id = absint( $id );
                $wpdb->query( "DELETE FROM $this->entries_table_name WHERE entries_id = $id" );
            }
        }
    }
    

    Now, call this method inside prepare_items() like so:

    function prepare_items() {
           //Do other stuff in here
    
           /* Handle our bulk actions */
           $this->process_bulk_action();
    }
    

    There’s a fantastic helper plugin called Custom List Table Example that makes figuring out the WP_List_Table class much easier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.