@@ -59,6 +59,7 @@ public function __construct( Visualizer_Plugin $plugin ) {
59
59
$ this ->_addFilter ( 'media_view_strings ' , 'setupMediaViewStrings ' );
60
60
$ this ->_addFilter ( 'plugin_action_links ' , 'getPluginActionLinks ' , 10 , 2 );
61
61
$ this ->_addFilter ( 'visualizer_logger_data ' , 'getLoggerData ' );
62
+ $ this ->_addFilter ( 'visualizer_get_chart_counts ' , 'getChartCountsByTypeAndMeta ' );
62
63
}
63
64
64
65
/**
@@ -69,31 +70,44 @@ public function __construct( Visualizer_Plugin $plugin ) {
69
70
* @access public
70
71
*/
71
72
public function getLoggerData ( $ data ) {
72
- return array (
73
- 'chart_types ' => $ this ->getChartTypesAndCounts (),
74
- 'wordpress_filters ' => '' ,
75
- );
73
+ return $ this ->getChartCountsByTypeAndMeta ();
76
74
}
77
75
78
76
/**
79
77
* Fetches the types of charts created and their counts.
80
78
*
79
+ * @param array $meta_keys An array of name vs. meta keys - to return how many charts have these keys.
81
80
* @access private
82
81
*/
83
- private function getChartTypesAndCounts () {
84
- $ charts = array ();
82
+ public function getChartCountsByTypeAndMeta ( $ meta_keys = array () ) {
83
+ $ charts = array ();
84
+ $ charts ['chart_types ' ] = array ();
85
85
// the initial query arguments to fetch charts
86
86
$ query_args = array (
87
87
'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
88
88
'posts_per_page ' => 300 ,
89
89
'fields ' => 'ids ' ,
90
+ 'no_rows_found ' => false ,
91
+ 'update_post_meta_cache ' => false ,
92
+ 'update_post_term_cache ' => false ,
93
+
90
94
);
91
95
92
96
$ query = new WP_Query ( $ query_args );
93
97
while ( $ query ->have_posts () ) {
94
98
$ chart_id = $ query ->next_post ();
95
99
$ type = get_post_meta ( $ chart_id , Visualizer_Plugin::CF_CHART_TYPE , true );
96
- $ charts [ $ type ] = isset ( $ charts [ $ type ] ) ? $ charts [ $ type ] + 1 : 1 ;
100
+ $ charts ['chart_types ' ][ $ type ] = isset ( $ charts ['chart_types ' ][ $ type ] ) ? $ charts ['chart_types ' ][ $ type ] + 1 : 1 ;
101
+ if ( ! empty ( $ meta_keys ) ) {
102
+ foreach ( $ meta_keys as $ name => $ key ) {
103
+ $ data = get_post_meta ( $ chart_id , $ key , true );
104
+ if ( ! empty ( $ data ) ) {
105
+ $ charts [ $ name ] = isset ( $ charts [ $ name ] ) ? $ charts [ $ name ] + 1 : 1 ;
106
+ } else {
107
+ $ charts [ $ name ] = 0 ;
108
+ }
109
+ }
110
+ }
97
111
}
98
112
return $ charts ;
99
113
}
0 commit comments