@@ -1254,13 +1254,24 @@ public function get_survey_metadata( $data, $page_slug ) {
1254
1254
$ plugin_version = $ plugin_data ['Version ' ];
1255
1255
}
1256
1256
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
+
1257
1267
$ data = array (
1258
1268
'environmentId ' => 'cltef8cut1s7wyyfxy3rlxzs5 ' ,
1259
1269
'attributes ' => array (
1260
1270
'free_version ' => $ plugin_version ,
1261
1271
'pro_version ' => defined ( 'VISUALIZER_PRO_VERSION ' ) ? VISUALIZER_PRO_VERSION : '' ,
1262
1272
'license_status ' => $ license_status ,
1263
1273
'install_days_number ' => $ install_days_number ,
1274
+ 'charts_number ' => $ charts_number ,
1264
1275
),
1265
1276
);
1266
1277
@@ -1274,4 +1285,23 @@ public function get_survey_metadata( $data, $page_slug ) {
1274
1285
1275
1286
return $ data ;
1276
1287
}
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
+ }
1277
1307
}
0 commit comments