diff --git a/simple-page-ordering.php b/simple-page-ordering.php index 57d3e99..2c02d6f 100644 --- a/simple-page-ordering.php +++ b/simple-page-ordering.php @@ -168,10 +168,31 @@ public static function load_edit_screen() { 'sort_by_order_link', ) ); + add_action( 'pre_get_posts', array( __CLASS__, 'filter_query' ) ); add_action( 'wp', array( __CLASS__, 'wp' ) ); add_action( 'admin_head', array( __CLASS__, 'admin_head' ) ); } + /** + * This is to enable pagination. + * + * @param WP_Query $query The WP_Query instance (passed by reference). + */ + public static function filter_query( $query ) { + if ( ! $query->is_main_query() ) { + return; + } + + // phpcs:ignore WordPress.Security.NonceVerification.Recommended + $is_simple_page_ordering = isset( $_GET['id'] ) ? 'simple-page-ordering' === $_GET['id'] : false; + + if ( ! $is_simple_page_ordering ) { + return; + } + + $query->set( 'posts_per_page', -1 ); + } + /** * when we load up our posts query, if we're actually sorting by menu order, initialize sorting scripts */ @@ -526,6 +547,7 @@ public static function sort_by_order_link( $views ) { if ( ! is_post_type_hierarchical( get_post_type() ) ) { $query_string = add_query_arg( 'orderby', 'menu_order title', $query_string ); $query_string = add_query_arg( 'order', 'asc', $query_string ); + $query_string = add_query_arg( 'id', 'simple-page-ordering', $query_string ); } $views['byorder'] = sprintf( '%s', esc_url( $query_string ), $class, __( 'Sort by Order', 'simple-page-ordering' ) ); diff --git a/tests/cypress/integration/admin.test.js b/tests/cypress/integration/admin.test.js index 315d52a..8b139d3 100644 --- a/tests/cypress/integration/admin.test.js +++ b/tests/cypress/integration/admin.test.js @@ -22,4 +22,19 @@ describe('Admin can login and make sure plugin is activated', () => { cy.visit('/wp-admin/edit.php?post_type=page'); cy.get('.subsubsub .byorder').should('have.text', 'Sort by Order'); }); + + it('Pagination is visible when Clicking "Sort by Order"', () => { + cy.login(); + cy.visit( '/wp-admin/edit.php?post_type=page' ); + cy.get( '#show-settings-link' ).click(); + cy.get( '#edit_page_per_page' ).clear().type( '2' ); + cy.get( '#screen-options-apply' ).click(); + cy.get( '.byorder' ).click(); + cy.get( '.pagination-links' ).should( 'be.visible' ); + + // Restore default pagination. + cy.get( '#show-settings-link' ).click(); + cy.get( '#edit_page_per_page' ).clear().type( '10' ); + cy.get( '#screen-options-apply' ).click(); + }); });