Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QTS: replaced call to qts_get_url with new filter in qtranxf_convertURL #1117

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions modules/slugs/slugs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

////////////////////////////////////////////////////////////////////////////////////////

function qts_get_url( $lang = false ) {
herrvigg marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -50,3 +52,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;
}
herrvigg marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 3 additions & 14 deletions qtranslate_core.php
Original file line number Diff line number Diff line change
Expand Up @@ -1118,20 +1118,6 @@ function qtranxf_convertURL( $url = '', $lang = '', $forceadmin = false, $showDe
if ( empty( $lang ) ) {
$lang = $q_config['language'];
}
if ( empty( $url ) ) {
herrvigg marked this conversation as resolved.
Show resolved Hide resolved
// 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 ) ) {
herrvigg marked this conversation as resolved.
Show resolved Hide resolved
if ( $showDefaultLanguage && $q_config['hide_default_language'] && $lang == $q_config['default_language'] ) {
$url = qtranxf_convertURL( $url, $lang, $forceadmin, true );
}
herrvigg marked this conversation as resolved.
Show resolved Hide resolved

return $url;
}
}
}
if ( ! $q_config['url_info']['doing_front_end'] && ! $forceadmin ) {
return $url;
}
Expand All @@ -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 );

herrvigg marked this conversation as resolved.
Show resolved Hide resolved
$complete = qtranxf_get_url_for_language( $url, $lang, $showLanguage );

return $complete;
Expand Down