@@ -237,6 +237,28 @@ public function deleteChart() {
237
237
exit ;
238
238
}
239
239
240
+ /**
241
+ * Delete charts that are still in auto-draft mode.
242
+ */
243
+ private function deleteOldCharts () {
244
+ $ query = new WP_Query (
245
+ array (
246
+ 'post_type ' => Visualizer_Plugin::CPT_VISUALIZER ,
247
+ 'post_status ' => 'auto-draft ' ,
248
+ 'fields ' => 'ids ' ,
249
+ 'update_post_meta_cache ' => false ,
250
+ 'update_post_term_cache ' => false ,
251
+ 'posts_per_page ' => 50 ,
252
+ )
253
+ );
254
+ if ( $ query ->have_posts () ) {
255
+ $ ids = array ();
256
+ while ( $ query ->have_posts () ) {
257
+ wp_delete_post ( $ query ->next_post (), true );
258
+ }
259
+ }
260
+ }
261
+
240
262
/**
241
263
* Renders appropriate page for chart builder. Creates new auto draft chart
242
264
* if no chart has been specified.
@@ -250,6 +272,7 @@ public function renderChartPages() {
250
272
// check chart, if chart not exists, will create new one and redirects to the same page with proper chart id
251
273
$ chart_id = isset ( $ _GET ['chart ' ] ) ? filter_var ( $ _GET ['chart ' ], FILTER_VALIDATE_INT ) : '' ;
252
274
if ( ! $ chart_id || ! ( $ chart = get_post ( $ chart_id ) ) || $ chart ->post_type != Visualizer_Plugin::CPT_VISUALIZER ) {
275
+ $ this ->deleteOldCharts ();
253
276
$ default_type = isset ( $ _GET ['type ' ] ) && ! empty ( $ _GET ['type ' ] ) ? $ _GET ['type ' ] : 'line ' ;
254
277
$ source = new Visualizer_Source_Csv ( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples ' . DIRECTORY_SEPARATOR . $ default_type . '.csv ' );
255
278
$ source ->fetch ();
0 commit comments