| @@ -526,10 +526,12 @@ | ||
| 526 | 526 | wp_redirect( add_query_arg( 'chart', (int) $chart_id ) ); |
| 527 | 527 | defined( 'WP_TESTS_DOMAIN' ) ? wp_die() : exit(); |
| 528 | 528 | } |
| 529 | 529 | |
| 530 | + $_POST['save_chart_image'] = isset( $_POST['save_chart_image'] ) && 'yes' === $_POST['save_chart_image'] ? true : false; | |
| 531 | + | |
| 530 | 532 | if ( isset( $_POST['chart-img'] ) && ! empty( $_POST['chart-img'] ) ) { |
| 531 | - $attachment_id = $this->save_chart_image( $_POST['chart-img'], $chart_id ); | |
| 533 | + $attachment_id = $this->save_chart_image( $_POST['chart-img'], $chart_id, $_POST['save_chart_image'] ); | |
| 532 | 534 | if ( $attachment_id ) { |
| 533 | 535 | update_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_IMAGE, $attachment_id ); |
| 534 | 536 | } |
| 535 | 537 | } |
| @@ -595,8 +597,16 @@ | ||
| 595 | 597 | // if the edit button is clicked. |
| 596 | 598 | $this->_chart = $this->handleExistingRevisions( $chart_id, $this->_chart ); |
| 597 | 599 | } |
| 598 | 600 | |
| 601 | + // Clear existing chart cache. | |
| 602 | + if ( isset( $_POST['save'] ) && 1 === intval( $_POST['save'] ) ) { | |
| 603 | + $cache_key = Visualizer_Plugin::CF_CHART_CACHE . '_' . $chart_id; | |
| 604 | + if ( get_transient( $cache_key ) ) { | |
| 605 | + delete_transient( $cache_key ); | |
| 606 | + } | |
| 607 | + } | |
| 608 | + | |
| 599 | 609 | switch ( $tab ) { |
| 600 | 610 | case 'settings': |
| 601 | 611 | $this->_handleDataAndSettingsPage(); |
| 602 | 612 | break; |
| @@ -1333,9 +1343,9 @@ | ||
| 1333 | 1343 | |
| 1334 | 1344 | $hours = filter_input( |
| 1335 | 1345 | INPUT_POST, |
| 1336 | 1346 | 'refresh', |
| 1337 | - FILTER_VALIDATE_INT, | |
| 1347 | + FILTER_VALIDATE_FLOAT, | |
| 1338 | 1348 | array( |
| 1339 | 1349 | 'options' => array( |
| 1340 | 1350 | 'min_range' => -1, |
| 1341 | 1351 | 'max_range' => apply_filters( 'visualizer_is_business', false ) ? PHP_INT_MAX : -1, |
| @@ -1342,9 +1352,9 @@ | ||
| 1342 | 1352 | ), |
| 1343 | 1353 | ) |
| 1344 | 1354 | ); |
| 1345 | 1355 | |
| 1346 | - if ( ! is_int( $hours ) ) { | |
| 1356 | + if ( ! is_numeric( $hours ) ) { | |
| 1347 | 1357 | $hours = -1; |
| 1348 | 1358 | } |
| 1349 | 1359 | |
| 1350 | 1360 | $render = new Visualizer_Render_Page_Update(); |
| @@ -1436,11 +1446,22 @@ | ||
| 1436 | 1446 | * Save chart image. |
| 1437 | 1447 | * |
| 1438 | 1448 | * @param string $base64_img Chart image. |
| 1439 | 1449 | * @param int $chart_id Chart ID. |
| 1450 | + * @param bool $save_attachment Save attachment. | |
| 1440 | 1451 | * @return attachment ID |
| 1441 | 1452 | */ |
| 1442 | - public function save_chart_image( $base64_img, $chart_id ) { | |
| 1453 | + public function save_chart_image( $base64_img, $chart_id, $save_attachment = true ) { | |
| 1454 | + // Delete old chart image. | |
| 1455 | + $old_attachment_id = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_IMAGE, true ); | |
| 1456 | + if ( $old_attachment_id ) { | |
| 1457 | + wp_delete_attachment( $old_attachment_id, true ); | |
| 1458 | + } | |
| 1459 | + | |
| 1460 | + if ( ! $save_attachment ) { | |
| 1461 | + return 0; | |
| 1462 | + } | |
| 1463 | + | |
| 1443 | 1464 | // Upload dir. |
| 1444 | 1465 | $upload_dir = wp_upload_dir(); |
| 1445 | 1466 | $upload_path = str_replace( '/', DIRECTORY_SEPARATOR, $upload_dir['path'] ) . DIRECTORY_SEPARATOR; |
| 1446 | 1467 | |
| @@ -1449,14 +1470,8 @@ | ||
| 1449 | 1470 | $decoded = base64_decode( $img ); |
| 1450 | 1471 | $filename = 'visualization-' . $chart_id . '.png'; |
| 1451 | 1472 | $file_type = 'image/png'; |
| 1452 | 1473 | $hashed_filename = $filename; |
| 1453 | - | |
| 1454 | - // Delete old chart image. | |
| 1455 | - $old_attachment_id = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_IMAGE, true ); | |
| 1456 | - if ( $old_attachment_id ) { | |
| 1457 | - wp_delete_attachment( $old_attachment_id, true ); | |
| 1458 | - } | |
| 1459 | 1474 | |
| 1460 | 1475 | // Save the image in the uploads directory. |
| 1461 | 1476 | require_once ABSPATH . '/wp-admin/includes/file.php'; |
| 1462 | 1477 | \WP_Filesystem(); |