Skip to content

Commit 358e166

Browse files
Merge pull request #467 from contactashish13/issue-466
Use filter instead of constant VISUALIZER_PRO
2 parents 3aa0409 + 23b1a3a commit 358e166

File tree

10 files changed

+64
-30
lines changed

10 files changed

+64
-30
lines changed

classes/Visualizer/Gutenberg/Block.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function enqueue_gutenberg_scripts() {
8383

8484
$type = 'community';
8585

86-
if ( VISUALIZER_PRO ) {
86+
if ( Visualizer_Module::is_pro() ) {
8787
$type = 'pro';
8888
if ( apply_filters( 'visualizer_is_business', false ) ) {
8989
$type = 'developer';
@@ -222,7 +222,7 @@ public function get_visualizer_data( $post ) {
222222
$data['visualizer-chart-schedule'] = $schedule;
223223
}
224224

225-
if ( VISUALIZER_PRO ) {
225+
if ( Visualizer_Module::is_pro() ) {
226226
$permissions = get_post_meta( $post_id, Visualizer_PRO::CF_PERMISSIONS, true );
227227

228228
if ( ! empty( $permissions ) ) {
@@ -253,7 +253,7 @@ public function update_chart_data( $data ) {
253253
apply_filters( 'visualizer_pro_remove_schedule', $data['id'] );
254254
}
255255

256-
if ( VISUALIZER_PRO ) {
256+
if ( Visualizer_Module::is_pro() ) {
257257
update_post_meta( $data['id'], Visualizer_PRO::CF_PERMISSIONS, $data['visualizer-permissions'] );
258258
}
259259

classes/Visualizer/Module.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ protected function load_chart_type( $chart_id ) {
494494
$class = new $name;
495495
}
496496

497-
if ( is_null( $class ) && VISUALIZER_PRO ) {
497+
if ( is_null( $class ) && Visualizer_Module::is_pro() ) {
498498
// lets see if this type exists in pro. New Lite(3.1.0+) & old Pro(1.8.0-).
499499
$type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true );
500500
$class = apply_filters( 'visualizer_pro_chart_type_sidebar', null, array( 'id' => $chart_id, 'type' => $type, 'settings' => get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ) ) );
@@ -600,4 +600,24 @@ protected static function hasChartType( $type ) {
600600
return $q->found_posts > 0;
601601
}
602602

603+
/**
604+
* Checks if the PRO version is active.
605+
*
606+
* @since 3.3.0
607+
*/
608+
public static function is_pro() {
609+
// versions of pro before 1.9.0 will use the constant VISUALIZER_PRO
610+
// versions of pro 1.9.0 onwards will use the filter
611+
return apply_filters( 'visualizer_is_pro', VISUALIZER_PRO );
612+
}
613+
614+
/**
615+
* Checks if the PRO version is older than a particular version.
616+
*
617+
* @since 3.3.0
618+
*/
619+
public static function is_pro_older_than( $version ) {
620+
return version_compare( VISUALIZER_PRO_VERSION, $version, '<' );
621+
}
622+
603623
}

classes/Visualizer/Module/Admin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ private static function handleDeprecatedCharts( $types, $enabledOnly, $get2Darra
436436
}
437437

438438
// if a user has a Gauge/Candlestick chart, then let them keep using it.
439-
if ( ! VISUALIZER_PRO ) {
439+
if ( ! Visualizer_Module::is_pro() ) {
440440
if ( ! self::hasChartType( 'gauge' ) ) {
441441
if ( $get2Darray ) {
442442
$deprecated[] = 'gauge';
@@ -465,7 +465,7 @@ private static function handleDeprecatedCharts( $types, $enabledOnly, $get2Darra
465465
}
466466

467467
// if a user has a Gauge/Candlestick chart, then let them keep using it.
468-
if ( ! VISUALIZER_PRO ) {
468+
if ( ! Visualizer_Module::is_pro() ) {
469469
if ( ! self::hasChartType( 'gauge' ) ) {
470470
if ( $get2Darray ) {
471471
$deprecated[] = 'gauge';

classes/Visualizer/Module/Chart.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,9 @@ public function renderChartPages() {
491491
);
492492
wp_register_script( 'visualizer-editor-simple', VISUALIZER_ABSURL . 'js/simple-editor.js', array( 'jquery' ), Visualizer_Plugin::VERSION, true );
493493

494-
// added by Ash/Upwork
495-
if ( VISUALIZER_PRO ) {
494+
do_action( 'visualizer_add_scripts' );
495+
496+
if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) {
496497
global $Visualizer_Pro;
497498
$Visualizer_Pro->_addScriptsAndStyles();
498499
}
@@ -547,7 +548,7 @@ private function loadCodeEditorAssets() {
547548
wp_enqueue_script( 'visualizer-datatables' );
548549
wp_enqueue_style( 'visualizer-jquery-ui' );
549550

550-
if ( ! VISUALIZER_PRO ) {
551+
if ( ! Visualizer_Module::is_pro() ) {
551552
return;
552553
}
553554

@@ -650,7 +651,7 @@ private function _handleDataAndSettingsPage() {
650651
wp_enqueue_script( 'visualizer-chosen' );
651652
wp_enqueue_script( 'visualizer-render' );
652653

653-
if ( ! VISUALIZER_PRO ) {
654+
if ( ! Visualizer_Module::is_pro() ) {
654655
wp_enqueue_script( 'visualizer-editor-simple' );
655656
wp_localize_script(
656657
'visualizer-editor-simple',
@@ -704,7 +705,7 @@ private function _handleDataAndSettingsPage() {
704705
'db_query' => array(
705706
'tables' => $table_col_mapping,
706707
),
707-
'is_pro' => VISUALIZER_PRO,
708+
'is_pro' => Visualizer_Module::is_pro(),
708709
'page_type' => 'chart',
709710
'json_tag_separator' => Visualizer_Source_Json::TAG_SEPARATOR,
710711
'json_tag_separator_view' => Visualizer_Source_Json::TAG_SEPARATOR_VIEW,
@@ -727,10 +728,14 @@ private function _handleDataAndSettingsPage() {
727728
} else {
728729
$render->button = esc_attr__( 'Insert Chart', 'visualizer' );
729730
}
730-
if ( VISUALIZER_PRO ) {
731+
732+
do_action( 'visualizer_enqueue_scripts_and_styles', $data );
733+
734+
if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) {
731735
global $Visualizer_Pro;
732736
$Visualizer_Pro->_enqueueScriptsAndStyles( $data );
733737
}
738+
734739
$this->_addAction( 'admin_head', 'renderFlattrScript' );
735740
wp_iframe( array( $render, 'render' ) );
736741
}
@@ -804,7 +809,6 @@ public function renderFlattrScript() {
804809
private function handleCSVasString( $data ) {
805810
$source = null;
806811

807-
// do not check for VISUALIZER_PRO here as that is false:
808812
// @issue https://github.com/Codeinwp/visualizer/issues/412
809813
if ( has_filter( 'visualizer_pro_handle_chart_data' ) ) {
810814
$source = apply_filters( 'visualizer_pro_handle_chart_data', $data, '' );
@@ -1125,11 +1129,14 @@ private function _handleDataPage() {
11251129
),
11261130
)
11271131
);
1128-
// Added by Ash/Upwork
1129-
if ( VISUALIZER_PRO ) {
1132+
1133+
do_action( 'visualizer_enqueue_scripts_and_styles', $data );
1134+
1135+
if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) {
11301136
global $Visualizer_Pro;
11311137
$Visualizer_Pro->_enqueueScriptsAndStyles( $data );
11321138
}
1139+
11331140
// Added by Ash/Upwork
11341141
$this->_addAction( 'admin_head', 'renderFlattrScript' );
11351142
wp_iframe( array( $render, 'render' ) );

classes/Visualizer/Module/Sources.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function addProUpsell( $old, $feature = null ) {
147147
$return .= ' </div>';
148148
$return .= '</div>';
149149
}
150-
if ( empty( $feature ) && VISUALIZER_PRO ) {
150+
if ( empty( $feature ) && Visualizer_Module::is_pro() ) {
151151
remove_filter( 'visualizer_pro_upsell', 'addProUpsell', 10, 1 );
152152
$return = '';
153153
}

classes/Visualizer/Render/Layout.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class="visualizer-input">
193193
?>
194194
</select>
195195
<?php
196-
if ( ! VISUALIZER_PRO ) {
196+
if ( ! Visualizer_Module::is_pro() ) {
197197
?>
198198
<br/>
199199
<br/>

classes/Visualizer/Render/Library.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private function _renderChartBox( $placeholder_id, $chart_id ) {
236236
* Render sidebar.
237237
*/
238238
private function _renderSidebar() {
239-
if ( ! VISUALIZER_PRO ) {
239+
if ( ! Visualizer_Module::is_pro() ) {
240240
echo '<div id="visualizer-sidebar">';
241241
echo '<div class="visualizer-sidebar-box">';
242242
echo '<h3>' . __( 'Gain more editing power', 'visualizer' ) . '</h3><ul>';

classes/Visualizer/Render/Page/Data.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,15 @@ class Visualizer_Render_Page_Data extends Visualizer_Render_Page {
3838
*/
3939
protected function _renderContent() {
4040
// Added by Ash/Upwork
41-
if ( VISUALIZER_PRO ) {
42-
global $Visualizer_Pro;
43-
$Visualizer_Pro->_addEditor( $this->chart->ID );
44-
if ( method_exists( $Visualizer_Pro, '_addFilterWizard' ) ) {
45-
$Visualizer_Pro->_addFilterWizard( $this->chart->ID );
41+
if ( Visualizer_Module::is_pro() ) {
42+
do_action( 'visualizer_add_editor_etc', $this->chart->ID );
43+
44+
if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) {
45+
global $Visualizer_Pro;
46+
$Visualizer_Pro->_addEditor( $this->chart->ID );
47+
if ( method_exists( $Visualizer_Pro, '_addFilterWizard' ) ) {
48+
$Visualizer_Pro->_addFilterWizard( $this->chart->ID );
49+
}
4650
}
4751
} else {
4852
Visualizer_Render_Layout::show( 'simple-editor-screen', $this->chart->ID );
@@ -190,7 +194,7 @@ class="visualizer-select">
190194
<div class="remote-file-section">
191195
<?php
192196
$bttn_label = 'visualizer_source_json' === $source_of_chart ? __( 'Modify Parameters', 'visualizer' ) : __( 'Create Parameters', 'visualizer' );
193-
if ( VISUALIZER_PRO ) {
197+
if ( Visualizer_Module::is_pro() ) {
194198
?>
195199
<p class="viz-group-description"><?php _e( 'How often do you want to check the URL', 'visualizer' ); ?></p>
196200
<select name="vz-json-time" id="vz-json-time" class="visualizer-select" data-chart="<?php echo $this->chart->ID; ?>">
@@ -222,7 +226,7 @@ class="visualizer-select">
222226
data-t-filter="<?php _e( 'Show Chart', 'visualizer' ); ?>"
223227
data-t-chart="<?php echo $bttn_label; ?>">
224228
<?php
225-
if ( VISUALIZER_PRO ) {
229+
if ( Visualizer_Module::is_pro() ) {
226230
?>
227231
<input type="button" id="json-chart-save-button" class="button button-primary "
228232
value="<?php _e( 'Save Schedule', 'visualizer' ); ?>">
@@ -246,7 +250,7 @@ class="dashicons dashicons-lock"></span></h2>
246250
<?php
247251
$fetch_link = add_query_arg(
248252
array(
249-
'action' => ( VISUALIZER_PRO ) ? Visualizer_Pro::ACTION_FETCH_DATA : '',
253+
'action' => Visualizer_Module::is_pro() ? Visualizer_Pro::ACTION_FETCH_DATA : '',
250254
'nonce' => wp_create_nonce(),
251255
),
252256
admin_url( 'admin-ajax.php' )
@@ -402,8 +406,8 @@ class="dashicons dashicons-lock"></span></h2>
402406

403407
<div class="viz-group-content edit-data-content">
404408
<div>
405-
<p class="viz-group-description"><?php echo sprintf( __( 'You can manually edit the chart data using the %s editor.', 'visualizer' ), VISUALIZER_PRO ? 'spreadsheet like' : 'simple' ); ?></p>
406-
<?php if ( ! VISUALIZER_PRO ) { ?>
409+
<p class="viz-group-description"><?php echo sprintf( __( 'You can manually edit the chart data using the %s editor.', 'visualizer' ), Visualizer_Module::is_pro() ? 'spreadsheet like' : 'simple' ); ?></p>
410+
<?php if ( ! Visualizer_Module::is_pro() ) { ?>
407411
<p class="viz-group-description simple-editor-type"><input type="checkbox" id="simple-editor-type" value="textarea"><label for="simple-editor-type"><?php _e( 'Use text area editor instead', 'visualizer' ); ?></label></p>
408412
<?php } ?>
409413
<input type="button" id="editor-chart-button" class="button button-primary "

classes/Visualizer/Render/Page/Update.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ protected function _toHTML() {
5454
echo 'win.visualizer.update();';
5555
echo '}';
5656

57-
// added by Ash/Upwork
58-
if ( VISUALIZER_PRO ) {
57+
do_action( 'visualizer_add_update_hook', $this->series, $this->data );
58+
59+
if ( Visualizer_Module::is_pro() && Visualizer_Module::is_pro_older_than( '1.9.0' ) ) {
5960
global $Visualizer_Pro;
6061
$Visualizer_Pro->_addUpdateHook( $this->series, $this->data );
6162
}

index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
if ( class_exists( 'Visualizer_Plugin', false ) ) {
2424
return;
2525
}
26+
27+
// support for pro versions before 3.3.0
2628
if ( class_exists( 'Visualizer_Pro', false ) ) {
2729
define( 'VISUALIZER_PRO', true );
2830
} else {

0 commit comments

Comments
 (0)