Created
November 16, 2014 13:25
-
-
Save ibrokemywp/63bc0c9a5c79641bd5c8 to your computer and use it in GitHub Desktop.
Load a .mo file for the old textdomain if one exists
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
/** | |
* Load a .mo file for the old textdomain if one exists | |
* | |
* If you have to change your textdomain to comply with upcoming | |
* plugin and theme repository standards, this function will check to | |
* see if an old translation file exists and load it if it does, so | |
* that people don't lose their translations. | |
* | |
* h/t: https://github.com/10up/grunt-wp-plugin/issues/21#issuecomment-62003284 | |
*/ | |
add_filter( 'load_textdomain_mofile', 'customslug_load_old_textdomain' ), 10, 2 ); | |
function customslug_load_old_textdomain( $mofile, $textdomain ) { | |
if ( $textdomain === 'new-textdomain' && 0 === strpos( $mofile, WP_LANG_DIR . '/plugins/' ) && !file_exists( $mofile ) ) { | |
$mofile = dirname( $mofile ) . DIRECTORY_SEPARATOR . str_replace( $textdomain, 'old-textdomain', basename( $mofile ) ); | |
} | |
return $mofile; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment