From 352f5ea7b098c0f6c839d961bd6a58e5aad8b2d3 Mon Sep 17 00:00:00 2001 From: Giovanni Cascione Date: Mon, 7 Mar 2022 09:44:54 +0100 Subject: [PATCH 1/2] QTS: replaced call to qts_get_url with new filter in qtranxf_convertURL --- modules/slugs/slugs.php | 9 +++++++++ qtranslate_core.php | 17 +++-------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/modules/slugs/slugs.php b/modules/slugs/slugs.php index bf080911..2656acfe 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_before', 'qts_convert_url_before_cb', 10, 2 ); + //////////////////////////////////////////////////////////////////////////////////////// /** @@ -59,3 +61,10 @@ function qts_uninstall() { $meta_keys = "'" . implode( "','", $meta_keys ) . "'"; $wpdb->query( "DELETE from $wpdb->postmeta WHERE meta_key IN ($meta_keys)" ); } + +function qts_convert_url_before_cb( $url, $lang ) { + if ( empty( $url ) ) { + return qts_get_url( $lang ); + } + return $url; +} diff --git a/qtranslate_core.php b/qtranslate_core.php index 1409d8e6..d604f55d 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_before', $url, $lang ); + $complete = qtranxf_get_url_for_language( $url, $lang, $showLanguage ); return $complete; From 7f11af089578ae5f95120fce523b81cdbba23a6b Mon Sep 17 00:00:00 2001 From: HerrVigg Date: Mon, 21 Mar 2022 23:31:22 +0100 Subject: [PATCH 2/2] Rename filter and callback --- modules/slugs/slugs.php | 5 +++-- qtranslate_core.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/slugs/slugs.php b/modules/slugs/slugs.php index 9885fc2c..ac71d0d7 100644 --- a/modules/slugs/slugs.php +++ b/modules/slugs/slugs.php @@ -27,7 +27,7 @@ // plugin init add_action( 'plugins_loaded', array( $qtranslate_slug, 'init' ) ); -add_filter( 'qtranslate_convert_url_before', 'qts_convert_url_before_cb', 10, 2 ); +add_filter( 'qtranslate_convert_url', 'qts_convert_url', 10, 2 ); //////////////////////////////////////////////////////////////////////////////////////// @@ -53,9 +53,10 @@ function qts_uninstall() { $wpdb->query( "DELETE from $wpdb->postmeta WHERE meta_key IN ($meta_keys)" ); } -function qts_convert_url_before_cb( $url, $lang ) { +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 d604f55d..05f1aacc 100644 --- a/qtranslate_core.php +++ b/qtranslate_core.php @@ -1130,7 +1130,7 @@ function qtranxf_convertURL( $url = '', $lang = '', $forceadmin = false, $showDe } $showLanguage = $showDefaultLanguage || $lang != $q_config['default_language']; - $url = apply_filters( 'qtranslate_convert_url_before', $url, $lang ); + $url = apply_filters( 'qtranslate_convert_url', $url, $lang ); $complete = qtranxf_get_url_for_language( $url, $lang, $showLanguage );