Skip to content

Commit 73d8f4a

Browse files
Merge branch 'development' of https://github.com/codeinwp/visualizer into issue-524
2 parents 4e2c619 + a04b6e5 commit 73d8f4a

File tree

10 files changed

+38
-10
lines changed

10 files changed

+38
-10
lines changed

classes/Visualizer/Gutenberg/Block.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,9 @@ public function update_chart_data( $data ) {
520520
}
521521

522522
if ( $data['id'] && ! is_wp_error( $data['id'] ) ) {
523-
523+
if ( get_post_type( $data['id'] ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
524+
return new WP_Error( 'invalid_post_type', 'Invalid post type.' );
525+
}
524526
$chart_type = sanitize_text_field( $data['visualizer-chart-type'] );
525527
$source_type = sanitize_text_field( $data['visualizer-source'] );
526528

classes/Visualizer/Module.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,22 +395,38 @@ private function _getHTML( $rows ) {
395395
);
396396
}
397397

398+
/**
399+
* Disable revisions temporarily for visualizer post type.
400+
*/
401+
protected final function disableRevisionsTemporarily() {
402+
add_filter(
403+
'wp_revisions_to_keep', function( $num, $post ) {
404+
if ( $post->post_type === Visualizer_Plugin::CPT_VISUALIZER ) {
405+
return 0;
406+
}
407+
return $num;
408+
}, 10, 2
409+
);
410+
}
411+
398412
/**
399413
* Undo revisions for the chart, and if necessary, restore the earliest version.
400414
*
401415
* @return bool If any revisions were found.
402416
*/
403417
public final function undoRevisions( $chart_id, $restore = false ) {
404418
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'undoRevisions for %d with%s restore', $chart_id, ( $restore ? '' : 'out' ) ), 'debug', __FILE__, __LINE__ );
405-
419+
if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
420+
return false;
421+
}
406422
$revisions = wp_get_post_revisions( $chart_id, array( 'order' => 'ASC' ) );
407423
if ( count( $revisions ) > 1 ) {
408424
$revision_ids = array_keys( $revisions );
409425

410426
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'found %d revisions = %s', count( $revisions ), print_r( $revision_ids, true ) ), 'debug', __FILE__, __LINE__ );
411427

412428
// when we restore, a new revision is likely to be created. so, let's disable revisions for the time being.
413-
add_filter( 'wp_revisions_to_keep', '__return_false' );
429+
$this->disableRevisionsTemporarily();
414430

415431
if ( $restore ) {
416432
// restore to the oldest one i.e. the first one.
@@ -431,8 +447,11 @@ public final function undoRevisions( $chart_id, $restore = false ) {
431447
* If existing revisions exist for the chart, restore the earliest version and then create a new revision to initiate editing.
432448
*/
433449
public final function handleExistingRevisions( $chart_id, $chart ) {
434-
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'handleExistingRevisions for %d', $chart_id ), 'debug', __FILE__, __LINE__ );
435450

451+
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'handleExistingRevisions for %d', $chart_id ), 'debug', __FILE__, __LINE__ );
452+
if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
453+
return $chart_id;
454+
}
436455
// undo revisions.
437456
$revisions_found = $this->undoRevisions( $chart_id, true );
438457

classes/Visualizer/Module/Chart.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,8 @@ private function _handleDataAndSettingsPage() {
684684

685685
// 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.
686686
// we do not want any difference in data so disable revisions temporarily.
687-
add_filter( 'wp_revisions_to_keep', '__return_false' );
687+
$this->disableRevisionsTemporarily();
688+
688689
wp_update_post( $this->_chart->to_array() );
689690
}
690691
// save meta data only when it is NOT being canceled.

classes/Visualizer/Module/Setup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public function refresh_db_for_chart( $chart, $chart_id, $force = false ) {
301301

302302
$error = $source->get_error();
303303
if ( empty( $error ) ) {
304-
add_filter( 'wp_revisions_to_keep', '__return_false' );
304+
$this->disableRevisionsTemporarily();
305305
if ( $load_series ) {
306306
update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
307307
}

classes/Visualizer/Plugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
class Visualizer_Plugin {
2929

3030
const NAME = 'visualizer';
31-
const VERSION = '3.4.3';
31+
const VERSION = '3.4.4';
3232

3333
// custom post types
3434
const CPT_VISUALIZER = 'visualizer';

css/media.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Version: 3.4.3
2+
Version: 3.4.4
33
*/
44
#visualizer-library-view {
55
padding: 30px 10px 10px 30px;

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Plugin Name: Visualizer: Tables and Charts for WordPress
55
Plugin URI: https://themeisle.com/plugins/visualizer-charts-and-graphs-lite/
66
Description: A simple, easy to use and quite powerful tool to create, manage and embed interactive charts into your WordPress posts and pages. The plugin uses Google Visualization API to render charts, which supports cross-browser compatibility (adopting VML for older IE versions) and cross-platform portability to iOS and new Android releases.
7-
Version: 3.4.3
7+
Version: 3.4.4
88
Author: Themeisle
99
Author URI: http://themeisle.com
1010
License: GPL v2.0 or later

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "visualizer",
3-
"version": "3.4.3",
3+
"version": "3.4.4",
44
"description": "Visualizer Lite",
55
"repository": {
66
"type": "git",

tests/test-import.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ public function test_db_import() {
232232
* @access public
233233
*/
234234
public function fileProvider() {
235+
$this->assertFileExists( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples', 'Folder "samples" does not exist' );
236+
235237
$file = VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . 'bar.csv';
236238
list( $content, $series ) = $this->parseFile( $file );
237239

@@ -305,6 +307,8 @@ private function parseFile( $file, $multiplyValuesBy = 1 ) {
305307
* @access public
306308
*/
307309
public function urlProvider() {
310+
$this->assertFileExists( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples', 'Folder "samples" does not exist' );
311+
308312
$url = 'https://demo.themeisle.com/wp-content/plugins/visualizer/samples/bar.csv';
309313
$file = download_url( $url );
310314
list( $content, $series ) = $this->parseFile( $file );

tests/test-revisions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ public function test_chart_edit_save( $file_orig, $file_new ) {
272272
* @access public
273273
*/
274274
public function fileProvider() {
275+
$this->assertFileExists( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples', 'Folder "samples" does not exist' );
276+
275277
return array(
276278
array( VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . 'line.csv', VISUALIZER_ABSPATH . DIRECTORY_SEPARATOR . 'samples' . DIRECTORY_SEPARATOR . 'bar.csv' ),
277279
);

0 commit comments

Comments
 (0)