-
-
Save lukecav/ae4368a3a8fc8c1e7f45a69fc5ce55e9 to your computer and use it in GitHub Desktop.
[WordPress] Forever eliminate “Wordcamp” from the planet (or at least the little bit we can influence).
This file contains hidden or 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: Capital C, dangit! | |
| * Description: Forever eliminate “Wordcamp” from the planet (or at least the little bit we can influence). | |
| * Version: 2015.12 | |
| * Author: Caspar Hübinger | |
| * Author URI: https://profiles.wordpress.org/glueckpress | |
| * License: GNU General Public License v3 or later | |
| * License URI: http://www.gnu.org/licenses/gpl-3.0.html | |
| */ | |
| if ( ! defined( 'ABSPATH' ) ) { | |
| exit; | |
| } | |
| /** | |
| * Iinitialize plugin. | |
| * | |
| * @return void | |
| */ | |
| function capital_C_dangit__init() { | |
| $default_filters = array( | |
| 'the_content', | |
| 'the_title', | |
| 'wp_title', | |
| 'document_title_parts' | |
| ); | |
| foreach ( $default_filters as $filter ) | |
| add_filter( $filter, 'capital_C_dangit', 11 ); | |
| add_filter( 'comment_text', 'capital_C_dangit', 31 ); | |
| } | |
| add_action( 'init', 'capital_C_dangit__init' ); | |
| /** | |
| * Forever eliminate "Wordcamp" from the planet (or at least the little bit we can influence). | |
| * Violating our coding standards for a good function name. | |
| * | |
| * See wp-includes/formatting.php | |
| * | |
| * @param string $text The text to be modified. | |
| * @return string The modified text. | |
| */ | |
| function capital_C_dangit( $text ) { | |
| // Simple replacement for titles | |
| $current_filter = current_filter(); | |
| if ( 'the_title' === $current_filter | |
| || 'wp_title' === $current_filter | |
| || 'document_title_parts' === $current_filter ) { | |
| return str_replace( 'Wordcamp', 'WordCamp', $text ); | |
| } | |
| // Still here? Use the more judicious replacement | |
| static $dblq = false; | |
| if ( false === $dblq ) { | |
| $dblqs = array( | |
| _x( '“', 'opening curly double quote' ) | |
| ); | |
| } | |
| // Wordcamp => WordCamp | |
| $capitalized = str_replace( | |
| array( | |
| ' Wordcamp', | |
| '‘Wordcamp', | |
| $dblq . 'Wordcamp', | |
| '>Wordcamp', | |
| '(Wordcamp' | |
| ), | |
| array( | |
| ' WordCamp', | |
| '‘WordCamp', | |
| $dblq . 'WordCamp', | |
| '>WordCamp', | |
| '(WordCamp' | |
| ), | |
| $text | |
| ); | |
| return $capitalized; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment