WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] Why is this function causing a white screen of death?

[Resolved] Why is this function causing a white screen of death?

  • richardxthripp

    @richardxthripp

    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.

Viewing 3 replies - 1 through 3 (of 3 total)
  • richardxthripp

    @richardxthripp

    I have discovered the error Apache is logging is:

    child pid ##### exit signal Segmentation fault (11)

    What does this mean?

    richardxthripp

    @richardxthripp

    Accessing get_the_excerpt() is causing the segmentation faults. If I set the excerpt as $excerpt = '', the plugin works fine (except for the lack of excerpts). This is a WordPress core function and I could not find any results on Google for “get_the_excerpt segmentation fault” so apparently no one else has experienced this problem.

    richardxthripp

    @richardxthripp

    My final decision was to write this function:

    /**
     * Returns the post excerpt, truncated with "..." if it exceeds $chars.
     * @package tweet-this
     * @since 1.8
     */
    function tt_get_the_excerpt($post_id = '', $chars = 70) {
    	if($post_id == '') {global $id; $post_id = $id;}
    	// tt_get_post($post_id) will not work here, for unknown reasons.
    	if(function_exists('get_post')) {
    		$gp = get_post($post_id);
    		$content = $gp->post_content;
    		$excerpt = $gp->post_excerpt;}
    	else {	$gp = get_postdata($post_id);
    		$content = $gp['Content'];
    		$excerpt = $gp['Excerpt'];}
    	if(trim($excerpt) != '')
    		$pxcr = strip_tags(tt_strip_shortcodes($excerpt));
    	else $pxcr = strip_tags(tt_strip_shortcodes($content));
    	if(strlen($pxcr) > $chars)
    		$pxcr = tt_mb_substr($pxcr, 0, ($chars - 3)) . '...';
    	return $pxcr;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Why is this function causing a white screen of death?’ is closed to new replies.