diff --git a/modules/slugs/slugs.php b/modules/slugs/slugs.php index 40b7f8f7..ac71d0d7 100644 --- a/modules/slugs/slugs.php +++ b/modules/slugs/slugs.php @@ -27,6 +27,8 @@ // plugin init add_action( 'plugins_loaded', array( $qtranslate_slug, 'init' ) ); +add_filter( 'qtranslate_convert_url', 'qts_convert_url', 10, 2 ); + //////////////////////////////////////////////////////////////////////////////////////// function qts_get_url( $lang = false ) { @@ -50,3 +52,11 @@ function qts_uninstall() { $meta_keys = "'" . implode( "','", $meta_keys ) . "'"; $wpdb->query( "DELETE from $wpdb->postmeta WHERE meta_key IN ($meta_keys)" ); } + +function qts_convert_url( $url, $lang ) { + if ( empty( $url ) ) { + return qts_get_url( $lang ); + } + + return $url; +} diff --git a/qtranslate_core.php b/qtranslate_core.php index 1409d8e6..05f1aacc 100644 --- a/qtranslate_core.php +++ b/qtranslate_core.php @@ -1118,20 +1118,6 @@ function qtranxf_convertURL( $url = '', $lang = '', $forceadmin = false, $showDe if ( empty( $lang ) ) { $lang = $q_config['language']; } - if ( empty( $url ) ) { - // TODO refactor this hack for qtranslate-slug! We might need a hook here. - if ( $q_config['url_info']['doing_front_end'] && function_exists( 'qts_get_url' ) && $q_config['url_mode'] != QTX_URL_QUERY ) { - // quick workaround, but need a permanent solution - $url = qts_get_url( $lang ); - if ( ! empty( $url ) ) { - if ( $showDefaultLanguage && $q_config['hide_default_language'] && $lang == $q_config['default_language'] ) { - $url = qtranxf_convertURL( $url, $lang, $forceadmin, true ); - } - - return $url; - } - } - } if ( ! $q_config['url_info']['doing_front_end'] && ! $forceadmin ) { return $url; } @@ -1143,6 +1129,9 @@ function qtranxf_convertURL( $url = '', $lang = '', $forceadmin = false, $showDe $showDefaultLanguage = ! $q_config['hide_default_language']; } $showLanguage = $showDefaultLanguage || $lang != $q_config['default_language']; + + $url = apply_filters( 'qtranslate_convert_url', $url, $lang ); + $complete = qtranxf_get_url_for_language( $url, $lang, $showLanguage ); return $complete;