$plugin(); } } if ( ! function_exists( 'is_plugin_active' ) ) { include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); } } /** * Prevent the class from being cloned * * @return void * @since 2.0.0 */ protected function __clone() { _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ uh?' ), '2.0' ); } /** * Compatibility with WPML * * @uses add_filter() * * @return void * @since 2.0.0 */ public function wpml() { add_action( 'plugins_loaded', array( $this, 'wpml_init', 20 ) ); add_action( 'black_studio_tinymce_before_widget', array( $this, 'wpml_widget_before' ), 10, 2 ); add_action( 'black_studio_tinymce_after_widget', array( $this, 'wpml_widget_after' ), 10, 2 ); add_filter( 'black_studio_tinymce_widget_update', array( $this, 'wpml_widget_update' ), 10, 2 ); add_action( 'black_studio_tinymce_before_editor', array( $this, 'wpml_check_deprecated_translations' ), 5, 2 ); add_filter( 'widget_text', array( $this, 'wpml_widget_text' ), 2, 3 ); } /** * Helper function to get WPML version * * @uses get_plugin_data() * * @return string * @since 2.6.0 */ public function wpml_get_version() { $wpml_data = get_plugin_data( WP_PLUGIN_DIR . '/sitepress-multilingual-cms/sitepress.php', false, false ); return $wpml_data['Version']; } /** * Initialize compatibility with WPML and WPML Widgets plugins * * @uses is_plugin_active() * @uses has_action() * @uses remove_action() * * @return void * @since 2.3.1 */ public function wpml_init() { if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) && is_plugin_active( 'wpml-widgets/wpml-widgets.php' ) ) { if ( false !== has_action( 'update_option_widget_black-studio-tinymce', 'icl_st_update_widget_title_actions' ) ) { remove_action( 'update_option_widget_black-studio-tinymce', 'icl_st_update_widget_title_actions', 5 ); } } } /** * Disable WPML String translation native behavior * * @uses remove_filter() * * @param mixed[] $args * @param mixed[] $instance * @return void * @since 2.3.0 */ public function wpml_widget_before( $args, $instance ) { if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ) { // Avoid native WPML string translation of widget titles // for widgets inserted in pages built with Page Builder (SiteOrigin panels) // and also when WPML Widgets is active and for WPML versions from 3.8.0 on if ( false !== has_filter( 'widget_title', 'icl_sw_filters_widget_title' ) ) { if ( isset( $instance['panels_info'] ) || isset( $instance['wp_page_widget'] ) || is_plugin_active( 'wpml-widgets/wpml-widgets.php' ) || version_compare( $this->wpml_get_version(), '3.8.0' ) >= 0 ) { remove_filter( 'widget_title', 'icl_sw_filters_widget_title', 0 ); $this->wpml_removed_widget_title_filter = true; } } // Avoid native WPML string translation of widget texts (for all widgets) // Note: Black Studio TinyMCE Widget already supports WPML string translation, // so this is needed to prevent duplicate translations if ( false !== has_filter( 'widget_text', 'icl_sw_filters_widget_text' ) ) { remove_filter( 'widget_text', 'icl_sw_filters_widget_text', 0 ); $this->wpml_removed_widget_text_filter = true; } } } /** * Re-Enable WPML String translation native behavior * * @uses add_filter() * * @param mixed[] $args * @param mixed[] $instance * @return void * @since 2.3.0 */ public function wpml_widget_after( $args, $instance ) { if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ) { // Restore widget title's native WPML string translation filter if it was removed if ( $this->wpml_removed_widget_title_filter ) { if ( false === has_filter( 'widget_title', 'icl_sw_filters_widget_title' ) && function_exists( 'icl_sw_filters_widget_title' ) ) { add_filter( 'widget_title', 'icl_sw_filters_widget_title', 0 ); $this->wpml_removed_widget_title_filter = false; } } // Restore widget text's native WPML string translation filter if it was removed if ( $this->wpml_removed_widget_text_filter ) { if ( false === has_filter( 'widget_text', 'icl_sw_filters_widget_text' ) && function_exists( 'icl_sw_filters_widget_text' ) ) { add_filter( 'widget_text', 'icl_sw_filters_widget_text', 0 ); $this->wpml_removed_widget_text_filter = false; } } } } /** * Add widget text to WPML String translation * * @uses is_plugin_active() * @uses icl_register_string() Part of WPML * * @param mixed[] $instance * @param object $widget * @return mixed[] * @since 2.0.0 */ public function wpml_widget_update( $instance, $widget ) { if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) && version_compare( $this->wpml_get_version(), '3.8.0' ) < 0 && ! is_plugin_active( 'wpml-widgets/wpml-widgets.php' ) ) { if ( function_exists( 'icl_register_string' ) && ! empty( $widget->number ) ) { // Avoid translation of Page Builder (SiteOrigin panels) and WP Page Widget widgets if ( ! isset( $instance['panels_info'] ) && ! isset( $instance['wp_page_widget'] ) ) { icl_register_string( 'Widgets', 'widget body - ' . $widget->id_base . '-' . $widget->number, $instance['text'] ); } } } return $instance; } /** * Translate widget text * * @uses is_plugin_active() * @uses icl_t() Part of WPML * @uses icl_st_is_registered_string() Part of WPML * * @param string $text * @param mixed[]|null $instance * @param object|null $widget * @return string * @since 2.0.0 */ public function wpml_widget_text( $text, $instance = null, $widget = null ) { if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) && ! is_plugin_active( 'wpml-widgets/wpml-widgets.php' ) ) { if ( bstw()->check_widget( $widget ) && ! empty( $instance ) ) { if ( function_exists( 'icl_t' ) && function_exists( 'icl_st_is_registered_string' ) ) { // Avoid translation of Page Builder (SiteOrigin panels) and WP Page Widget widgets if ( ! isset( $instance['panels_info'] ) && ! isset( $instance['wp_page_widget'] ) ) { if ( icl_st_is_registered_string( 'Widgets', 'widget body - ' . $widget->id_base . '-' . $widget->number ) ) { $text = icl_t( 'Widgets', 'widget body - ' . $widget->id_base . '-' . $widget->number, $text ); } } } } } return $text; } /** * Check for existing deprecated translations (made with WPML String Translations plugin) and display warning * * @uses is_plugin_active() * @uses icl_st_is_registered_string() Part of WPML * @uses admin_url() * * @param mixed[]|null $instance * @param object|null $widget * @return void * @since 2.6.0 */ public function wpml_check_deprecated_translations( $instance, $widget ) { if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) && version_compare( $this->wpml_get_version(), '3.8.0' ) >= 0 ) { if ( function_exists( 'icl_st_is_registered_string' ) ) { if ( icl_st_is_registered_string( 'Widgets', 'widget body - ' . $widget->id_base . '-' . $widget->number ) ) { $wpml_st_url = admin_url( 'admin.php?page=wpml-string-translation%2Fmenu%2Fstring-translation.php&context=Widgets' ); echo '
'; /* translators: Warning displayed when deprecated translations of the current widget are detected */ echo sprintf( __( 'WARNING: This widget has one or more translations made using WPML String Translation plugin, which is now a deprecated method of translating widgets, in favor of the "Display on language" dropdown introduced with WPML 3.8. Please migrate your existing translations by creating new widgets and selecting the language of this widget and the new ones accordingly. Finally delete the existing translations from WPML String Translation interface.', 'black-studio-tinymce-widget' ), esc_url( $wpml_st_url ) ); echo '