Why is this function causing a white screen of death?
-
I am writing a WordPress plugin with a function to run replacements on a string like “@richardxthripp [TITLE] [URL] – posted [DATE] in [CATEGORY] by [AUTHOR] on [BLOG_TITLE]” but limit the string to 140 characters for Twitter. However, this function appears to cause every public page (not back-end pages) to display only a white screen, after several seconds of loading. No errors are logged or displayed, even when WP_DEBUG is set to true. While the plugin contains many other functions, I did a diff against the last known working version and applied the changes one by one until the white screen returned, which was when I added the function below.
/** * Performs replacements on a string for the current post in the loop. * @package tweet-this * @since 1.7.7 */ function get_tt_parse_string($text = '', $url = '', $space = ' ', $service = 'twitter', $title = '') { if($url == '') $url = get_tweet_this_short_url(); if($title == '') $title = get_the_title(); if(function_exists('get_the_author_meta')) $author = get_the_author_meta('nickname'); else $author = get_the_author_nickname(); $category = null; $categories = get_the_category(); if($categories > 0) $category = $categories[0]->cat_name; $excerpt = get_the_excerpt(); if(strlen($excerpt) > 50) { $excerpt = substr($excerpt . ' ', 0, 47); $excerpt = substr($excerpt, 0, strrpos($excerpt, ' ')) . '...';} $matches = array('[TITLE]', '[TITLE_SHARE]', '[AUTHOR]', '[CATEGORY]', '[DATE]', '[EXCERPT]', '[BLOG_TITLE]'); $replacements = array(get_tweet_this_trim_title($title, $text), get_tweet_this_trim_title($title, $text, 'twitter-share'), $author, $category, the_date('', '', '', FALSE), $excerpt, get_bloginfo('name')); $final_text = str_replace($matches, $replacements, $text); if($service != 'twitter-share' && strpos($final_text, '[URL]') !== false && (strlen($final_text) > (145 - get_tt_url_service_len()))) $final_text = substr(str_replace('[URL]', '', preg_replace("/(40)+/", " ", $final_text)), 0, (136 - get_tt_url_service_len())) . '... ' . $url; elseif($service != 'twitter-share' && strpos($final_text, '[URL]') === false && strlen($final_text) > 140) $final_text = substr($final_text, 0, 137) . '...'; else $final_text = str_replace('[URL]', $url, $final_text); return str_replace(' ', $space, $final_text); }
Any ideas? Incidentally, I have tested this plugin on WP 1.5, 2.1, 2.3, 2.5, 2.7, and 3.0.1. It works fine on WP 1.5, but every newer version gives the white screen of death.
- The topic ‘Why is this function causing a white screen of death?’ is closed to new replies.