Last active
December 14, 2015 21:33
-
-
Save glueckpress/224948d6680ff574d320 to your computer and use it in GitHub Desktop.
[WordPress] Mini example plugin. Modify default (not translated) language strings of a plugin. Beware: Might result in performance issues when applied to many strings.
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 | |
/** | |
* Plugin Name: Custom Text Strings for Foo Plugin | |
* Description: Modify default (not translated) language strings of a plugin. Beware: Might result in performance issues when applied to many strings. | |
* Version: 2014.10 | |
* Author: Caspar Hübinger | |
* Author URI: http://glueckpress.com/ | |
* License: GNU General Public License v2 or later | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
/** | |
* Modify default text strings of Foo plugin. | |
* Assuming plugin intorduces "Foo_Plugin" class, has text domain "foo-plugin". | |
* | |
* @param mixed $translated | |
* @param mixed $original | |
* @param mixed $domain | |
* @return string | |
*/ | |
function gp1410201916( $translated, $original, $domain ) { | |
/* Only strings from given plugin */ | |
if( ! class_exists( 'Foo_Plugin' ) || 'foo-plugin' !== $domain ) { | |
return $translated; | |
} | |
/* 'Original string' => 'New string' */ | |
$strings = array( 'Wordpress' => 'WordPress' ); | |
if( isset( $strings[ $original ] ) ) { | |
$translations = &get_translations_for_domain( $domain ); | |
$translated = $translations->translate( $strings[ $original ] ); | |
} | |
return $translated; | |
} | |
add_filter( 'gettext', 'gp1410201916', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment