Resources

My Agape try

Your Agape try


Support Forum

You must be logged in to post Login Register

Search 
Search Forums:


 




Attachment Comment Count

UserPost

4:31 am
January 31, 2009


metal450

Member

posts 178

1

Comment counts for attachments seem to always get reported as zero when RoleScoper is activated (1.0.0-rc8.9113).  They're reported correctly when I deactivate the plugin.

I've got a page that I use as a video gallery, structured as follows:

$videos = get_posts('numberposts=1000&post_type=attachment&post_parent='.$post->ID);
foreach($videos as $thisVideo)
{
    echo "…thumbnail, link, etc…";

   //ALWAYS RETURNS ZERO
    echo get_comments_number($thisVideo->ID) . ' Comments';   
}

11:40 pm
February 6, 2009


Kevin

Admin

posts 2503

2

I think I nabbed the bug that was storing the invalid comment counts on post edit. Therefore, front-end filtering of comment count should not be necessary and is disabled unless you put the following line in wp-config.php:

define( 'SCOPER_FILTER_COMMENT_COUNT', true );

As you discovered before, any remaining corrupted comment count can be cleared by re-saving the post as an administrator.

I would appreciate hearing if this proves to resolve your issues.

8:35 am
February 7, 2009


metal450

Member

posts 178

3

This bug is different from the previous one (where comment counts for regular posts would randomly be displayed as unusually large values when a non-admin user would comment).


In the case of attachments, counts are ALWYAS listed as zero when RS is on.  It doesn't change when someone (myself or other) adds; only turning off the plugin changes the outputted value from 0 to correct.

11:56 am
February 7, 2009


Kevin

Admin

posts 2503

4

In the flt_recent_comments function of plugins/role-scoper/hardway/hardway_rs.php:

change:

if ( ! is_administrator_rs() ) {

to:

if ( ! is_attachment() && ! is_administrator_rs() ) {

12:20 pm
February 7, 2009


metal450

Member

posts 178

5

No dice.


You can see the behavior I'm talking about here: http://www.justin-klein.com/wordpress/videos/fourteen_months (there are two comments, but it says there are none)


Or here: http://www.justin-klein.com/wordpress/videos (for every item, it lists 0 comments)…

4:10 pm
February 7, 2009


Kevin

Admin

posts 2503

6

Can you run a test in your single.php template file and tell me if is_attachment() evaluates true?

4:42 pm
February 7, 2009


metal450

Member

posts 178

7

I'm using video.php (attachment template, http://codex.wordpress.org/Template_Hierarchy#Attachment_display), but yes, is_attachment() evaluates to true :)

5:04 pm
February 7, 2009


Kevin

Admin

posts 2503

8

Okay, so as not to confuse the issue, make sure you have not defined SCOPER_FILTER_COMMENT_COUNT.

Then as a sanity check, the next thing I'd like to know is what happens if you temporarily change:

if ( ! is_attachment() && ! is_administrator_rs() ) {

to:

if ( false && ! is_attachment() && ! is_administrator_rs() ) {

…in hardway_rs.php. This will tell us if I'm barking up the wrong tree. While you're at it, you might throw a temporary

if ( is_administrator_rs() ) die('trying');

into the top of flt_recent_comments just to make sure you're not editing the wrong copy or role scoper. I'll check back in Monday.

5:06 pm
February 7, 2009


metal450

Member

posts 178

9

I've not manually defined SCOPER_FILTER_COMMENT_COUNT (if that's what ur asking?)


Trying the others in 5 mins :)

5:13 pm
February 7, 2009


metal450

Member

posts 178

10

echo defined("SCOPER_FILTER_COMMENT_COUNT")

//shows nothing


iif ( is_administrator_rs() ) die('trying');

//dies as expected


if ( false && ! is_attachment() && ! is_administrator_rs() ) {

//Behavior did not change


5:13 pm
February 7, 2009


metal450

Member

posts 178

11

sorry…those typos were just in my post :)


iif –> if, and the echo DID have a semicolon after it in the pho :P

11:57 am
February 9, 2009


Kevin

Admin

posts 2503

12

Since the comment count is a stored value, it will be off until the next comment is posted with the flt_recent_comments fix in place. If you must have the count updated immediately, submit & delete a fake comment or define SCOPER_FILTER_COMMENT_COUNT (and live with the extra front-end DB queries).

12:01 pm
February 9, 2009


Kevin

Admin

posts 2503

13

You'll need to make one more change to keep the comment count intact on new comment submission. The flt_recent_comments change cited above should be:

if ( empty($_POST) && ! is_attachment() && ! is_administrator_rs() ) {

12:06 pm
February 9, 2009


metal450

Member

posts 178

14

Still didn't get it - note that simply enabling/disabling RoleScoper also causes the zero/correct comment counts to show (without the need for someone to post an additional comment).  The correct values are being stored, i beleive - just not shown…

12:09 pm
February 9, 2009


Kevin

Admin

posts 2503

15

How is your theme calling for the comment count?

12:10 pm
February 9, 2009


metal450

Member

posts 178

16

//ALWAYS RETURNS ZERO (if RS enabled)
    echo get_comments_number($thisVideo->ID) . ' Comments';   

2:13 pm
February 9, 2009


Kevin

Admin

posts 2503

17

So if I'm looking at http://www.justin-klein.com/wordpress/videos/fourteen_months

and the template call is

echo get_comments_number($thisVideo->ID) . ' Comments';

Where does $thisVideo come from?

2:18 pm
February 9, 2009


metal450

Member

posts 178

18

See fiirst post in this thread :)


$videos = get_posts('numberposts=1000&post_type=attachment&post_parent='.$post->ID);
foreach($videos as $thisVideo)
{
    echo "…thumbnail, link, etc…";

   //ALWAYS RETURNS ZERO
    echo get_comments_number($thisVideo->ID) . ' Comments';   
}

2:44 pm
February 9, 2009


Kevin

Admin

posts 2503

19

Yeah, I saw that. But I copied that code into my template and still can't reproduce your error. So I'm trying to reproduce the (seemingly simple) case for a single video.

Do you call get_posts in video.php even when a single video has been requested? In that case, isn't $post->ID the actual attachment ID and not the post_parent?

2:51 pm
February 9, 2009


metal450

Member

posts 178

20

Ah, I see the confusion.  The code I mentioned is not for individual videos, but for the video listing here:

http://www.justin-klein.com/wordpress/videos

It's a "Page" to which I add the attachments (videos). It, like the individual video pages (and photos in some private photo galleries), all echo "0″ for comment counts on attachments.  The full code (minus the header) for that listing is:


$videos = get_posts('numberposts=1000&post_type=attachment&post_parent='.$post->ID);
foreach($videos as $thisVideo)
{
    //Skip image attachments (these will correspond to the video thumbnails)
    if( wp_attachment_is_image( $thisVideo->ID ) ) continue;
   
    //Show the video's thumbnail (stored in the "excerpt" field)
    echo "\n<div class=\"galleryImg\">\n".
    "\t<a href=\"". get_permalink($thisVideo->ID) ."\">" . $thisVideo->post_excerpt . "</a>\n</div>\n";
   
    //Title, time, and country
    echo '<div class="galleryTxt">';
    echo '<h1><a href="' . get_permalink($thisVideo->ID) . '">' . $thisVideo->post_title . '</a></h1>';
    echo '<small>' . mysql2date('F j, Y', $thisVideo->post_date_gmt) . ' in ' . get_country($thisVideo->ID)  . '<br />';
    echo get_comments_number($thisVideo->ID) . ' Comments';   
    if( function_exists('get_view_count') ) echo ', ' . $thisVideo->view_count . ' views.<br />';
    echo '</small>';
    echo '<br />' . strip_tags($thisVideo->post_content) . '<br />';
    echo '</div>';
   
    echo "<br clear=\"all\" />\n";
    echo "<hr />\n";
}


About the Agapetry forum

Currently Online:

13 Guests

Maximum Online: 150

Forums:

Groups: 2

Forums: 7

Topics: 1245

Posts: 5653

Members:

There are 1255 members

There are 1 guests


Kevin has made 2503 posts

Top Posters:

metal450 - 178

Ragnar - 108

YikYak - 70

whiteorb - 49

Daisy - 35

Administrator: Kevin | Moderators: Kevin