Skip to content

Commit

Permalink
Merge pull request #165 from 10up/fix/164
Browse files Browse the repository at this point in the history
fix/164: Show pagination when Sort by Order is clicked
  • Loading branch information
Sidsector9 authored Oct 5, 2023
2 parents ed8e540 + a34488b commit 1956eb6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
22 changes: 22 additions & 0 deletions simple-page-ordering.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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( '<a href="%s" class="%s">%s</a>', esc_url( $query_string ), $class, __( 'Sort by Order', 'simple-page-ordering' ) );

Expand Down
15 changes: 15 additions & 0 deletions tests/cypress/integration/admin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit 1956eb6

Please sign in to comment.