Skip to content

Commit 978cbfe

Browse files
handle front end charts
1 parent 7024d35 commit 978cbfe

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

classes/Visualizer/Module.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public function __construct( Visualizer_Plugin $plugin ) {
6363

6464
$this->_wpdb = $wpdb;
6565
$this->_plugin = $plugin;
66+
67+
$this->_addFilter( Visualizer_Plugin::FILTER_UNDO_REVISIONS, 'undoRevisions', 10, 2 );
68+
$this->_addFilter( Visualizer_Plugin::FILTER_HANDLE_REVISIONS, 'handleExistingRevisions', 10, 2 );
69+
6670
}
6771

6872
/**
@@ -328,11 +332,15 @@ private function _getHTML( $rows ) {
328332
*
329333
* @return bool If any revisions were found.
330334
*/
331-
protected function undoRevisions( $chart_id, $restore = false ) {
335+
public final function undoRevisions( $chart_id, $restore = false ) {
336+
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'undoRevisions for %d with%s restore', $chart_id, ( $restore ? '' : 'out' ) ), 'debug', __FILE__, __LINE__ );
337+
332338
$revisions = wp_get_post_revisions( $chart_id, array( 'order' => 'ASC' ) );
333339
if ( count( $revisions ) > 1 ) {
334340
$revision_ids = array_keys( $revisions );
335341

342+
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'found %d revisions = %s', count( $revisions ), print_r( $revision_ids, true ) ), 'debug', __FILE__, __LINE__ );
343+
336344
// when we restore, a new revision is likely to be created. so, let's disable revisions for the time being.
337345
add_filter( 'wp_revisions_to_keep', '__return_false' );
338346

@@ -354,7 +362,9 @@ protected function undoRevisions( $chart_id, $restore = false ) {
354362
/**
355363
* If existing revisions exist for the chart, restore the earliest version and then create a new revision to initiate editing.
356364
*/
357-
protected function handleExistingRevisions( $chart_id, $chart ) {
365+
public final function handleExistingRevisions( $chart_id, $chart ) {
366+
do_action( 'themeisle_log_event', Visualizer_Plugin::NAME, sprintf( 'handleExistingRevisions for %d', $chart_id ), 'debug', __FILE__, __LINE__ );
367+
358368
// undo revisions.
359369
$revisions_found = $this->undoRevisions( $chart_id, true );
360370

classes/Visualizer/Module/Frontend.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ public function renderChart( $atts ) {
197197
return '';
198198
}
199199

200+
// in case revisions exist.
201+
if ( true === ( $revisions = $this->undoRevisions( $chart->ID, true ) ) ) {
202+
$chart = get_post( $chart->ID );
203+
}
204+
200205
$id = 'visualizer-' . $atts['id'];
201206
$defaultClass = 'visualizer-front';
202207
$class = apply_filters( Visualizer_Plugin::FILTER_CHART_WRAPPER_CLASS, $atts['class'], $atts['id'] );

classes/Visualizer/Plugin.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class Visualizer_Plugin {
6262
const FILTER_GET_CHART_SERIES = 'visualizer-get-chart-series';
6363
const FILTER_GET_CHART_DATA = 'visualizer-get-chart-data';
6464
const FILTER_GET_CHART_SETTINGS = 'visualizer-get-chart-settings';
65+
const FILTER_UNDO_REVISIONS = 'visualizer-undo-revisions';
66+
const FILTER_HANDLE_REVISIONS = 'visualizer-handle-revisions';
6567

6668
const CF_CHART_URL = 'visualizer-chart-url';
6769
const CF_CHART_SCHEDULE = 'visualizer-chart-schedule';
@@ -97,6 +99,9 @@ class Visualizer_Plugin {
9799
* @access private
98100
*/
99101
private function __construct() {
102+
if ( VISUALIZER_DEBUG ) {
103+
add_action( 'themeisle_log_event', array( $this, 'themeisle_log_event_debug' ), 10, 5 );
104+
}
100105
}
101106

102107
/**
@@ -184,4 +189,14 @@ public function setModule( $class ) {
184189
private function __clone() {
185190
}
186191

192+
/**
193+
* For local testing, overrides the 'themeisle_log_event' hook and redirects to error.log.
194+
*/
195+
final function themeisle_log_event_debug( $name, $message, $type, $file, $line ) {
196+
if ( Visualizer_Plugin::NAME !== $name ) {
197+
return;
198+
}
199+
error_log( sprintf( '%s (%s): %s in %s:%s', $name, $type, $message, $file, $line ) );
200+
}
201+
187202
}

index.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ function visualizer_launch() {
7575
if ( ! defined( 'VISUALIZER_CSV_ENCLOSURE' ) ) {
7676
define( 'VISUALIZER_CSV_ENCLOSURE', '"' );
7777
}
78+
if ( ! defined( 'VISUALIZER_DEBUG' ) ) {
79+
define( 'VISUALIZER_DEBUG', false );
80+
}
81+
7882
// instantiate the plugin
7983
$plugin = Visualizer_Plugin::instance();
8084
// set general modules

0 commit comments

Comments
 (0)