state(); $page = max( 1, absint( $_GET['paged'] ?? 1 ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Publicly durable collection state does not change data. $per_page = 20; $offset = ( $page - 1 ) * $per_page; $table = "{$this->wpdb->prefix}senti_subscriptions"; if ( $state !== '' ) { $count_query = $this->wpdb->prepare( 'SELECT COUNT(*) FROM %i WHERE state = %s', $table, $state ); $list_query = $this->wpdb->prepare( 'SELECT * FROM %i WHERE state = %s ORDER BY created_gmt DESC LIMIT %d OFFSET %d', $table, $state, $per_page, $offset ); } else { $count_query = $this->wpdb->prepare( 'SELECT COUNT(*) FROM %i', $table ); $list_query = $this->wpdb->prepare( 'SELECT * FROM %i ORDER BY created_gmt DESC LIMIT %d OFFSET %d', $table, $per_page, $offset ); } // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Queries are prepared immediately above. $total = is_string( $count_query ) ? (int) $this->wpdb->get_var( $count_query ) : 0; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Queries are prepared immediately above. $subscribers = is_string( $list_query ) ? $this->wpdb->get_results( $list_query ) : []; $pagination = paginate_links( [ 'base' => add_query_arg( 'paged', '%#%' ), 'current' => $page, 'total' => max( 1, (int) ceil( $total / $per_page ) ), ] ); $context = [ 'state' => $state, 'subscribers' => is_array( $subscribers ) ? $subscribers : [], 'pagination' => is_string( $pagination ) ? $pagination : '', ]; require dirname( __DIR__, 2 ) . '/templates/admin/subscribers.php'; } private function state(): string { $state = isset( $_GET['state'] ) && is_string( $_GET['state'] ) ? sanitize_key( wp_unslash( $_GET['state'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- This request only filters a collection. return in_array( $state, [ 'pending', 'active', 'unsubscribed' ], true ) ? $state : ''; } }