@@ -58,9 +58,59 @@ public function __construct( Visualizer_Plugin $plugin ) {
58
58
$ this ->_addAction ( 'admin_menu ' , 'registerAdminMenu ' );
59
59
$ this ->_addFilter ( 'media_view_strings ' , 'setupMediaViewStrings ' );
60
60
$ this ->_addFilter ( 'plugin_action_links ' , 'getPluginActionLinks ' , 10 , 2 );
61
- $ this ->_addFilter ( 'plugin_row_meta ' , 'getPluginMetaLinks ' , 10 , 2 );
61
+ $ this ->_addFilter ( 'visualizer_logger_data ' , 'getLoggerData ' );
62
+ $ this ->_addFilter ( 'visualizer_get_chart_counts ' , 'getChartCountsByTypeAndMeta ' );
62
63
}
63
64
65
+ /**
66
+ * Fetches the SDK logger data.
67
+ *
68
+ * @param array $data The default data that needs to be sent.
69
+ *
70
+ * @access public
71
+ */
72
+ public function getLoggerData ( $ data ) {
73
+ return $ this ->getChartCountsByTypeAndMeta ();
74
+ }
75
+
76
+ /**
77
+ * Fetches the types of charts created and their counts.
78
+ *
79
+ * @param array $meta_keys An array of name vs. meta keys - to return how many charts have these keys.
80
+ * @access private
81
+ */
82
+ public function getChartCountsByTypeAndMeta ( $ meta_keys = array () ) {
83
+ $ charts = array ();
84
+ $ charts ['chart_types ' ] = array ();
85
+ // the initial query arguments to fetch charts
86
+ $ query_args = array (
87
+ 'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
88
+ 'posts_per_page ' => 300 ,
89
+ 'fields ' => 'ids ' ,
90
+ 'no_rows_found ' => false ,
91
+ 'update_post_meta_cache ' => false ,
92
+ 'update_post_term_cache ' => false ,
93
+
94
+ );
95
+
96
+ $ query = new WP_Query ( $ query_args );
97
+ while ( $ query ->have_posts () ) {
98
+ $ chart_id = $ query ->next_post ();
99
+ $ type = get_post_meta ( $ chart_id , Visualizer_Plugin::CF_CHART_TYPE , true );
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
+ }
111
+ }
112
+ return $ charts ;
113
+ }
64
114
65
115
/**
66
116
* Enqueues media scripts and styles.
0 commit comments