Commit Graph

116 Commits

Author SHA1 Message Date
Boone Gorges
18d6b3c8dc Force comment pagination on single posts.
Previously, the 'page_comments' toggle allowed users to disable comment
pagination. This toggle was only superficial, however. Even with
'page_comments' turned on, `comments_template()` loaded all of a post's
comments into memory, and passed them to `wp_list_comments()` and
`Walker_Comment`, the latter of which produced markup for only the
current page of comments. In other words, it was possible to enable
'page_comments', thereby showing only a subset of a post's comments on a given
page, but all comments continued to be loaded in the background. This technique
scaled poorly. Posts with hundreds or thousands of comments would load slowly,
or not at all, even when the 'comments_per_page' setting was set to a
reasonable number.

Recent changesets have addressed this problem through more efficient tree-
walking, better descendant caching, and more selective queries for top-level
post comments. The current changeset completes the project by addressing the
root issue: that loading a post causes all of its comments to be loaded too.

Here's the breakdown:

* Comment pagination is now forced. Setting 'page_comments' to false leads to evil things when you have many comments. If you want to avoid pagination, set 'comments_per_page' to something high.
* The 'page_comments' setting has been expunged from options-discussion.php, and from places in the codebase where it was referenced. For plugins relying on 'page_comments', we now force the value to `true` with a `pre_option` filter.
* `comments_template()` now queries for an appropriately small number of comments. Usually, this means the `comments_per_page` value.
* To preserve the current (odd) behavior for comment pagination links, some unholy hacks have been inserted into `comments_template()`. The ugliness is insulated in this function for backward compatibility and to minimize collateral damage. A side-effect is that, for certain settings of 'default_comments_page', up to 2x the value of `comments_per_page` might be fetched at a time.
* In support of these changes, a `$format` parameter has been added to `WP_Comment::get_children()`. This param allows you to request a flattened array of comment children, suitable for feeding into `Walker_Comment`.
* `WP_Query` loops are now informed about total available comment counts and comment pages by the `WP_Comment_Query` (`found_comments`, `max_num_pages`), instead of by `Walker_Comment`.

Aside from radical performance improvements in the case of a post with many
comments, this changeset fixes a bug that caused the first page of comments to
be partial (`found_comments` % `comments_per_page`), rather than the last, as
you'd expect.

Props boonebgorges, wonderboymusic.
Fixes #8071.
Built from https://develop.svn.wordpress.org/trunk@34561


git-svn-id: http://core.svn.wordpress.org/trunk@34525 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-25 20:40:25 +00:00
Boone Gorges
4c18ad595e Improve status checks when sending comment post author notification.
[34537] hooked `wp_new_comment_notify_postauthor()` to the
'wp_set_comment_status' when a comment had been approved. When performing
multiple actions on a comment in the same request (as happens in
`Tests_Ajax_DeleteComment::test_ajax_trash_double_action()`, and may happen
sometimes in real life too), and when one of those actions involves deleting
the comment, the `$comment_ID` passed to `wp_new_comment_notify_postauthor()`
can correspond to an already-deleted comment. The `comment_status` check should
account for this possibility.

See #14078.
Built from https://develop.svn.wordpress.org/trunk@34545


git-svn-id: http://core.svn.wordpress.org/trunk@34509 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-25 14:43:24 +00:00
Boone Gorges
eaaabd4105 Send comment approval notification to post author via hook.
This is part of the project of #33587.

Moving this particular message to the
'wp_set_comment_status' action has the added bonus that the notification is
sent after the comment status has been updated in the database. Previously, a
database error could lead to a case where an approval notification is sent,
but the comment status change fails for some reason.

Props mrmist, NickDuncan.
Fixes #14078.
Built from https://develop.svn.wordpress.org/trunk@34537


git-svn-id: http://core.svn.wordpress.org/trunk@34501 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-25 05:37:25 +00:00
Boone Gorges
cb586896c6 Introduce 'duplicate_comment_id' filter.
`wp_allow_comment()` disallows a comment if it matches a comment on the same
post with the same content, author email, and parent. This new filter allows
developers to circumvent or modify this logic, making the duplicate check
more or less lenient, as they see fit.

