Skip to content

Instantly share code, notes, and snippets.

@glueckpress
Last active February 2, 2017 19:47
Show Gist options
  • Select an option

  • Save glueckpress/48283f42060c74fbcded to your computer and use it in GitHub Desktop.

Select an option

Save glueckpress/48283f42060c74fbcded 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).
<?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( '&#8220;', 'opening curly double quote' )
);
}
// Wordcamp => WordCamp
$capitalized = str_replace(
array(
' Wordcamp',
'&#8216;Wordcamp',
$dblq . 'Wordcamp',
'>Wordcamp',
'(Wordcamp'
),
array(
' WordCamp',
'&#8216;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