PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.2
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.2
4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 All 200 releases
← All changes | includes/Core/Rewrite.php +40 -0 4.6.14.9.2 View file →
@@ -22,8 +22,48 @@
22 22 public function init() {
23 23 add_action( 'init', [ $this, 'rules' ] );
24 24 add_action( 'betterdocs::settings::saved', [ $this, 'save_permalink_structure' ], 2, 3 );
25 25 add_action( 'template_redirect', [ $this, 'handle_pagination_redirect' ] );
26 + add_filter( 'term_link', [ $this, 'taxonomy_term_link' ], 10, 3 );
27 + }
28 +
29 + /**
30 + * Swap a BetterDocs taxonomy base slug for its WPML-translated value in term links.
31 + *
32 + * doc_tag / doc_category are registered with the default-language slug, so
33 + * WordPress' core get_term_link() always builds `/docs-tag/{slug}/` etc. When
34 + * WPML translates the "URL <taxonomy> tax slug" string, rewrite the base segment
35 + * to the active language's slug so term links match the translated archive URL.
36 + * No-op for other taxonomies, when the slug isn't translated, or when the base
37 + * segment isn't present (e.g. MKB category permalinks that omit it).
38 + *
39 + * @param string $termlink
40 + * @param \WP_Term $term
41 + * @param string $taxonomy
42 + * @return string
43 + */
44 + public function taxonomy_term_link( $termlink, $term, $taxonomy ) {
45 + if ( ! is_string( $termlink ) ) {
46 + return $termlink;
47 + }
48 +
49 + $slug_map = [
50 + 'doc_tag' => trim( $this->settings->get( 'tag_slug', 'docs-tag' ), '/' ),
51 + 'doc_category' => trim( $this->settings->get( 'category_slug', 'docs-category' ), '/' ),
52 + ];
53 +
54 + if ( ! isset( $slug_map[ $taxonomy ] ) || $slug_map[ $taxonomy ] === '' ) {
55 + return $termlink;
56 + }
57 +
58 + $default = $slug_map[ $taxonomy ];
59 + $translated = \WPDeveloper\BetterDocs\Utils\Helper::wpml_translated_tax_slug( $taxonomy, $default );
60 +
61 + if ( $translated === $default ) {
62 + return $termlink;
63 + }
64 +
65 + return preg_replace( '#/' . preg_quote( $default, '#' ) . '/#', '/' . $translated . '/', $termlink, 1 );
26 66 }
27 67
28 68 /**
29 69 * Handle pagination redirect