From e3cf23d1774dfa2af4f78a52d59163a7ee473ab7 Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Fri, 29 Sep 2023 11:15:08 +0530 Subject: [PATCH 1/4] replace `title` with `post_title` in `menu_order` --- simple-page-ordering.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simple-page-ordering.php b/simple-page-ordering.php index 57d3e99..7e51e30 100644 --- a/simple-page-ordering.php +++ b/simple-page-ordering.php @@ -524,7 +524,7 @@ public static function sort_by_order_link( $views ) { $class = ( get_query_var( 'orderby' ) === 'menu_order title' ) ? 'current' : ''; $query_string = remove_query_arg( array( 'orderby', 'order' ) ); if ( ! is_post_type_hierarchical( get_post_type() ) ) { - $query_string = add_query_arg( 'orderby', 'menu_order title', $query_string ); + $query_string = add_query_arg( 'orderby', 'menu_order post_title', $query_string ); $query_string = add_query_arg( 'order', 'asc', $query_string ); } $views['byorder'] = sprintf( '%s', esc_url( $query_string ), $class, __( 'Sort by Order', 'simple-page-ordering' ) ); From d34a5966501e219766c528ae0a2f8ce377421e0c Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Fri, 29 Sep 2023 11:45:25 +0530 Subject: [PATCH 2/4] add E2E tests --- tests/cypress/integration/admin.test.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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(); + }); }); From 1073914fa10584cef1d9aa8e060a752f54fef91e Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Mon, 2 Oct 2023 11:28:16 +0530 Subject: [PATCH 3/4] set posts_per_page to -1 --- simple-page-ordering.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/simple-page-ordering.php b/simple-page-ordering.php index 7e51e30..8f842a7 100644 --- a/simple-page-ordering.php +++ b/simple-page-ordering.php @@ -168,10 +168,26 @@ 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 ) { + $is_simple_page_ordering = isset( $_GET['id'] ) ? 'simple-page-ordering' === sanitize_text_field( wp_unslash( $_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 */ @@ -524,8 +540,9 @@ public static function sort_by_order_link( $views ) { $class = ( get_query_var( 'orderby' ) === 'menu_order title' ) ? 'current' : ''; $query_string = remove_query_arg( array( 'orderby', 'order' ) ); if ( ! is_post_type_hierarchical( get_post_type() ) ) { - $query_string = add_query_arg( 'orderby', 'menu_order post_title', $query_string ); + $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' ) ); From a34488b14f222f437740acd6f3a6ba90fd877b7d Mon Sep 17 00:00:00 2001 From: Siddharth Thevaril Date: Wed, 4 Oct 2023 09:52:40 +0530 Subject: [PATCH 4/4] code review changes --- simple-page-ordering.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/simple-page-ordering.php b/simple-page-ordering.php index 8f842a7..2c02d6f 100644 --- a/simple-page-ordering.php +++ b/simple-page-ordering.php @@ -179,7 +179,12 @@ public static function load_edit_screen() { * @param WP_Query $query The WP_Query instance (passed by reference). */ public static function filter_query( $query ) { - $is_simple_page_ordering = isset( $_GET['id'] ) ? 'simple-page-ordering' === sanitize_text_field( wp_unslash( $_GET['id'] ) ) : false; + 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;