Skip to:
Content

bbPress.org

Changeset 4524


Ignore:
Timestamp:
11/26/2012 05:43:43 PM (11 years ago)
Author:
johnjamesjacoby
Message:

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.
Location:
trunk/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/forums/functions.php

    r4508 r4524  
    19441944        return;
    19451945
    1946     // Forum is being permanently deleted, so its topics gotta go too
    1947     if ( $topics = new WP_Query( array(
     1946    // Forum is being permanently deleted, so its content has go too
     1947    // Note that we get all post statuses here
     1948    $topics = new WP_Query( array(
    19481949        'suppress_filters' => true,
    19491950        'post_type'        => bbp_get_topic_post_type(),
    19501951        'post_parent'      => $forum_id,
    1951         'post_status'      => 'any',
     1952        'post_status'      => array_keys( get_post_stati() ),
    19521953        'posts_per_page'   => -1,
    19531954        'nopaging'         => true,
    19541955        'fields'           => 'id=>parent'
    1955     ) ) ) {
     1956    ) );
     1957
     1958    // Loop through and delete child topics. Topic replies will get deleted by
     1959    // the bbp_delete_topic() action.
     1960    if ( !empty( $topics->posts ) ) {
    19561961        foreach ( $topics->posts as $topic ) {
    19571962            wp_delete_post( $topic->ID, true );
     
    19611966        wp_reset_postdata();
    19621967    }
     1968
     1969    // Cleanup
     1970    unset( $topics );
    19631971}
    19641972
  • trunk/includes/topics/functions.php

    r4522 r4524  
    29352935
    29362936    // Topic is being permanently deleted, so its replies gotta go too
    2937     if ( $replies = new WP_Query( array(
     2937    // Note that we get all post statuses here
     2938    $replies = new WP_Query( array(
    29382939        'suppress_filters' => true,
    29392940        'post_type'        => bbp_get_reply_post_type(),
    2940         'post_status'      => 'any',
     2941        'post_status'      => array_keys( get_post_stati() ),
    29412942        'post_parent'      => $topic_id,
    29422943        'posts_per_page'   => -1,
    29432944        'nopaging'         => true,
    29442945        'fields'           => 'id=>parent'
    2945     ) ) ) {
     2946    ) );
     2947
     2948    // Loop through and delete child replies
     2949    if ( ! empty( $replies->posts ) ) {
    29462950        foreach ( $replies->posts as $reply ) {
    29472951            wp_delete_post( $reply->ID, true );
     
    29512955        wp_reset_postdata();
    29522956    }
     2957
     2958    // Cleanup
     2959    unset( $replies );
    29532960}
    29542961
     
    29772984
    29782985    // Topic is being trashed, so its replies are trashed too
    2979     if ( $replies = new WP_Query( array(
     2986    $replies = new WP_Query( array(
    29802987        'suppress_filters' => true,
    29812988        'post_type'        => bbp_get_reply_post_type(),
     
    29852992        'nopaging'         => true,
    29862993        'fields'           => 'id=>parent'
    2987     ) ) ) {
     2994    ) );
     2995
     2996    if ( !empty( $replies->posts ) ) {
    29882997
    29892998        // Prevent debug notices
     
    30043013        wp_reset_postdata();
    30053014    }
     3015
     3016    // Cleanup
     3017    unset( $replies );
    30063018}
    30073019
Note: See TracChangeset for help on using the changeset viewer.