WP-Custom-List-Table-With-Database-Example icon indicating copy to clipboard operation
WP-Custom-List-Table-With-Database-Example copied to clipboard

Crash when deleting a single item.

Open patrick-here opened this issue 2 years ago • 0 comments

Prashant, thanks very much for this plugin; it's very well done!

There is a serious error in cltd_example_persons_page_handler() - the code only works when deleting multiple items. I changed my code to look like this:

if ('delete' === $table->current_action()) {
    # WARNING: At this point, the type and value of $_REQUEST['id'] will depend on the number of items deleted as follows:
    #  one item: type will be string and value will be the id of the item deleted (eg: the 'id' field of the item)
#  more than one item: type will be array and the value will be an array !!!

    if (is_array($_REQUEST['id']) === false ) { /* a SINGLE ITEM was deleted - String type */
    $itemCount = 1;
    } else {         /* MULTIPLE ITEMS were deleted  - array type */
    $itemCount =  count($_REQUEST['id']));
    }
    $message = '<div class="updated below-h2" id="message"><p>' . sprintf(__('Items deleted: %d', 'cltd_example'), $itemCount) . '</p></div>';
}

Regards, Patrick

patrick-here avatar Dec 15 '22 04:12 patrick-here