Skip to content

Commit 9943ec1

Browse files
dparker1005claude
andcommitted
Fix Screen Options clearing filters on list table pages
WP_List_Table::display_tablenav() calls wp_nonce_field() with $referer=true by default, adding a _wp_http_referer hidden field to the GET form. When filters are applied, this stale referer (pointing to the pre-filter URL) ends up in the URL. The Screen Options form has no _wp_http_referer of its own, so WordPress picks up the stale GET value and redirects to the old URL, losing all active filters and search. Override display_tablenav() in all four PMPro list table classes, passing false for the $referer parameter in wp_nonce_field(). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 872785e commit 9943ec1

4 files changed

Lines changed: 120 additions & 0 deletions

classes/class-pmpro-discount-code-list-table.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,36 @@ public function set_screen_option( $dummy, $option, $value ) {
9090
}
9191
}
9292

93+
/**
94+
* Override display_tablenav to prevent _wp_http_referer from being added
95+
* to the form. The stale referer in the URL causes Screen Options to
96+
* redirect to the pre-filter page, clearing all active filters.
97+
*
98+
* @since TBD
99+
*
100+
* @param string $which The location of the tablenav: 'top' or 'bottom'.
101+
*/
102+
protected function display_tablenav( $which ) {
103+
if ( 'bottom' === $which && ! $this->has_items() ) {
104+
return;
105+
}
106+
if ( 'top' === $which ) {
107+
wp_nonce_field( 'bulk-' . $this->_args['plural'], '_wpnonce', false );
108+
}
109+
?>
110+
<div class="tablenav <?php echo esc_attr( $which ); ?>">
111+
<?php if ( $this->has_items() ) : ?>
112+
<div class="alignleft actions bulkactions">
113+
<?php $this->bulk_actions( $which ); ?>
114+
</div>
115+
<?php endif; ?>
116+
<?php $this->extra_tablenav( $which ); ?>
117+
<?php $this->pagination( $which ); ?>
118+
<br class="clear" />
119+
</div>
120+
<?php
121+
}
122+
93123
/**
94124
* Prepares the list of items for displaying.
95125
*

classes/class-pmpro-members-list-table.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,36 @@ public function set_screen_option( $dummy, $option, $value ) {
9090
}
9191
}
9292

93+
/**
94+
* Override display_tablenav to prevent _wp_http_referer from being added
95+
* to the form. The stale referer in the URL causes Screen Options to
96+
* redirect to the pre-filter page, clearing all active filters.
97+
*
98+
* @since TBD
99+
*
100+
* @param string $which The location of the tablenav: 'top' or 'bottom'.
101+
*/
102+
protected function display_tablenav( $which ) {
103+
if ( 'bottom' === $which && ! $this->has_items() ) {
104+
return;
105+
}
106+
if ( 'top' === $which ) {
107+
wp_nonce_field( 'bulk-' . $this->_args['plural'], '_wpnonce', false );
108+
}
109+
?>
110+
<div class="tablenav <?php echo esc_attr( $which ); ?>">
111+
<?php if ( $this->has_items() ) : ?>
112+
<div class="alignleft actions bulkactions">
113+
<?php $this->bulk_actions( $which ); ?>
114+
</div>
115+
<?php endif; ?>
116+
<?php $this->extra_tablenav( $which ); ?>
117+
<?php $this->pagination( $which ); ?>
118+
<br class="clear" />
119+
</div>
120+
<?php
121+
}
122+
93123
/**
94124
* Prepares the list of items for displaying.
95125
*

classes/class-pmpro-orders-list-table.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,36 @@ public function set_screen_option( $dummy, $option, $value ) {
9595
}
9696
}
9797

98+
/**
99+
* Override display_tablenav to prevent _wp_http_referer from being added
100+
* to the form. The stale referer in the URL causes Screen Options to
101+
* redirect to the pre-filter page, clearing all active filters.
102+
*
103+
* @since TBD
104+
*
105+
* @param string $which The location of the tablenav: 'top' or 'bottom'.
106+
*/
107+
protected function display_tablenav( $which ) {
108+
if ( 'bottom' === $which && ! $this->has_items() ) {
109+
return;
110+
}
111+
if ( 'top' === $which ) {
112+
wp_nonce_field( 'bulk-' . $this->_args['plural'], '_wpnonce', false );
113+
}
114+
?>
115+
<div class="tablenav <?php echo esc_attr( $which ); ?>">
116+
<?php if ( $this->has_items() ) : ?>
117+
<div class="alignleft actions bulkactions">
118+
<?php $this->bulk_actions( $which ); ?>
119+
</div>
120+
<?php endif; ?>
121+
<?php $this->extra_tablenav( $which ); ?>
122+
<?php $this->pagination( $which ); ?>
123+
<br class="clear" />
124+
</div>
125+
<?php
126+
}
127+
98128
/**
99129
* Prepares the list of items for displaying.
100130
*

classes/class-pmpro-subscriptions-list-table.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,36 @@ public function set_screen_option( $dummy, $option, $value ) {
9090
}
9191
}
9292

93+
/**
94+
* Override display_tablenav to prevent _wp_http_referer from being added
95+
* to the form. The stale referer in the URL causes Screen Options to
96+
* redirect to the pre-filter page, clearing all active filters.
97+
*
98+
* @since TBD
99+
*
100+
* @param string $which The location of the tablenav: 'top' or 'bottom'.
101+
*/
102+
protected function display_tablenav( $which ) {
103+
if ( 'bottom' === $which && ! $this->has_items() ) {
104+
return;
105+
}
106+
if ( 'top' === $which ) {
107+
wp_nonce_field( 'bulk-' . $this->_args['plural'], '_wpnonce', false );
108+
}
109+
?>
110+
<div class="tablenav <?php echo esc_attr( $which ); ?>">
111+
<?php if ( $this->has_items() ) : ?>
112+
<div class="alignleft actions bulkactions">
113+
<?php $this->bulk_actions( $which ); ?>
114+
</div>
115+
<?php endif; ?>
116+
<?php $this->extra_tablenav( $which ); ?>
117+
<?php $this->pagination( $which ); ?>
118+
<br class="clear" />
119+
</div>
120+
<?php
121+
}
122+
93123
/**
94124
* Prepares the list of items for displaying.
95125
*

0 commit comments

Comments
 (0)