superspeedyplugins / issue-tracker

Submit bugs and feature requests for any of our plugins
0 stars 0 forks source link

Scalability pro add next page - previous page on products #122

Closed ned-bs closed 5 months ago

ned-bs commented 6 months ago

Remove SQL_CALC_ROWS remove pagination on admin page

"When WP_Query fetches posts/products, it also calculates the total number of matching items. This is useful to display at the top of your shop/page/edit.php, e.g. Showing 1 - 50 of 650,000. However, this count requires either an index scan or table scan. Removing it, can result in ultra-fast WP_Query speed. Depending on your setup, you may need to switch to the natural sort order above too for successful use of the indexes. Since most users only need to view page 1, this is a recommended option but you should be aware that page counts will be incorrect as a result. Because of this, most people combine this option with an infinite scroll plugin."

Also on edit.php, SQL_CALC_ROWS is used. If you remove it, you remove pagination on these pages, but searching is unaffected and your pages will load far faster.

Describe the solution you'd like It make admin panel fast but also remove functionality. What if add next page and previous page links on top of wp-admin products page. /wp-admin/edit.php?post_type=product It can help to move next page, even there is no next page it is harmless

voodoo911 commented 6 months ago

@ned-bs Can you pls clarify - its two tasks?

1 - remove "Showing 1 - 50 of 650,000" on front end and replace it via pagination buttons ? Pls, tell what theme you used, as not all themes return this info.

2 - in edit.php for post types remove default pagination and replace it with prev/next page button?

ned-bs commented 6 months ago

@voodoo911 I didn't understand what do you mean.

  1. We use generatepress theme.
  2. When SPRO removes pagination, we are not able to click somewhere to reach 2nd or 3rd page at backend. But when I add page number to URL by hand, that works.

In this case; Go to woocommerce products page (Or post, which I don't need) and add 2 buttons with next and previous page links.

  1. Define a Page Number variable. 0 by default.
  2. Put next page link ($pagenumber+1)
  3. Put previous page link ($pagenumber-1).

I guess, code should be something like this

<?php
/*
Plugin Name: Custom Admin Pagination for WooCommerce Products and Orders
Plugin URI:  https://yourwebsite.com
Description: Adds custom next and previous page buttons to the WooCommerce Products and Orders admin pages, at both the top and bottom of the lists.
Version:     1.0
Author:      Your Name
Author URI:  https://yourwebsite.com
*/

if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly.
}

// Only execute in admin dashboard
if (is_admin()) {
    add_action('admin_footer', 'custom_pagination_buttons');
}

function custom_pagination_buttons() {
    global $pagenow;

    // Ensure the script only runs on the WooCommerce product or order admin pages
    if ('edit.php' !== $pagenow || !in_array($_GET['post_type'], ['product', 'shop_order'])) {
        return;
    }

    // Determine the current page
    $page = isset($_GET['paged']) ? absint($_GET['paged']) : 1;

    // Generate the URLs for previous and next pages
    $prev_link = add_query_arg('paged', max(1, $page - 1));
    $next_link = add_query_arg('paged', $page + 1);

    // JavaScript to inject pagination buttons
    echo "<script type='text/javascript'>
            jQuery(document).ready(function($) {
                var paginationHTML = '<div style=\"padding: 10px 0; display: inline-block;\">";

    // Add 'Previous' button if not on the first page
    if ($page > 1) {
        paginationHTML += " <a href=\"" + '" . esc_url($prev_link) . "' + "\" class=\"button custom-pagination\">Previous Page</a>";
    }

    // Add 'Next' button
    paginationHTML += " <a href=\"" + '" . esc_url($next_link) . "' + "\" class=\"button custom-pagination\">Next Page</a>";
    paginationHTML += "</div>';

                // Prepend to top and append to bottom of the product or order list
                $('.tablenav.top').first().prepend(paginationHTML);
                $('.tablenav.bottom').last().append(paginationHTML);
            });
          </script>";
}
dhilditch commented 6 months ago

@voodoo911 -

When scalability pro remove admin SQL CALC ROWS is enabled, pagination on wp-admin > products or wp-admin orders etc is broken.

When that option is enabled, simply add a NEXT PAGE and PREVIOUS page button where the pagination used to be.

voodoo911 commented 6 months ago

@dhilditch Wrote you request about issue with pagination set

ned-bs commented 5 months ago

Hi, any plan?

voodoo911 commented 5 months ago

@ned-bs Fix already applied

ned-bs commented 5 months ago

I am on SPRO 5.53 and woocommerce 8.9.0, I don't see anything like next page or previous page on products page.

voodoo911 commented 5 months ago

image @dhilditch seems fix not merged yet?

dhilditch commented 5 months ago

Fixed in 5.55

ned-bs commented 5 months ago

Suggest to add it to media page too. /wp-admin/upload.php page