@@ -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,94 @@ 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
+ }
743
+ }
744
+
745
+ /**
746
+ * Adds the display filters to be used in the meta_query while displaying the charts.
747
+ */
748
+ private function getDisplayFilters ( &$ query_args ) {
749
+ $ query = array ();
750
+
751
+ // add chart type filter to the query arguments
752
+ $ type = filter_input ( INPUT_GET , 'type ' );
753
+ if ( $ type && in_array ( $ type , Visualizer_Plugin::getChartTypes (), true ) ) {
754
+ $ query [] = array (
755
+ 'key ' => Visualizer_Plugin::CF_CHART_TYPE ,
756
+ 'value ' => $ type ,
757
+ 'compare ' => '= ' ,
758
+ );
759
+ }
760
+
761
+ // add chart library filter to the query arguments
762
+ $ library = filter_input ( INPUT_GET , 'library ' );
763
+ if ( $ library ) {
764
+ $ query [] = array (
765
+ 'key ' => Visualizer_Plugin::CF_CHART_LIBRARY ,
766
+ 'value ' => $ library ,
767
+ 'compare ' => '= ' ,
768
+ );
769
+ }
770
+
771
+ // add date filter to the query arguments
772
+ $ date = filter_input ( INPUT_GET , 'date ' );
773
+ $ possible = array_keys ( Visualizer_Plugin::getSupportedDateFilter () );
774
+ if ( $ date && in_array ( $ date , $ possible , true ) ) {
775
+ $ query_args ['date_query ' ] = array (
776
+ 'after ' => "$ date -1 day " ,
777
+ 'inclusive ' => true ,
778
+ );
779
+ }
780
+
781
+ // add source filter to the query arguments
782
+ $ source = filter_input ( INPUT_GET , 'source ' );
783
+ if ( $ source ) {
784
+ $ source = ucwords ( $ source );
785
+ $ source = "Visualizer_Source_ {$ source }" ;
786
+ $ query [] = array (
787
+ 'key ' => Visualizer_Plugin::CF_SOURCE ,
788
+ 'value ' => $ source ,
789
+ 'compare ' => '= ' ,
790
+ );
791
+ }
792
+
793
+ $ query_args ['meta_query ' ] = $ query ;
794
+
795
+ $ orderby = filter_input ( INPUT_GET , 'orderby ' );
796
+ $ order = filter_input ( INPUT_GET , 'order ' );
797
+ if ( $ orderby ) {
798
+ $ query_args ['order_by ' ] = $ orderby ;
799
+ }
800
+ $ query_args ['order ' ] = empty ( $ order ) ? 'desc ' : $ order ;
710
801
}
711
802
712
803
/**
@@ -730,25 +821,30 @@ private function getQuery() {
730
821
),
731
822
)
732
823
);
824
+
825
+ $ per_page = 6 ;
826
+ $ screen = get_current_screen ();
827
+ if ( $ screen ) {
828
+ // retrieve the per_page option
829
+ $ screen_option = $ screen ->get_option ( 'per_page ' , 'option ' );
830
+ // retrieve the value stored for the current user
831
+ $ user = get_current_user_id ();
832
+ $ per_page = get_user_meta ( $ user , $ screen_option , true );
833
+ if ( empty ( $ per_page ) || $ per_page < 1 ) {
834
+ // nothing set, get the default value
835
+ $ per_page = $ screen ->get_option ( 'per_page ' , 'default ' );
836
+ }
837
+ }
838
+
733
839
// the initial query arguments to fetch charts
734
840
$ query_args = array (
735
841
'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
736
- 'posts_per_page ' => 6 ,
842
+ 'posts_per_page ' => $ per_page ,
737
843
'paged ' => $ page ,
738
844
);
739
- // add chart type filter to the query arguments
740
- $ filter = filter_input ( INPUT_GET , 'type ' );
741
- if ( $ filter && in_array ( $ filter , Visualizer_Plugin::getChartTypes (), true ) ) {
742
- $ query_args ['meta_query ' ] = array (
743
- array (
744
- 'key ' => Visualizer_Plugin::CF_CHART_TYPE ,
745
- 'value ' => $ filter ,
746
- 'compare ' => '= ' ,
747
- ),
748
- );
749
- } else {
750
- $ filter = 'all ' ;
751
- }
845
+
846
+ $ this ->getDisplayFilters ( $ query_args );
847
+
752
848
// Added by Ash/Upwork
753
849
$ filterByMeta = filter_input ( INPUT_GET , 's ' , FILTER_SANITIZE_STRING );
754
850
if ( $ filterByMeta ) {
@@ -830,7 +926,7 @@ public function renderLibraryPage() {
830
926
}
831
927
832
928
$ series = apply_filters ( Visualizer_Plugin::FILTER_GET_CHART_SERIES , get_post_meta ( $ chart ->ID , Visualizer_Plugin::CF_SERIES , true ), $ chart ->ID , $ type );
833
- $ data = apply_filters ( Visualizer_Plugin:: FILTER_GET_CHART_DATA , unserialize ( html_entity_decode ( $ chart-> post_content ) ), $ chart -> ID , $ type );
929
+ $ data = self :: get_chart_data ( $ chart , $ type );
834
930
835
931
$ library = $ this ->load_chart_type ( $ chart ->ID );
836
932
0 commit comments