Skip to content

Commit e96395e

Browse files
build: test case fails
1 parent 63e1a06 commit e96395e

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

classes/Visualizer/Module.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,20 @@ 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
*
@@ -412,13 +426,12 @@ public final function undoRevisions( $chart_id, $restore = false ) {
412426
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'found %d revisions = %s', count( $revisions ), print_r( $revision_ids, true ) ), 'debug', __FILE__, __LINE__ );
413427

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

417431
if ( $restore ) {
418432
// restore to the oldest one i.e. the first one.
419433
wp_restore_post_revision( array_shift( $revision_ids ) );
420434
}
421-
remove_filter( 'wp_revisions_to_keep', '__return_false' );
422435

423436
// delete all revisions.
424437
foreach ( $revision_ids as $id ) {

classes/Visualizer/Module/Chart.php

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

666666
// 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.
667667
// we do not want any difference in data so disable revisions temporarily.
668-
add_filter( 'wp_revisions_to_keep', '__return_false' );
668+
$this->disableRevisionsTemporarily();
669+
669670
wp_update_post( $this->_chart->to_array() );
670671
}
671672
// 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
@@ -296,7 +296,7 @@ public function refresh_db_for_chart( $chart, $chart_id, $force = false ) {
296296

297297
$error = $source->get_error();
298298
if ( empty( $error ) ) {
299-
add_filter( 'wp_revisions_to_keep', '__return_false' );
299+
$this->disableRevisionsTemporarily();
300300
if ( $load_series ) {
301301
update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() );
302302
}

0 commit comments

Comments
 (0)