Fixes #9775.
Built from https://develop.svn.wordpress.org/trunk@34536


git-svn-id: http://core.svn.wordpress.org/trunk@34500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-25 05:23:28 +00:00
Boone Gorges
e2c57a9451 Use WP_Comment_Query in get_page_of_comment().
This change allows `get_page_of_comment()` to use `WP_Comment_Query`'s native
caching mechanisms.

Props boonebgorges, Viper007Bond, wmertens, jeremyfelt.
Fixes #11334.
Built from https://develop.svn.wordpress.org/trunk@34535


git-svn-id: http://core.svn.wordpress.org/trunk@34499 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-25 05:11:25 +00:00
Boone Gorges
fd946a9b5a Pinking shears.
Built from https://develop.svn.wordpress.org/trunk@34534


git-svn-id: http://core.svn.wordpress.org/trunk@34498 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-25 04:44:25 +00:00
Boone Gorges
2370a81286 Allow metadata to be attached to comment at time of creation.
The new `$comment_meta` parameter of `wp_insert_comment()` allows an array of
key/value pairs to be passed when creating a comment. These pairs are then
stored as commentmeta when the comment has been created.

Props tellyworth, wonderboymusic.
Fixes #12431.
Built from https://develop.svn.wordpress.org/trunk@34533


git-svn-id: http://core.svn.wordpress.org/trunk@34497 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-25 04:41:25 +00:00
Scott Taylor
59279c5f8b Comments: In get_comment_statuses(), also return trash.
XML-RPC: In `wp_xmlrpc_server::wp_editComment()`, allow comments to be trashed.

Introduce unit tests for `wp_editComment` in `xmlrpc/*` #NeverForget

Props tyxla, wonderboymusic.
Fixes #30965.

Built from https://develop.svn.wordpress.org/trunk@34524


git-svn-id: http://core.svn.wordpress.org/trunk@34488 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-24 21:48:27 +00:00
Scott Taylor
223a2d0f7b Comments: in check_comment_flood_db(), don't throttle moderators. If the commenter is logged in, check against their user_id instead of comment_author_IP.
Throwback: "If you can edit comments on the post, 'Slow down Cowboy' shouldn't kick in."

Props garyc40, wonderboymusic.
Fixes #16219.

Built from https://develop.svn.wordpress.org/trunk@34522


git-svn-id: http://core.svn.wordpress.org/trunk@34486 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-24 21:22:25 +00:00
Scott Taylor
939d9b7395 Remove some unused globals and/or their docs.
See ##33491.

Built from https://develop.svn.wordpress.org/trunk@34446


git-svn-id: http://core.svn.wordpress.org/trunk@34410 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-22 20:27:25 +00:00
Drew Jaynes
35977a06e7 Docs: The Comments subpackage is plural.
See #33701.

Built from https://develop.svn.wordpress.org/trunk@34411


git-svn-id: http://core.svn.wordpress.org/trunk@34375 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-22 13:45:26 +00:00
Drew Jaynes
8df8fb6046 Docs: The Comment API is singular.
See #33701.

Built from https://develop.svn.wordpress.org/trunk@34409


git-svn-id: http://core.svn.wordpress.org/trunk@34373 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-22 13:43:25 +00:00
Drew Jaynes
b051f0f6c8 Docs: Add a description for the documented use of the $wpdb global in _prime_comment_caches().
See #8071. See #32246.

Built from https://develop.svn.wordpress.org/trunk@34355


git-svn-id: http://core.svn.wordpress.org/trunk@34319 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-20 09:39:23 +00:00
Boone Gorges
c6c9f8ad26 Split the comment query.
`WP_Comment_Query` now fetches comments in two stages: (1) a query to get the
IDs of comments matching the query vars, and (2) a query to populate the
objects corresponding to the matched IDs. The two queries are cached
separately, so that sites with persistent object caches will continue to have
complete cache coverage for normal comment queries.

Splitting the query allows our cache strategy to be more modest and precise, as
full comment data is only stored once per comment. It also makes it possible
to introduce logic for paginated threading, which is necessary to address
certain performance problems.

See #8071.
data is only stored once per comment, instead of along with
Built from https://develop.svn.wordpress.org/trunk@34310


