Instantly share code, notes, and snippets.

What would you like to do?
This is my general functions file. Lots of them aren't mine - I've indicated where I've found them where appropriate
* Rich Text cleaner
* This function pulls out rich text quotes and dashes, usually from Word or other rich text editors
* @author Mango
* @link
* @param string $text text to clean up
* @return string
function richClean($text) {
$text = str_replace(
array("\xe2\x80\x98", "\xe2\x80\x99", "\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x93", "\xe2\x80\x94", "\xe2\x80\xa6"),
array("'", "'", '"', '"', '-', '--', '...'),
// Next, replace their Windows-1252 equivalents.
$text = str_replace(
array(chr(145), chr(146), chr(147), chr(148), chr(150), chr(151), chr(133)),
array("'", "'", '"', '"', '-', '--', '...'),
* Show the results of a print_r without having to view source
* @author gadhra
* @param array $arr the array to print out
* @param boolean $exit whether the function should exit after you print the array. Defaults to true
if(! function_exists('debug')) {
function debug($arr, $exit=true) {
echo '<pre>';
echo '</pre>';
if($exit) {
* Serialize and unserialize data for storage. This gets around the magic_quotes issue
* by encoding the results - helps when you're saving it to the db
* @author gadhra
* @param string $str base64 encoded serialized string
* @param array $arr base64 decoded unserialized array
* @return string|array depending on which function
function srl($arr) {
if(is_array($arr)) {
function unsrl($str) {
$arr = @unserialize(base64_decode($str));
if(is_array($arr) ) {
* Wrapper for server side redirection
* @author gadhra
* @param string $url URL to redirect to
* @param string $type header type to send
function go($url,$type='301' ) {
$h_types = arr_headers();
header("HTTP/1.1 $type $h_types[$type]");
* When I was moving accounts from MT to WP, I found that the
* old MT binaries were encrypting passwords using CRYPT(), while
* WP was using MD5. This was my workaround - worked about 80% of the
* time. Note: this is real specific to WP, but might have some use to s
* someone. Hooked from the pluggable.php file
* @author gadhra
* @param string $password Plaintext user's password
* @param string $hash Hash of the user's password to check against.
* @return bool False, if the $password does not match the hashed password
function check_crypt_pass($check, $password, $hash, $user_id = '') {
if($check) return true;
$user_info = get_userdata($user_id);
for($i=0;$i<2;$i++) {
$salt .= $hash[$i];
$check= ($hash == crypt($password,$salt) );
if ( $check && $user_id ) {
// Rehash using new hash.
wp_set_password($password, $user_id);
$hash = wp_hash_password($password);
return true;
return false;
* These are all functions that just return arrays I got tired of writing
* @author gadhra
function arr_states( ) {
return array(
'DC'=>'District of Columbia',
'NH'=>'New Hampshire',
'NJ'=>'New Jersey',
'NM'=>'New Mexico',
'NY'=>'New York',
'NC'=>'North Carolina',
'ND'=>'North Dakota',
'PR'=>'Puerto Rico',
'RI'=>'Rhode Island',
'SC'=>'South Carolina',
'SD'=>'South Dakota',
'VI'=>'Virgin Islands',
'WV'=>'West Virginia',
function arr_headers() {
return array(
'101'=>'Switching Protocols',
'203'=>'Non-Authoritative Information',
'204'=>'No Content',
'205'=>'Reset Content',
'206'=>'Partial Content',
'300'=>'Multiple Choices',
'301'=>'Moved Permanently',
'303'=>'See Other',
'304'=>'Not Modified',
'305'=>'Use Proxy',
'307'=>'Temporary Redirect',
'400'=>'Bad Request',
'402'=>'Payment Required',
'404'=>'Not Found',
'405'=>'Method Not Allowed',
'406'=>'Not Acceptable',
'407'=>'Proxy Authentication Required',
'408'=>'Request Timeout',
'411'=>'Length Required',
'412'=>'Precondition Failed',
'413'=>'Request Entity Too Large',
'414'=>'Request-URI Too Long',
'415'=>'Unsupported Media Type',
'416'=>'Requested Range Not Satisfiable',
'417'=>'Expectation Failed',
'500'=>'Internal Server Error',
'501'=>'Not Implemented',
'502'=>'Bad Gateway',
'503'=>'Service Unavailable',
'504'=>'Gateway Timeout',
'505'=>'HTTP Version Not Supported'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment