diff --git a/classes/Visualizer/Module/Admin.php b/classes/Visualizer/Module/Admin.php index 9e9e64ae2..94bcdb1ff 100644 --- a/classes/Visualizer/Module/Admin.php +++ b/classes/Visualizer/Module/Admin.php @@ -74,6 +74,8 @@ public function __construct( Visualizer_Plugin $plugin ) { $this->_addAction( 'admin_init', 'init' ); + $this->_addAction( 'visualizer_chart_languages', 'addMultilingualSupport' ); + if ( defined( 'TI_CYPRESS_TESTING' ) ) { $this->load_cypress_hooks(); } @@ -1128,4 +1130,49 @@ public static function proFeaturesLocked() { } return 'yes' === get_option( 'visualizer-new-user', 'yes' ) ? false : true; } + + /** + * Multilingual Support. + * + * @param int $chart_id Chart ID. + * @return bool Default false + */ + public function addMultilingualSupport( $chart_id ) { + if ( Visualizer_Module::is_pro() ) { + return; + } + if ( function_exists( 'icl_get_languages' ) ) { + $language = icl_get_languages(); + $current_lang = icl_get_current_language(); + $default_lang = icl_get_default_language(); + $post_info = wpml_get_language_information( null, $chart_id ); + + global $sitepress; + $translations = array(); + if ( ! empty( $post_info ) && ( $default_lang === $post_info['language_code'] ) ) { + $trid = $sitepress->get_element_trid( $chart_id, 'post_' . Visualizer_Plugin::CPT_VISUALIZER ); + $translations = $sitepress->get_element_translations( $trid ); + } + if ( empty( $translations ) ) { + return; + } + ?> +