@@ -63,6 +63,9 @@ public function __construct( Visualizer_Plugin $plugin ) {
63
63
$ this ->_addFilter ( 'visualizer_get_chart_counts ' , 'getChartCountsByTypeAndMeta ' );
64
64
$ this ->_addFilter ( 'visualizer_feedback_review_trigger ' , 'feedbackReviewTrigger ' );
65
65
66
+ // screen pagination
67
+ $ this ->_addFilter ( 'set-screen-option ' , 'setScreenOptions ' , 10 , 3 );
68
+
66
69
// revision support.
67
70
$ this ->_addFilter ( 'wp_revisions_to_keep ' , 'limitRevisions ' , null , 10 , 2 );
68
71
$ this ->_addAction ( '_wp_put_post_revision ' , 'addRevision ' , null , 10 , 1 );
@@ -707,6 +710,36 @@ public function registerAdminMenu() {
707
710
array ( $ this , 'renderSupportPage ' )
708
711
);
709
712
remove_submenu_page ( Visualizer_Plugin::NAME , Visualizer_Plugin::NAME );
713
+
714
+ add_action ( "load- {$ this ->_libraryPage }" , array ( $ this , 'addScreenOptions ' ) );
715
+ }
716
+
717
+ /**
718
+ * Adds the screen options for pagination.
719
+ */
720
+ function addScreenOptions () {
721
+ $ screen = get_current_screen ();
722
+
723
+ // bail if it's some other page.
724
+ if ( ! is_object ( $ screen ) || $ screen ->id !== $ this ->_libraryPage ) {
725
+ return ;
726
+ }
727
+
728
+ $ args = array (
729
+ 'label ' => __ ( 'Number of charts per page: ' , 'visualizer ' ),
730
+ 'default ' => 6 ,
731
+ 'option ' => 'visualizer_per_page_library ' ,
732
+ );
733
+ add_screen_option ( 'per_page ' , $ args );
734
+ }
735
+
736
+ /**
737
+ * Returns the screen option for pagination.
738
+ */
739
+ function setScreenOptions ( $ status , $ option , $ value ) {
740
+ if ( 'visualizer_per_page_library ' === $ option ) {
741
+ return $ value ;
742
+ }
710
743
}
711
744
712
745
/**
@@ -730,10 +763,25 @@ private function getQuery() {
730
763
),
731
764
)
732
765
);
766
+
767
+ $ per_page = 6 ;
768
+ $ screen = get_current_screen ();
769
+ if ( $ screen ) {
770
+ // retrieve the per_page option
771
+ $ screen_option = $ screen ->get_option ( 'per_page ' , 'option ' );
772
+ // retrieve the value stored for the current user
773
+ $ user = get_current_user_id ();
774
+ $ per_page = get_user_meta ( $ user , $ screen_option , true );
775
+ if ( empty ( $ per_page ) || $ per_page < 1 ) {
776
+ // nothing set, get the default value
777
+ $ per_page = $ screen ->get_option ( 'per_page ' , 'default ' );
778
+ }
779
+ }
780
+
733
781
// the initial query arguments to fetch charts
734
782
$ query_args = array (
735
783
'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
736
- 'posts_per_page ' => 6 ,
784
+ 'posts_per_page ' => $ per_page ,
737
785
'paged ' => $ page ,
738
786
);
739
787
// add chart type filter to the query arguments
0 commit comments