Skip to content

Commit 140f6b1

Browse files
committed
fixes for revison wipe
1 parent 556ed88 commit 140f6b1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,9 @@ private function _getHTML( $rows ) {
402402
*/
403403
public final function undoRevisions( $chart_id, $restore = false ) {
404404
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'undoRevisions for %d with%s restore', $chart_id, ( $restore ? '' : 'out' ) ), 'debug', __FILE__, __LINE__ );
405-
405+
if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
406+
return false;
407+
}
406408
$revisions = wp_get_post_revisions( $chart_id, array( 'order' => 'ASC' ) );
407409
if ( count( $revisions ) > 1 ) {
408410
$revision_ids = array_keys( $revisions );
@@ -416,6 +418,7 @@ public final function undoRevisions( $chart_id, $restore = false ) {
416418
// restore to the oldest one i.e. the first one.
417419
wp_restore_post_revision( array_shift( $revision_ids ) );
418420
}
421+
remove_filter( 'wp_revisions_to_keep', '__return_false' );
419422

420423
// delete all revisions.
421424
foreach ( $revision_ids as $id ) {
@@ -431,8 +434,11 @@ public final function undoRevisions( $chart_id, $restore = false ) {
431434
* If existing revisions exist for the chart, restore the earliest version and then create a new revision to initiate editing.
432435
*/
433436
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__ );
435437

438+
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'handleExistingRevisions for %d', $chart_id ), 'debug', __FILE__, __LINE__ );
439+
if ( get_post_type( $chart_id ) !== Visualizer_Plugin::CPT_VISUALIZER ) {
440+
return $chart_id;
441+
}
436442
// undo revisions.
437443
$revisions_found = $this->undoRevisions( $chart_id, true );
438444

0 commit comments

Comments
 (0)