@@ -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 );
@@ -608,6 +611,36 @@ public function registerAdminMenu() {
608
611
array ( $ this , 'renderSupportPage ' )
609
612
);
610
613
remove_submenu_page ( Visualizer_Plugin::NAME , Visualizer_Plugin::NAME );
614
+
615
+ add_action ( "load- {$ this ->_libraryPage }" , array ( $ this , 'addScreenOptions ' ) );
616
+ }
617
+
618
+ /**
619
+ * Adds the screen options for pagination.
620
+ */
621
+ function addScreenOptions () {
622
+ $ screen = get_current_screen ();
623
+
624
+ // bail if it's some other page.
625
+ if ( ! is_object ( $ screen ) || $ screen ->id != $ this ->_libraryPage ) {
626
+ return ;
627
+ }
628
+
629
+ $ args = array (
630
+ 'label ' => __ ( 'Number of charts per page: ' , 'visualizer ' ),
631
+ 'default ' => 6 ,
632
+ 'option ' => 'visualizer_per_page_library ' ,
633
+ );
634
+ add_screen_option ( 'per_page ' , $ args );
635
+ }
636
+
637
+ /**
638
+ * Returns the screen option for pagination.
639
+ */
640
+ function setScreenOptions ( $ status , $ option , $ value ) {
641
+ if ( 'visualizer_per_page_library ' === $ option ) {
642
+ return $ value ;
643
+ }
611
644
}
612
645
613
646
/**
@@ -631,10 +664,25 @@ private function getQuery() {
631
664
),
632
665
)
633
666
);
667
+
668
+ $ per_page = 6 ;
669
+ $ screen = get_current_screen ();
670
+ if ( $ screen ) {
671
+ // retrieve the per_page option
672
+ $ screen_option = $ screen ->get_option ( 'per_page ' , 'option ' );
673
+ // retrieve the value stored for the current user
674
+ $ user = get_current_user_id ();
675
+ $ per_page = get_user_meta ( $ user , $ screen_option , true );
676
+ if ( empty ( $ per_page ) || $ per_page < 1 ) {
677
+ // nothing set, get the default value
678
+ $ per_page = $ screen ->get_option ( 'per_page ' , 'default ' );
679
+ }
680
+ }
681
+
634
682
// the initial query arguments to fetch charts
635
683
$ query_args = array (
636
684
'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
637
- 'posts_per_page ' => 6 ,
685
+ 'posts_per_page ' => $ per_page ,
638
686
'paged ' => $ page ,
639
687
);
640
688
// add chart type filter to the query arguments
0 commit comments