Last active
November 16, 2022 21:29
-
-
Save wp-user-manager/bb7c515fd25a158cfd9feefac47f45f5 to your computer and use it in GitHub Desktop.
WP User Manager - Translate the profile URL slugs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wpum_profile_tabs_translation_mapping() { | |
// Translated to Slovenian, change to your language | |
return array( | |
'about' => 'priblizno', | |
'posts' => 'objave', | |
'comments' => 'komentarj', | |
); | |
} | |
add_filter( 'wpum_get_registered_profile_tabs', function ( $tabs ) { | |
foreach ( wpum_profile_tabs_translation_mapping() as $tab => $translated_tab ) { | |
if ( ! isset( $tabs[ $tab ] ) ) { | |
continue; | |
} | |
$tabs[ $translated_tab ] = $tabs[ $tab ]; | |
unset( $tabs[ $tab ] ); | |
} | |
return $tabs; | |
} ); | |
add_filter( 'wpum_get_template_part', function ( $parts ) { | |
$profile_tabs = wpum_profile_tabs_translation_mapping(); | |
foreach ( $parts as $part ) { | |
foreach ( $profile_tabs as $tab => $translated_tab ) { | |
if ( false !== strpos( $part, $translated_tab ) ) { | |
$parts[] = str_replace( $translated_tab, $tab, $part ); | |
} | |
} | |
} | |
return $parts; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Save this file to your /wp-content/mu-plugins/ directory (you might need to create the mu-plugins directory).