Skip to content

Commit ae91c41

Browse files
Move pro feature #731
1 parent e573329 commit ae91c41

File tree

3 files changed

+16
-93
lines changed

3 files changed

+16
-93
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ public function __construct( Visualizer_Plugin $plugin ) {
7474

7575
$this->_addAction( 'admin_init', 'init' );
7676

77-
// Multilingual support.
78-
$this->_addAction( 'visualizer_chart_languages', 'addMultilingualSupport' );
79-
8077
if ( defined( 'TI_CYPRESS_TESTING' ) ) {
8178
$this->load_cypress_hooks();
8279
}
@@ -770,11 +767,20 @@ function setScreenOptions( $status, $option, $value ) {
770767
private function getDisplayFilters( &$query_args ) {
771768
$query = array();
772769

773-
if ( function_exists( 'icl_get_languages' ) ) {
774-
$query[] = array(
775-
'key' => 'chart_lang',
776-
'compare' => 'NOT EXISTS',
777-
);
770+
if ( Visualizer_Module::is_pro() && function_exists( 'icl_get_languages' ) ) {
771+
$current_lang = icl_get_current_language();
772+
if ( in_array( $current_lang, array( 'all', icl_get_default_language() ), true ) ) {
773+
$query[] = array(
774+
'key' => 'chart_lang',
775+
'compare' => 'NOT EXISTS',
776+
);
777+
} else {
778+
$query[] = array(
779+
'key' => 'chart_lang',
780+
'value' => $current_lang,
781+
'compare' => '=',
782+
);
783+
}
778784
}
779785

780786
// add chart type filter to the query arguments
@@ -1115,43 +1121,4 @@ public static function proFeaturesLocked() {
11151121
}
11161122
return 'yes' === get_option( 'visualizer-new-user', 'yes' ) ? false : true;
11171123
}
1118-
1119-
/**
1120-
* Multilingual Support.
1121-
*
1122-
* @return bool Default false
1123-
*/
1124-
public static function addMultilingualSupport( $chart_id ) {
1125-
if ( function_exists( 'icl_get_languages' ) ) {
1126-
$language = icl_get_languages();
1127-
$current_lang = icl_get_current_language();
1128-
global $sitepress;
1129-
$trid = $sitepress->get_element_trid( $chart_id, 'post_' . Visualizer_Plugin::CPT_VISUALIZER );
1130-
$translations = $sitepress->get_element_translations( $trid );
1131-
?>
1132-
<hr><div class="visualizer-languages-list">
1133-
<?php
1134-
foreach ( $language as $lang ) {
1135-
$lang_code = $lang['code'];
1136-
if ( $current_lang !== $lang_code ) {
1137-
$lang_chart_exist = get_post_meta( $chart_id, Visualizer_Plugin::NAME . '_' . $lang_code, true );
1138-
$translate_info = isset( $translations[ $lang_code ] ) ? $translations[ $lang_code ] : false;
1139-
?>
1140-
<a href="javascript:;" data-lang_code="<?php echo esc_attr( $lang_code ); ?>" data-chart="<?php echo $translate_info ? $translate_info->element_id : $chart_id; ?>">
1141-
<img src="<?php echo esc_url( $lang['country_flag_url'] ); ?>" alt="<?php echo esc_attr( $lang['translated_name'] ); ?>">
1142-
<?php if ( $translate_info ) : ?>
1143-
<i class="otgs-ico-edit"></i>
1144-
<?php else : ?>
1145-
<i class="otgs-ico-add"></i>
1146-
<?php endif; ?>
1147-
</a>
1148-
<?php
1149-
}
1150-
}
1151-
?>
1152-
</div>
1153-
<?php
1154-
}
1155-
return;
1156-
}
11571124
}

classes/Visualizer/Module/Chart.php

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ public function deleteChart() {
439439
}
440440
}
441441
if ( $success ) {
442-
if ( function_exists( 'icl_get_languages' ) ) {
442+
if ( Visualizer_Module::is_pro() && function_exists( 'icl_get_languages' ) ) {
443443
global $sitepress;
444444
$trid = $sitepress->get_element_trid( $chart_id, 'post_' . Visualizer_Plugin::CPT_VISUALIZER );
445445
$translations = $sitepress->get_element_translations( $trid );
@@ -538,11 +538,6 @@ public function renderChartPages() {
538538
)
539539
);
540540

541-
if ( ! empty( $_GET['lang'] ) && ! empty( $_GET['parent_chart_id'] ) ) {
542-
$parent_chart_id = (int) $_GET['parent_chart_id'];
543-
add_post_meta( $chart_id, 'chart_lang', $_GET['lang'] );
544-
$this->set_wpml_element_language_details( $parent_chart_id, $chart_id, $_GET['lang'] );
545-
}
546541
do_action( 'visualizer_pro_new_chart_defaults', $chart_id );
547542
}
548543
wp_redirect( esc_url_raw( add_query_arg( 'chart', (int) $chart_id ) ) );
@@ -1541,43 +1536,4 @@ public function save_chart_image( $base64_img, $chart_id, $save_attachment = tru
15411536
$attach_id = wp_insert_attachment( $attachment, $upload_dir['path'] . '/' . $hashed_filename );
15421537
return $attach_id;
15431538
}
1544-
1545-
/**
1546-
* WPML set element language details.
1547-
*
1548-
* @param int $post_id Post ID.
1549-
* @param int $translated_post_id Translated post ID.
1550-
* @param string $language_code Selected language code.
1551-
*/
1552-
public function set_wpml_element_language_details( $post_id = 0, $translated_post_id = 0, $language_code = '' ) {
1553-
global $sitepress;
1554-
if ( $post_id && ! empty( $language_code ) ) {
1555-
$post_type = Visualizer_Plugin::CPT_VISUALIZER;
1556-
$wpml_element_type = apply_filters( 'wpml_element_type', $post_type );
1557-
$trid = $sitepress->get_element_trid( $post_id, 'post_' . $post_type );
1558-
$recursive = false;
1559-
$original_post_id = $translated_post_id;
1560-
$original_lang_code = $language_code;
1561-
if ( empty( $trid ) ) {
1562-
$translated_post_id = $post_id;
1563-
$trid = $post_id;
1564-
$recursive = true;
1565-
$language_code = icl_get_default_language();
1566-
}
1567-
1568-
$language_args = array(
1569-
'element_id' => $translated_post_id,
1570-
'element_type' => $wpml_element_type,
1571-
'trid' => $trid,
1572-
'language_code' => $language_code,
1573-
'source_language_code' => ! $recursive ? icl_get_default_language() : null,
1574-
);
1575-
// Set language details.
1576-
do_action( 'wpml_set_element_language_details', $language_args );
1577-
1578-
if ( $recursive ) {
1579-
$this->set_wpml_element_language_details( $post_id, $original_post_id, $original_lang_code );
1580-
}
1581-
}
1582-
}
15831539
}

classes/Visualizer/Module/Frontend.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public function renderChart( $atts ) {
305305
$atts
306306
);
307307

308-
if ( function_exists( 'icl_get_languages' ) ) {
308+
if ( Visualizer_Module::is_pro() && function_exists( 'icl_get_languages' ) ) {
309309
global $sitepress;
310310
$locale = get_locale();
311311
$locale = strtolower( str_replace( '_', '-', $locale ) );

0 commit comments

Comments
 (0)