[wp-trac] [WordPress Trac] #19623: Use Comment API in comments_template, rather than hardcoded SQL
WordPress Trac
wp-trac at lists.automattic.com
Mon Jul 23 08:23:07 UTC 2012
#19623: Use Comment API in comments_template, rather than hardcoded SQL
------------------------------------+------------------------------
Reporter: simonwheatley | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Comments | Version: 3.4.1
Severity: normal | Resolution:
Keywords: has-patch dev-feedback |
------------------------------------+------------------------------
Changes (by hardy101):
* cc: hardy101@… (added)
* version: 3.3 => 3.4.1
Comment:
I came up with a patch similar to the one from simonwheatly. Fewer lines
in my patch, but the logic is essentially the same. There are three
conditions for which comments_template() checks when outputting comments
on a post page. 2 out of 3 were using straight SQL in wp-includes
/comment-template.php:
1) If the user is logged in, show them approved comments, as well as
pending comments where the author (user_id) matches their user ID. [Used
direct SQL query - *patched*]
2) If not logged in, and no comment author identified - via WP's author
cookie system wp_get_current_commenter() - just display approved comments.
[Used WP_Comment_Query API]
3) You're an author identified by your browser cookie after leaving a
comment. We'll show you the pending comment if your name and email match
the comment. [Used direct SQL query - *patched*]
My patch takes the 2 SQL queries and ports their query elements to
get_comments() via WP_Comments_Query's query() arguments. I added:
{{{
unapproved_comment_author_user_id
}}}
and
{{{
unapproved_comment_author_data
}}}
The former takes the logged-in user's ID. The latter takes an array
including the author's name and email from the cookie data retrieved by
wp_get_current_commenter() in comments_template()
The patch is a line-for-line swap in comments_template, with 2 new lines
in WP_Comment_Query->query()
The trac ticket scribu mentioned was more about optimizing get_comments().
This patch simply let's us use the benefits of the API that's already
there.
Let's put the infamous
{{{
/** @todo Use API instead of SELECTs. */
}}}
line to rest once and for all...
--
Ticket URL: <http://core.trac.wordpress.org/ticket/19623#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list