Make WordPress Core

Opened 14 years ago

Closed 9 years ago

#11566 closed defect (bug) (fixed)

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

Reported by: sirzooro's profile sirzooro Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 2.9
Component: Comments Keywords: has-patch dev-feedback
Focuses: Cc:

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 14 years ago.

Download all attachments as: .zip

Change History (15)

#1 @hakre
14 years ago

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

#2 in reply to: ↑ description @hakre
14 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?

#3 @sirzooro
14 years ago

  • 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.

#4 @nacin
14 years ago

  • Milestone changed from 3.0 to Future Release

#5 @beaulebens
13 years ago

  • Cc beau@… added

#6 @chriscct7
10 years ago

  • Keywords dev-feedback added

#7 @wonderboymusic
9 years ago

  • Milestone changed from Future Release to 4.4
  • Owner set to wonderboymusic
  • Status changed from new to assigned

there are some weird uses of $comment global

#8 @wonderboymusic
9 years ago

In 33824:

WP_Widget_Pages::widget() has no reason to set $comment and $comments globals.

See #11566.

#9 @wonderboymusic
9 years ago

In 33826:

WP_Comments_List_Table::single_row() has no reason to set the $comment global. No other methods use it, and we are not in template/loop context. This can mess with the response of get_comment() elsewhere, since get_comment() internally bypasses the cache/db when a global is set.

See #11566.

#10 @wonderboymusic
9 years ago

In 33828:

Fix warnings after [33826]. Only only one function call needs a global $comment, we shall hamburger it.

See #11566.

#11 @wonderboymusic
9 years ago

In 33829:

Remove the hamburger global'ing from [33828]: since no args are passed to comment_author_email_link(), the internals can be simplified and applied inline.

See #11566.

This ticket was mentioned in Slack in #core by drew. View the logs.


9 years ago

#13 @DrewAPicture
9 years ago

In 33830:

Docs: Add a duplicate filter comment to the comment_email filter call in WP_Comments_List_Table, introduced in [33829].

See #11566.

#14 @wonderboymusic
9 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

Fixed via [33891]

Note: See TracTickets for help on using tickets.