git-svn-id: http://core.svn.wordpress.org/trunk@34274 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-18 19:28:51 +00:00
Boone Gorges
32887d3dfb Lazy-load comment meta on single post pages.
[34268] introduced cache priming for commentmeta, enabled by default. To
ensure performance on single post pages - where commentmeta is most likely
to cause performance issues - we disable up-front cache-priming. Instead, we
prime commentmeta caches for all comments in the loop the first time
`get_comment_meta()` is called on the page.

Props bradt, dd32, wonderboymusic, boonebgorges.
Fixes #16894.
Built from https://develop.svn.wordpress.org/trunk@34270


git-svn-id: http://core.svn.wordpress.org/trunk@34234 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-17 20:01:24 +00:00
Boone Gorges
bb43f72692 Prime comment meta caches in WP_Comment_Query.
The new 'update_comment_meta_cache' parameter, which defaults to `true`, can
be used to disable this behavior.

`update_comment_cache()` has been updated to support an `$update_meta_cache`
parameter, which also updates to true; this matches the pattern we use for
priming post caches.

See #16894.
Built from https://develop.svn.wordpress.org/trunk@34268


git-svn-id: http://core.svn.wordpress.org/trunk@34232 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-17 19:30:27 +00:00
Sergey Biryukov
444509e246 Docs: Expand the $comment_approved argument description for 'comment_post' action.
Props cfinke.
Fixes #33903.
Built from https://develop.svn.wordpress.org/trunk@34253


git-svn-id: http://core.svn.wordpress.org/trunk@34217 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-16 22:30:23 +00:00
Boone Gorges
48b7547a52 Improve consistency of comment notification callback signatures.
Both `wp_new_comment_notify_moderator()` and `wp_new_comment_notify_postauthor()`
now accept a single argument: `$comment_ID`.

Props SergeyBiryukov.
Fixes #33587.
Built from https://develop.svn.wordpress.org/trunk@34252


git-svn-id: http://core.svn.wordpress.org/trunk@34216 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-16 22:26:24 +00:00
Boone Gorges
f6fb4653eb Don't notify post authors about spam comments.
[34106] moved post author notification to a hook, and in the process, missed
the 'spam' check. This changeset restores that check.

To make unit testing easier, the notification callbacks have been refactored
to return values: false when various conditions aren't met (eg, approved
comments should not trigger moderation emails), and the return value of the
`wp_notify_*()` function otherwise.

Props cfinke, kraftbj.
See #33587.
Built from https://develop.svn.wordpress.org/trunk@34250


git-svn-id: http://core.svn.wordpress.org/trunk@34214 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-16 22:00:25 +00:00
Scott Taylor
69e3a390b2 In _wp_ajax_delete_comment_response(), read the new 'all' prop returned by get_comment_count() via wp_count_comments() when setting $total. 'all' doesn't include spam in its count.
Updates unit tests.

Props dipesh.kakadiya.
Fixes #32362.

Built from https://develop.svn.wordpress.org/trunk@34161


git-svn-id: http://core.svn.wordpress.org/trunk@34129 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-15 01:47:25 +00:00
Scott Taylor
31c2bfd69d More bonkers comment cache cleanup: toggle wp_defer_comment_counting() in wp_insert_post() and wp_insert_attachment(). Move the cache deletion in wp_update_comment_count_now() to before the get_post() call, so that the caches get deleted even if the post has already been deleted and the function returns early.
See #33875.

Built from https://develop.svn.wordpress.org/trunk@34158


git-svn-id: http://core.svn.wordpress.org/trunk@34126 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-15 00:58:26 +00:00
Scott Taylor
8479ff90bc Ensure that the count cache for all is in sync with comment-{$post_id} values. These are the values most often relied-upon by the list table for comments.
Adds unit tests.

See #33875.

Built from https://develop.svn.wordpress.org/trunk@34136


git-svn-id: http://core.svn.wordpress.org/trunk@34104 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-14 22:39:24 +00:00
Scott Taylor
60367d567d The "counts" cache for comments by post id is never invalidated. Neither wp_update_comment_count() nor wp_update_comment_count_now() touch the cache.
Adds unit test.
See #33875.

Built from https://develop.svn.wordpress.org/trunk@34131


