Coffee2Code

==

Scott Reilly

Plugin: Text Replace

This plugin has been updated! Comments to this post are now closed. For the latest download, documentation, and link for posting new comments related to this plugin, visit the plugin’s new homepage at:coffee2code.com/wp-plugins/text-replace

Name:

Text Replace

Author:

Scott Reilly

Version:

1.0

Last updated:

27 March 2005

Description:

Replace text with other text in posts, etc. Very handy to create shortcuts to commonly-typed and/or lengthy text/HTML, or for smilies.

Notes:

SPECIAL NOTE FOR UPGRADERS:
– Remember to copy the text replacement array ($text_to_replace) from your current text-replace.php before overwriting it with the latest version. You’ll need to transfer that information into the newer version. (And prior to all that, just go ahead and make a backup of the text-replace.php you are currently using prior to any upgrade of the plugin.

This plugin can be utilized to make shortcuts for frequently typed text, but keep these things in mind:

Your best bet with defining shortcuts is to define something that would never otherwise appear in your text. For instance, bookend the shortcut with colons:

Would have the effect of changing “His majesty” to “Hellos majesty”. One solution might be to instead have used ” Hi ” (with spaces).

Do not use the backspace character, ‘\’, within the shortcut text.

Be mindful of your use of quotes as you define replacement text. Escape embedded double-quotes.

List the more specific matches early, to avoid stomping on another of your shortcuts. For example, if you have both “:p” and “:pout:”
as shortcuts, put “:pout:” first, otherwise, the “:p” will match against all the “:pout:” in your text.

If you intend to use this plugin to handle smilies, you should disable WordPress’s default smilie handler.

This plugin is set to filter the_content, the_excerpt, and if uncommented, comment_text.

Movable Type users: This plugin could be used to do what MT’s <MTMacroDefine> did:

SPECIAL CONSIDERATION: Be aware that the shortcut text that you use in your posts will be stored that way in the database (naturally). While calls to display the posts will see the filtered, text replaced version, anything that operates directly on the database will not see the expanded replacement text. So if you only ever referred to “America Online” as “:aol:” (where “:aol:” => “<a href=’http://www.aol.com’>America Online</a>”), visitors to your site will see the linked, expanded text due to the text replace, but a database search would never turn up a match for “America Online”.

However, a benefit of the replacement text not being saved to the database and instead evaluated when the data is being loaded into a web page is that if the replacement text is modified, all pages making use of the shortcut will henceforth use the updated replacement text.

Installation:

Download the file text-replace.zip and unzip it into your wp-content/plugins/ directory.
-OR-
Copy and paste the the code ( text-replace.phps ) into a file called text-replace.php, and put that file into your wp-content/plugins/ directory.

Modify the array $text_to_replace in the plugin file to define the text replacements you’d like to have happen.
Note: If upgrading, you’ll want to copy this information from your previous version of this plugin.

Activate the plugin from your WordPress admin ‘Plugins’ page.

Use the shortcut in a post.

Functions:

function c2c_text_replace( $text, $case_sensitive=false )

$text : The text to processed for text replacement.

$case_sensitive : Boolean value (either ‘true’ or ‘false’) to indicate if the search for shortcut text for possible replacement should be case sensitive or not; default is ‘false’

Tips & Examples:

N/A — Just type your shortcut text into a post and when viewed on your site you should see the expanded text.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.