Created
January 3, 2015 21:19
-
-
Save hinnerk-a/473ffd69277f3949a85a to your computer and use it in GitHub Desktop.
Postfix all occurrences of a trademark with ® (PHP function and optional WordPress hook)
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
/* | |
Author: Hinnerk Altenburg | |
Author URI: http://www.hinnerk-altenburg.de | |
Trademark: 'WP-ImmoMakler' is a registered trademark of Hinnerk Altenburg | |
Copyright: © 2015 Hinnerk Altenburg ([email protected]) | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License, version 2, as | |
published by the Free Software Foundation. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
/** | |
* Corrects letter case of a given trademark and postfixes all occurrences of it with ® | |
* | |
* @param string $text The text to be filtered | |
* @param string $trademark The notation of the trademark in correct letter case | |
* @return string The filtered text | |
*/ | |
function postfix_registered_trademark( $text, $trademark='WP-ImmoMakler' ) { | |
// Correct case | |
$text = str_ireplace( $trademark, $trademark, $text ); | |
// Remove already attached ®'s to prevent double ®'s | |
$text = str_replace( $trademark . '®', $trademark, $text ); | |
// Postfix a superscript ® to the trademark | |
$text = str_replace( $trademark, $trademark . '<sup>®</sup>', $text ); | |
return $text; | |
} | |
// WordPress developers may now hook that function into the_content, the_title and comment_text to globally transform the trademark | |
add_filter( 'the_title', 'postfix_registered_trademark', 12 ); | |
add_filter( 'the_content', 'postfix_registered_trademark', 12 ); | |
add_filter( 'comment_text', 'postfix_registered_trademark', 32 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment