[buddypress-trac] [BuddyPress Trac] #5339: comments_template() runs during theme compatibility

buddypress-trac noreply at wordpress.org
Wed Jan 15 21:40:34 UTC 2014


#5339: comments_template() runs during theme compatibility
--------------------------+-----------------------
 Reporter:  r-a-y         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  1.9.2
Component:  Core          |    Version:
 Severity:  normal        |   Keywords:  has-patch
--------------------------+-----------------------
 r7735 changed the reset post arguments so `'is_page'` is set to true.

 If a theme's page.php template uses `comments_template()`, that function
 will now run since `'is_page'` is set to true:
 https://core.trac.wordpress.org/browser/tags/3.8/src/wp-includes/comment-
 template.php#L1020

 Previously, this did not run at all since `'is_archive'` was set.

 What happens is a comments loop is shown when a user is logged out.
 (Props to imath for testing.)  This obviously isn't great.

 I've come up with two ways to address the issue.

 '''1)''' `toggle_is_page.patch` toggles the `'is_page'` and `'is_single'`
 flags at the very end of object buffering.  This forces
 comments_template() to
 [https://core.trac.wordpress.org/browser/tags/3.8/src/wp-includes/comment-
 template.php#L1020 bail out of rendering the rest of that function], which
 is great because we don't want any additional DB queries or requiring to
 load the comments template.  I tried some other things like toggling the
 `$withcomments` global to false, but that did not work.

 '''2)''' `current_comment.patch` alters `bp_theme_compat_reset_post()` so
 `$wp_query->current_comment` is greater than `$wp_query->comment_count` in
 .  This forces `have_comments()` to always be false.  However, this will
 still load up the entire comments_template() function, which will lead to
 the DB queries and loading of the comments template I mention in point 1.

 ----

 I've tested this Twenty Twelve, but you can test with any theme calling
 `comments_template()` in their post loop in page.php.

 I'm an advocate of point 1, but it isn't the most elegant piece of code
 ever.  Thoughts?

--
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/5339>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list