@@ -1254,13 +1254,24 @@ public function get_survey_metadata( $data, $page_slug ) {
12541254 $ plugin_version = $ plugin_data ['Version ' ];
12551255 }
12561256
1257+ $ count_charts_cache_key = 'visualizer_count_charts ' ;
1258+ $ charts_number = get_transient ( $ count_charts_cache_key );
1259+
1260+ if ( false === $ charts_number ) {
1261+ $ charts_number = $ this ->count_charts ( 100 );
1262+ set_transient ( $ count_charts_cache_key , $ charts_number , 100 === $ charts_number ? WEEK_IN_SECONDS : 6 * HOUR_IN_SECONDS );
1263+ } else {
1264+ $ charts_number = strval ( $ charts_number );
1265+ }
1266+
12571267 $ data = array (
12581268 'environmentId ' => 'cltef8cut1s7wyyfxy3rlxzs5 ' ,
12591269 'attributes ' => array (
12601270 'free_version ' => $ plugin_version ,
12611271 'pro_version ' => defined ( 'VISUALIZER_PRO_VERSION ' ) ? VISUALIZER_PRO_VERSION : '' ,
12621272 'license_status ' => $ license_status ,
12631273 'install_days_number ' => $ install_days_number ,
1274+ 'charts_number ' => $ charts_number ,
12641275 ),
12651276 );
12661277
@@ -1274,4 +1285,23 @@ public function get_survey_metadata( $data, $page_slug ) {
12741285
12751286 return $ data ;
12761287 }
1288+
1289+ /**
1290+ * Count the charts.
1291+ *
1292+ * @param int $limit The count limit (optional).
1293+ *
1294+ * @return int The number of charts.
1295+ */
1296+ public function count_charts ( $ limit = -1 ) {
1297+ $ args = array (
1298+ 'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
1299+ 'post_status ' => 'publish ' ,
1300+ 'posts_per_page ' => $ limit ,
1301+ 'fields ' => 'ids ' ,
1302+ );
1303+
1304+ $ query = new WP_Query ( $ args );
1305+ return $ query ->post_count ;
1306+ }
12771307}
0 commit comments