Support » Plugin: Polylang » 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.

    https://wordpress.org/plugins/polylang/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Chrystl

    (@chrystl)

    Hi
    Could you please post it on GitHub, as a pull request? Thanks.

    Thread Starter Gwyneth Llewelyn

    (@gwynethllewelyn)

    @chrystl, you really want me to get involved more with this amazing plugin than I’m willing to 🙂

    So I’m going to decline your kind invitation and just add that anyone is allowed to cut & paste the above snippet and use it as their own without giving me credit, lol — I’m not after credit, just getting those very tiny, minor annoyances cleaned up; and there isn’t even any need to rush 🙂

    Plugin Author Chouby

    (@chouby)

    Hi!

    For your information, the problem was not there, but the issue will be fixed in v1.9.3 anyway. See https://github.com/polylang/polylang/issues/14

    Thread Starter Gwyneth Llewelyn

    (@gwynethllewelyn)

    Oh I see! Anyway, thanks so much for fixing it 🙂 Awesome work!

    Thread Starter Gwyneth Llewelyn

    (@gwynethllewelyn)

    Oh my, I’m sorry, I’m reopening this again…

    I can confirm that saving the page will return to the correct page. So, yes, that’s fixed.

    But now the small input box which allows you to jump to a specific page is broken 🙁 More specifically: you can type a number for the page you wish to jump to, press Enter, but you will stay exactly on the page you were. So far I have tested this on the latest versions of Chrome, Safari, and Firefox, all on Mac OS X 10.11.6 Beta (15G19a).

    Note that I have on one website nothing less than 88 pages, so it’s a pain to step through each one of them until the end…

    This worked quite well under 1.9.2, so it seems that your fixes for the page saving issue somehow disabled the input box for directly jumping towards a specific page.

    Plugin Author Chouby

    (@chouby)

    🙁 What a mess! Sorry.
    I opened a new issue: https://github.com/polylang/polylang/issues/29
    I will fix that in the next version (not sure if it will be 2.0 for which we are closed to a beta, or 1.9.4).

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Slight annoyance: when editing strings manually, saving them returns to page 1’ is closed to new replies.