| @@ -493,9 +493,22 @@ | ||
| 493 | 493 | $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please, try again.', 'visualizer' ); |
| 494 | 494 | } |
| 495 | 495 | if ( $source ) { |
| 496 | 496 | if ( $source->fetch() ) { |
| 497 | - $chart->post_content = $source->getData(); | |
| 497 | + $content = $source->getData(); | |
| 498 | + $populate = true; | |
| 499 | + if ( is_string( $content ) && is_array( unserialize( $content ) ) ) { | |
| 500 | + $json = unserialize( $content ); | |
| 501 | + // if source exists, so should data. if source exists but data is blank, do not populate the chart. | |
| 502 | + // if we populate the data even if it is empty, the chart will show "Table has no columns". | |
| 503 | + if ( array_key_exists( 'source', $json ) && ! empty( $json['source'] ) && ( ! array_key_exists( 'data', $json ) || empty( $json['data'] ) ) ) { | |
| 504 | + do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'Not populating chart data as source exists (%s) but data is empty!', $json['source'] ), 'warn', __FILE__, __LINE__ ); | |
| 505 | + $populate = false; | |
| 506 | + } | |
| 507 | + } | |
| 508 | + if ( $populate ) { | |
| 509 | + $chart->post_content = $content; | |
| 510 | + } | |
| 498 | 511 | wp_update_post( $chart->to_array() ); |
| 499 | 512 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 500 | 513 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 501 | 514 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 ); |