Opened 6 months ago

Closed 6 months ago

Last modified 6 months ago

#2059 closed defect (fixed)

bbp_delete_topic is not deleting the child replies

Reported by: MZAWeb Owned by: MZAWeb
Priority: normal Milestone: 2.3
Component: Code Improvement Version: 2.2
Severity: major Keywords: has-patch commit
Cc: wordpress@…

Description

The query generated by the WP_Query in there looks like:

SELECT   wp_posts.ID, wp_posts.post_parent FROM wp_posts  WHERE 1=1  AND wp_posts.post_parent = 93  AND wp_posts.post_type = 'reply' AND (wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft' AND wp_posts.post_status <> 'spam' AND wp_posts.post_status <> 'orphan' AND wp_posts.post_status <> 'hidden')  ORDER BY wp_posts.post_date DESC 

It seems the post_status => any is getting lost somehow.

I'm on WordPress 3.5 trunk

Attachments (2)

2059.diff (1.4 KB) - added by MZAWeb 6 months ago.
2059.2.diff (1.4 KB) - added by MZAWeb 6 months ago.

Download all attachments as: .zip

Change History (13)

  • Cc wordpress@… added

Interesting! The post_status=>any won't work for us. get_post excludes all the stati that has 'exclude_from_search':

if ( ! empty( $q['post_status'] ) ) {

... more code ...

if ( in_array('any', $q_status) ) {
				foreach ( get_post_stati( array('exclude_from_search' => true) ) as $status )
					$e_status[] = "$wpdb->posts.post_status <> '$status'";

... more code ...

} elseif ( !$this->is_singular ) {

... more code ...

if ( $this->is_admin ) {
				// Add protected states that should show in the admin all list.
				$admin_all_states = get_post_stati( array('protected' => true, 'show_in_admin_all_list' => true) );
				foreach ( (array) $admin_all_states as $state )
					$where .= " OR $wpdb->posts.post_status = '$state'";
			}

... more code ...

}

so, the $this->is_admin is not kicking in when post_status=>any

  • Component changed from Topics to Code Improvement
  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 2.3

Looks like the safest thing we can do here is include an array of every single post status that's possible for these to have. Being explicit appears to override any of the additional checks that WP_Query::get_posts() does.

I see two usages of post_status 'any' that would need this.

Last edited 6 months ago by johnjamesjacoby (previous) (diff)

Makes sense. I'll take a pass next week. So,

[publish] => publish
[future] => future
[draft] => draft
[pending] => pending
[private] => private
[trash] => trash
[auto-draft] => auto-draft
[inherit] => inherit

Probably all, right?

Last edited 6 months ago by MZAWeb (previous) (diff)
  • Owner set to MZAWeb
  • Status changed from new to assigned

MZAWeb6 months ago

  • Keywords has-patch added; needs-patch removed

Attached a fix.

Don't forget the bbPress statuses: closed, spam, etc...

get_post_stati returns the bbp stati too:

Array
(
    [0] => publish
    [1] => future
    [2] => draft
    [3] => pending
    [4] => private
    [5] => trash
    [6] => auto-draft
    [7] => inherit
    [8] => closed
    [9] => spam
    [10] => orphan
    [11] => hidden
)

MZAWeb6 months ago

  • Keywords commit added

Nice.

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

(In [4524]) Deleting:

  • When deleting a forum or topic, make sure all child content is deleted also.
  • Also add some inline doc, and unset query variables, and clean up messy inline comparisons.
  • Props MZAWeb.
  • Fixes #2059.

(In [4525]) Supplemental update to bbp_trash_forum_topics(). See #2059.

Note: See TracTickets for help on using tickets.