git-svn-id: http://core.svn.wordpress.org/trunk@34099 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-14 22:04:26 +00:00
Scott Taylor
7639a89a1f wp_unspam_comment() can accept a full object instead of comment_ID to reduce cache/db lookups..
See #33638.

Built from https://develop.svn.wordpress.org/trunk@34130


git-svn-id: http://core.svn.wordpress.org/trunk@34098 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-14 21:47:25 +00:00
Scott Taylor
b1bc8a6522 More comment functions can accept a full object instead of comment_ID to reduce cache/db lookups.
See ##33638.


Built from https://develop.svn.wordpress.org/trunk@34129


git-svn-id: http://core.svn.wordpress.org/trunk@34097 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-14 21:40:24 +00:00
Boone Gorges
c614849786 Send comment notification emails via a hooked function.
Previously, `wp_notify_postauthor()` and `wp_notify_moderator()` were called
directly from `wp_new_comment()`, making it difficult to modify or suppress
default notification emails.

Props dshanske, thomaswm.
See #33587.
Built from https://develop.svn.wordpress.org/trunk@34106


git-svn-id: http://core.svn.wordpress.org/trunk@34074 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-14 02:17:26 +00:00
Scott Taylor
71f955dc84 In WP_Comments_List_Table, favor passing WP_Comment instances instead of $comment_ID to template functions. This allows us to bypass unnecessary cache lookups and simply pass the object through when it is set.
See #33638.

Built from https://develop.svn.wordpress.org/trunk@33964


git-svn-id: http://core.svn.wordpress.org/trunk@33933 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-09 03:00:24 +00:00
Scott Taylor
d973339738 After [33891], get_comment() returns global $comment if no args are passed and the global is set (after setting the default to null here). This allows us to ditch global comment imports.
See #33638.

Built from https://develop.svn.wordpress.org/trunk@33963


git-svn-id: http://core.svn.wordpress.org/trunk@33932 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-09 02:51:24 +00:00
Scott Taylor
c1bb5b5ce3 After [33843], update the location of some files in This filter is documented in docs
Props dimadin.
See #33413.

Built from https://develop.svn.wordpress.org/trunk@33954


git-svn-id: http://core.svn.wordpress.org/trunk@33923 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-08 22:17:26 +00:00
Scott Taylor
00c8fe6b38 Bump the timeout in trackback() to 10 seconds (from 4) to match wp_xmlrpc_server::pingback_ping() and prevent trackback timeouts.
Props gnaka08 for the initial patch.
Fixes #10414.

Built from https://develop.svn.wordpress.org/trunk@33948


git-svn-id: http://core.svn.wordpress.org/trunk@33917 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-08 18:56:25 +00:00
Drew Jaynes
f57d7527e6 Docs: Clarify the file header summary for wp-includes/comment-functions.php, introduced in [33750].
See #33413. See #33701.

Built from https://develop.svn.wordpress.org/trunk@33899


git-svn-id: http://core.svn.wordpress.org/trunk@33868 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-04 01:42:24 +00:00
Scott Taylor
e73ee5ac98 Introduce WP_Comment class to model/strongly-type rows from the comments database table. Inclusion of this class is a pre-req for some more general comment cleanup and sanity.
* Takes inspiration from `WP_Post` and adds sanity to comment caching. 
* Clarifies when the current global value for `$comment` is returned. The current implementation in `get_comment()` introduces side effects and an occasion stale global value for `$comment` when comment caches are cleaned.
* Strongly-types `@param` docs
* This class is marked `final` for now

Props wonderboymusic, nacin.

See #32619.

Built from https://develop.svn.wordpress.org/trunk@33891


git-svn-id: http://core.svn.wordpress.org/trunk@33860 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-09-03 18:17:24 +00:00
Scott Taylor
6ae78f0fe4 Comments: wp_count_comments() can use get_comment_count() internally to makes its DB query, provided that get_comment_count() returns more properties.
Adds/updates unit tests. There were zero (0) unit tests for `wp_count_comments()`.

Fixes #19903. 

Built from https://develop.svn.wordpress.org/trunk@33822


