Slight annoyance: when editing strings manually, saving them returns to page 1
-
Hi there,
This is not really a ‘bug’ per se, but just a minor annoyance. If you are translating strings manually, and happen to have a huge amount of them (it’s my case: I’m also using NextGEN Gallery, with a few hundreds of images, each of which needs a translation for both the title and the caption…), then, every time the changes are saved, the table is reset back to page 1 — and not to the page you were on. Of course it’s easy to remember the number of the page you’re on, to get back to it quickly by just typing the page number on the navigation bar, but it would still be nice to have it done automatically…
So I digged into the code. It was no surprise that you’re extending WP_List_Table, which makes a lot of sense ?? So, looking back at some examples from other plugins (I remember having used this trick myself at some point…), your prepare_items() method (in settings/table-settings.php) could have something like this (copied from a test plugin and adapted for your variable names):
/* Your own code for setting $this->_column_headers */ $per_page = 20; /* this seems to be what you're using, or maybe it's WP's default? You could also do $per_page = $this->get_pagination_arg('per_page'); which ought to work */ /* Let's figure out what page the user is currently * looking at. */ $current_page = $this->get_pagenum(); /** * REQUIRED for pagination. */ $total_items = count($items); /** * The WP_List_Table class does not handle pagination for us, so we need * to ensure that the data is trimmed to only the current page. We can use * array_slice() to */ $items = array_slice($items,(($current_page-1)*$per_page),$per_page); $this->items = $items; /** * REQUIRED. We also have to register our pagination options & calculations. */ $this->set_pagination_args( array( 'total_items' => $total_items, //WE have to calculate the total number of items 'per_page' => $per_page, //WE have to determine how many items to show on a page 'total_pages' => ceil($total_items/$per_page) //WE have to calculate the total number of pages ) );
This should theoretically send the user directly to the page s/he was editing, but I did not test it out. Unfortunately, the website where I need this most has been live for several years, and the last thing I wish is to break it… but I might set up a test site somewhere and see if this works.
- The topic ‘Slight annoyance: when editing strings manually, saving them returns to page 1’ is closed to new replies.