id, $ids, true ); } // End is_our_screen() /** * Get the saved per page value for the current user, or 0 if none * * @return int */ private function get_saved() : int { $value = absint( get_user_meta( get_current_user_id(), $this->key, true ) ); return in_array( $value, self::$choices, true ) ? $value : 0; } // End get_saved() /** * Save the selection from the dropdown and redirect to a clean URL * * @return void */ public function maybe_save() { if ( ! isset( $_GET[ $this->key ] ) || ! $this->is_our_screen( get_current_screen() ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return; } check_admin_referer( $this->key ); $value = absint( wp_unslash( $_GET[ $this->key ] ) ); if ( in_array( $value, self::$choices, true ) ) { update_user_meta( get_current_user_id(), $this->key, $value ); } wp_safe_redirect( remove_query_arg( [ $this->key, '_wpnonce', 'paged' ] ) ); exit; } // End maybe_save() /** * Apply the saved value to our post type list tables * * @param int $per_page * @param string $post_type * @return int */ public function filter_posts_per_page( $per_page, $post_type ) { if ( ! in_array( $post_type, [ HelpDocs::$post_type, Imports::$post_type ], true ) ) { return $per_page; } $saved = $this->get_saved(); return $saved ? $saved : $per_page; } // End filter_posts_per_page() /** * Apply the saved value to the Folders list table * * @param int $per_page * @return int */ public function filter_tags_per_page( $per_page ) { $screen = get_current_screen(); if ( ! $screen || $screen->id !== 'edit-' . Folders::$taxonomy ) { return $per_page; } $saved = $this->get_saved(); return $saved ? $saved : $per_page; } // End filter_tags_per_page() /** * Render the dropdown server side on our post type list tables * * @param string $which * @return void */ public function render_field( $which ) { $screen = get_current_screen(); if ( ! $screen || ! in_array( $screen->post_type, [ HelpDocs::$post_type, Imports::$post_type ], true ) ) { return; } $id = 'helpdocs-per-page-' . sanitize_key( $which ); $current = $this->get_saved() ?: self::$default; ?>