Opened 3 years ago

Last modified 2 years ago

#11566 new defect (bug)

clean_comment_cache() does not clean $GLOBALS['comment']

Reported by: sirzooro Owned by:
Priority: normal Milestone: Future Release
Component: Comments Version: 2.9
Severity: normal Keywords: has-patch
Cc: beau@…

Description

I am trying to add links to comment list, which will allow to delete comments directly without need to move them to trash first (and with trash enabled). For posts/pages I found working workaround: hook trashed_post and call wp_delete_post() again from.

Unfortunately similar approach for comments does work. As I checked, wp_trash_comment() calls get_comment(). The latter function implements simple comments cache using $GLOBALS['comment']. When you change comment status to trash, wp_set_comment_status() clears cache by calling clean_comment_cache(), but it leaves that global set. As a result my workaround does not work.

I think that clean_comment_cache() should clear that global too.

Attachments (1)

comment.php.diff (495 bytes) - added by sirzooro 3 years ago.

Download all attachments as: .zip

Change History (6)

$GLOBALS['comment'] =/= a comment cache

comment:2 in reply to: ↑ description   hakre3 years ago

Replying to sirzooro:

As I checked, wp_trash_comment() calls get_comment(). The latter function implements simple comments cache using $GLOBALS['comment'].

Why not fix that function to use the propper cache instead of a global?

  • Milestone changed from 2.9.1 to 3.0

get_comment() uses wp_cache_add()/wp_cache_get(), and additionally that global.

As I checked, $GLOBALScomment? is set by Walker_Comment::start_el(), and functions from comment-template.php relies on this variable. Therefore my patch may introduce bug when some plugin will change comment when it is displayed. Looks that other solution may be needed here.

BTW, I clear this variable in my comment, so it works now. Therefore I think we can move this to 3.0.

  • Milestone changed from 3.0 to Future Release
  • Cc beau@… added
Note: See TracTickets for help on using tickets.