git-svn-id: http://core.svn.wordpress.org/trunk@33790 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-08-31 18:51:22 +00:00
Scott Taylor
107a7104bd Fix the doc block syntax for the 'wp_get_current_commenter' filter.
Props dimadin.
Fixes #33304.

Built from https://develop.svn.wordpress.org/trunk@33811


git-svn-id: http://core.svn.wordpress.org/trunk@33779 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-08-30 03:21:20 +00:00
Scott Taylor
e49980bdc1 get_comment_count() currently increments awaiting_moderation when comments are in the trash. This occurs because case 0: will match any value passed to switch that is a string that isn't specified in the list of cases. This is terrifying.
* Cases for `0` and `1` should be `'1'` and `'0'`
* Add unit tests for `get_comment_count()`. Currently, there are none.

See #33414.

Built from https://develop.svn.wordpress.org/trunk@33806


git-svn-id: http://core.svn.wordpress.org/trunk@33774 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-08-30 02:19:21 +00:00
Scott Taylor
f07ab12359 Comments: move WP_Comment_Query into its own file. comment.php loads the new files, so this is 100% BC if someone is loading comment.php directly. New files created using svn cp.
Creates: 
`class-wp-comment-query.php` 
`comment-functions.php` 

`comment.php` contains only top-level code. Class file only contains the class. Functions file only contains functions.

See #33413.

Built from https://develop.svn.wordpress.org/trunk@33750


git-svn-id: http://core.svn.wordpress.org/trunk@33718 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-08-26 04:27:21 +00:00
ryan
6027cfa946 Reorg comment functions. #2525
git-svn-id: http://svn.automattic.com/wordpress/trunk@3714 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2006-04-19 02:32:12 +00:00
ryan
d650991531 Move clean_url() to functions-formatting.php. #2525
git-svn-id: http://svn.automattic.com/wordpress/trunk@3713 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2006-04-18 04:58:38 +00:00
ryan
31cb659651 Filter comments when updating. Props mdawaffe.
git-svn-id: http://svn.automattic.com/wordpress/trunk@3662 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2006-03-29 20:41:13 +00:00
ryan
25c2dcac3c More comment cookie sanitation.
git-svn-id: http://svn.automattic.com/wordpress/trunk@3577 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2006-02-28 09:49:06 +00:00
ryan
5322fc2faa current user cleanup
git-svn-id: http://svn.automattic.com/wordpress/trunk@3566 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2006-02-22 19:08:55 +00:00
ryan
34398e5a2e Make sure user_id is set before inserting. Props bungeman. fixes #2459
git-svn-id: http://svn.automattic.com/wordpress/trunk@3537 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2006-02-17 01:00:18 +00:00
ryan
60d01b1f96 Use post_type not post_status.
git-svn-id: http://svn.automattic.com/wordpress/trunk@3535 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2006-02-15 07:16:58 +00:00
ryan
dd202ce1f9 Death to trailing tabs. Props Mark J. fixes #2405
git-svn-id: http://svn.automattic.com/wordpress/trunk@3517 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2006-02-12 07:53:23 +00:00
ryan
d96ba966cd Use ->comments instead of . fixes #2294
git-svn-id: http://svn.automattic.com/wordpress/trunk@3442 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2006-01-16 20:03:56 +00:00
ryan
ba29615e7e Trigger pre_ping action outside of loop. Props Mark Jaquith. fixes #2269
git-svn-id: http://svn.automattic.com/wordpress/trunk@3427 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2006-01-11 21:35:36 +00:00
ryan
ee8b3c94df i18n fixes from SteveAgl. fixes #2207
git-svn-id: http://svn.automattic.com/wordpress/trunk@3393 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2006-01-02 21:08:34 +00:00
ryan
00e695e6f5 LJ tweaks.
git-svn-id: http://svn.automattic.com/wordpress/trunk@3375 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2005-12-29 01:25:41 +00:00
ryan
2d9779beba Make sure comment_parent is set.
git-svn-id: http://svn.automattic.com/wordpress/trunk@3331 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2005-12-20 04:28:32 +00:00
ryan
97cd7143da New asyncronous ping method. fixes #2048
git-svn-id: http://svn.automattic.com/wordpress/trunk@3317 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2005-12-16 03:04:33 +00:00