Skip to content

Commit 45fdfed

Browse files
committed
feat: add Screen Options for customisable log entries per page
The Syndication Logs page now supports WordPress Screen Options, allowing users to configure how many log entries they see per page (defaulting to 20). This brings the UX in line with standard WordPress admin tables like Posts, making the interface more familiar and customisable for users managing large numbers of syndication logs.
1 parent 1558ff7 commit 45fdfed

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

includes/class-syndication-logger-viewer.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function prepare_items() {
181181
usort( $filtered_data, array( $this, 'usort_reorder' ) );
182182

183183
// Paginate the filtered and sorted data.
184-
$per_page = $this->get_items_per_page( 'per_page' );
184+
$per_page = $this->get_items_per_page( 'syndication_logs_per_page', 20 );
185185
$current_page = $this->get_pagenum();
186186
$total_items = count( $filtered_data );
187187

@@ -287,18 +287,45 @@ class Syndication_Logger_Viewer {
287287

288288
public function __construct() {
289289
add_action( 'admin_menu', array( $this, 'add_menu_items' ) );
290+
add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 );
290291
}
291292

292293
public function add_menu_items(){
293294
$hook = add_submenu_page( 'edit.php?post_type=syn_site', 'Logs', 'Logs', 'activate_plugins', 'syndication_dashboard', array( $this, 'render_list_page' ) );
294295
add_action( "load-$hook", array( $this, 'initialize_list_table' ) );
295296
}
296297

298+
/**
299+
* Save the screen option value when submitted.
300+
*
301+
* @param mixed $status The current status (false by default).
302+
* @param string $option The option name.
303+
* @param mixed $value The option value.
304+
* @return mixed The value to save, or $status to skip saving.
305+
*/
306+
public function set_screen_option( $status, $option, $value ) {
307+
if ( 'syndication_logs_per_page' === $option ) {
308+
return absint( $value );
309+
}
310+
return $status;
311+
}
312+
297313
public function initialize_list_table() {
298314
if ( ! empty( $_POST['log_id'] ) && ( empty( $_GET['log_id'] ) || esc_attr( $_GET['log_id'] ) != esc_attr( $_POST['log_id'] ) ) ) {
299315
wp_safe_redirect( add_query_arg( array( 'log_id' => esc_attr( $_REQUEST['log_id'] ) ), wp_unslash($_SERVER['REQUEST_URI'] ) ) );
300316
exit;
301317
}
318+
319+
// Add screen options for items per page.
320+
add_screen_option(
321+
'per_page',
322+
array(
323+
'label' => __( 'Log entries', 'push-syndication' ),
324+
'default' => 20,
325+
'option' => 'syndication_logs_per_page',
326+
)
327+
);
328+
302329
$this->syndication_logger_table = new Syndication_Logger_List_Table();
303330
}
304331

0 commit comments

Comments
 (0)