4

I have a custom wp_list_table to create my own table. Almost everything works perfect, but the bulk action button seems to be not working. It's proper displayed,but on click nothing happens. I think somehow there is a form-wrapper missing or just some javascript? I added the button described on wp-engineeers: http://wpengineer.com/2426/wp_list_table-a-step-by-step-guide/#bulk

My Bulk-action functions:

function get_bulk_actions() {
    $actions = array(
        'activate'    => __('Show'),
        'deactivate'  => __('Hide')
    );
    //Add delete function for admins
    if(current_user_can( 'delete_published_posts' )){
        $actions['delete'] = __('Delete');
    }
    return $actions;
 }

    function process_bulk_action() {

        $action = $this->current_action();
        if( 'activate'===$action ) {

          foreach($_GET['wp_list_event'] as $event) {
                echo($event['title']);
            }

        }
        if( 'deactivate'===$action ) {
          wp_die('Items deactivated (or they would be if we had items to deactivate)!');
        }
        //Detect when a bulk action is being triggered...
        if( 'delete'===$action ) {
          wp_die('Items deleted (or they would be if we had items to delete)!');
        }
    } 

The rendered HTML (not wrapped by any form tag)

<div class="alignleft actions">
  <select name='action'>
    <option value='-1' selected='selected'>Aktion wählen</option>
    <option value='activate'>Anzeigen</option>
    <option value='deactivate'>Verstecken</option>
  </select>
  <input type="submit" name="" id="doaction" class="button action" value="Übernehmen"  />
</div>

2 Answers 2

10

You need to wrap your table into form tag, otherwise your bulk action button won't work.

0
10

this lines from Custom List Table Example Plugin the solved the issue:

   <form id="events-filter" method="get">
    <input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
    <?php
      $wp_list_table->display();
    ?>
    </form>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.