| @@ -306,11 +306,18 @@ | ||
| 306 | 306 | } |
| 307 | 307 | if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset( $_GET['nonce'] ) && wp_verify_nonce( $_GET['nonce'] ) ) { |
| 308 | 308 | if ( $this->_chart->post_status == 'auto-draft' ) { |
| 309 | 309 | $this->_chart->post_status = 'publish'; |
| 310 | + | |
| 311 | + // ensure that a revision is not created. If a revision is created it will have the proper data and the parent of the revision will have default data. | |
| 312 | + // we do not want any difference in data so disable revisions temporarily. | |
| 313 | + add_filter( 'wp_revisions_to_keep', '__return_false' ); | |
| 310 | 314 | wp_update_post( $this->_chart->to_array() ); |
| 311 | 315 | } |
| 312 | - update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $_POST ); | |
| 316 | + // save meta data only when it is NOT being canceled. | |
| 317 | + if ( ! ( isset( $_POST['cancel'] ) && 1 === intval( $_POST['cancel'] ) ) ) { | |
| 318 | + update_post_meta( $this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $_POST ); | |
| 319 | + } | |
| 313 | 320 | $render = new Visualizer_Render_Page_Send(); |
| 314 | 321 | $render->text = sprintf( '[visualizer id="%d"]', $this->_chart->ID ); |
| 315 | 322 | wp_iframe( array( $render, 'render' ) ); |
| 316 | 323 | |
| @@ -486,9 +493,22 @@ | ||
| 486 | 493 | $render->message = esc_html__( 'CSV file with chart data was not uploaded. Please, try again.', 'visualizer' ); |
| 487 | 494 | } |
| 488 | 495 | if ( $source ) { |
| 489 | 496 | if ( $source->fetch() ) { |
| 490 | - $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 | + } | |
| 491 | 511 | wp_update_post( $chart->to_array() ); |
| 492 | 512 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); |
| 493 | 513 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_SOURCE, $source->getSourceName() ); |
| 494 | 514 | update_post_meta( $chart->ID, Visualizer_Plugin::CF_DEFAULT_DATA, 0 ); |