WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Customised Plugin Broken with 3.0 - Please help (2 posts)

  1. jameslp
    Member
    Posted 3 years ago #

    I have a customised plugin (based on an abandoned plugin, modified to work again) that counts the number of comments and trackbacks to allow me to insert a string stating how many there are.

    It has worked perfectly for over 2 years, but 3.0 has broken it! It now returns "No Reader Comments" and "No Linkbacks from Other Sites" even when there are. Can anyone spot what could be wrong with it?

    I've checked the SQL in phpmyadmin (replacing the variables with example IDs) and everything still seems to be OK with that.

    Plugin Code:

    <?php
    function count_comments($zero = false, $one = false, $more = false, $deprecated = '')
    {
    	global $wpdb, $tablecomments, $post;
    	$comments = $wpdb->get_results("SELECT * FROM $tablecomments WHERE comment_post_ID = $post->ID AND  comment_type <> 'pingback' AND  comment_type <> 'trackback' AND comment_approved = '1'");
    
    	$number = count($comments);
    
    	if ( $number > 1 )
    			$output = str_replace('%', $number, ( false === $more ) ? __('% Comments') : $more);
    		elseif ( $number == 0 )
    			$output = ( false === $zero ) ? __('No Comments') : $zero;
    		else // must be one
    			$output = ( false === $one ) ? __('1 Comment') : $one;
    
    	echo apply_filters('count_comments', $output, $number);
    
    }
    
    function count_trackbacks($zero = false, $one = false, $more = false, $deprecated = '') {
    	global $wpdb, $tablecomments, $post;
    	$trackbacks = $wpdb->get_results("SELECT * FROM $tablecomments WHERE comment_post_ID = $post->ID AND  (comment_type = 'pingback' OR comment_type = 'trackback') AND comment_approved = '1'");
    
    	$number = count($trackbacks);
    
    	if ( $number > 1 )
    			$output = str_replace('%', $number, ( false === $more ) ? __('% Comments') : $more);
    		elseif ( $number == 0 )
    			$output = ( false === $zero ) ? __('No Comments') : $zero;
    		else // must be one
    			$output = ( false === $one ) ? __('1 Comment') : $one;
    
    	echo apply_filters('count_trackbacks', $output, $number);
    }
    
    ?>

    Theme Code:

    <?php if ($comments) : ?>
    	<div class="comments"><h3 id="comments"><?php count_comments('No Reader Comments', '1 Reader Comment', '% Reader Comments') ?></h3></div>
    
    	<ol class="commentlist">
    ...

    and

    <div class="linkbacks"><h3 id="linkbacks"><?php count_trackbacks('No Linkbacks from Other Sites', '1 Linkback from Another Site', '% Linkbacks from Other Sites') ?></h3></div>

  2. jameslp
    Member
    Posted 3 years ago #

    Phew, I found the problem myself after lots of debugging on a test blog. I was using an old variable that has been discontinued in 3.0 - $tablecomments. I've replaced it with $wpdb->comments and it's back up and running again! :-)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.