diff --git a/admin/class-recursivetable.php b/admin/class-recursivetable.php index f82c13d..6ff30e4 100644 --- a/admin/class-recursivetable.php +++ b/admin/class-recursivetable.php @@ -218,17 +218,18 @@ private static function array_to_html_table_recursive( array $arr ): string { $paged = filter_input( INPUT_GET, 'paged', FILTER_VALIDATE_INT ); $nonce = filter_input( INPUT_GET, 'nonce', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); - $paged = $paged && wp_verify_nonce( $nonce, 'google_ss2db_pagination' ) - ? $paged - : 1; + if ( $paged && ! wp_verify_nonce( $nonce, 'google_ss2db_pagination' ) ) { + $paged = 1; + } + + $paged = $paged ? $paged : 1; $limit = 24; $offset = ( $paged - 1 ) * $limit; $countsql = 'SELECT * FROM ' . GOOGLE_SS2DB_TABLE_NAME . ' ORDER BY date DESC'; - $allrows = count( $wpdb->get_results( $countsql ) ); // phpcs:ignore + $allrows = count( $wpdb->get_results( $countsql ) ); // phpcs:ignore $max_num_pages = ceil( $allrows / $limit ); - // $sql = 'SELECT * FROM ' . GOOGLE_SS2DB_TABLE_NAME . ' ORDER BY date DESC LIMIT ' . $offset . ', ' . $limit; - $sql = 'SELECT * FROM ' . $table . ' ORDER BY date DESC LIMIT %d OFFSET %d'; - $prepared = $wpdb->prepare( + $sql = 'SELECT * FROM ' . $table . ' ORDER BY date DESC LIMIT %d OFFSET %d'; + $prepared = $wpdb->prepare( $sql, // phpcs:ignore $limit, $offset @@ -287,8 +288,14 @@ private static function array_to_html_table_recursive( array $arr ): string { diff --git a/functions/functions.php b/functions/functions.php index cb7322b..b3ded10 100644 --- a/functions/functions.php +++ b/functions/functions.php @@ -30,37 +30,74 @@ * This function generates HTML for a simple pagination interface, based on the current page, * total number of pages, and the range of pages to display around the current page. * - * @param int $paged Current page number, defaults to 1. - * @param int $pages Total number of pages, defaults to 1. - * @param int $range Number of pages to display around the current page, defaults to 2. + * @param int $paged Current page number, defaults to 1. + * @param int $pages Total number of pages, defaults to 1. + * @param int $range Number of pages to display around the current page, defaults to 2. + * @param string $nonce Nonce for security verification. * @return void */ -function google_ss2db_options_pagination( int $paged = 1, int $pages = 1, int $range = 2 ): void { +function google_ss2db_options_pagination( int $paged = 1, int $pages = 1, int $range = 2, string $nonce = '' ): void { $paged = intval( $paged ); $pages = intval( $pages ); $range = intval( $range ); $showitems = ( $range * 2 ) + 1; + $base_link = add_query_arg( + array( + 'paged' => 1, + 'nonce' => $nonce, + ), + remove_query_arg( array( 'paged', 'nonce' ) ) + ); + if ( 1 !== $pages ) { echo '