Skip to:
Content

bbPress.org

Ticket #2653: 2653.2.diff

File 2653.2.diff, 3.0 KB (added by netweb, 11 years ago)
  • src/includes/topics/functions.php

     
    338338
    339339        /** No Errors *************************************************************/
    340340
    341         if ( ! empty( $topic_id ) && ! is_wp_error( $topic_id ) ) {
     341        if ( !empty( $topic_id ) && !is_wp_error( $topic_id ) ) {
    342342
     343                /** Close Check *******************************************************/
     344
     345                // If the topic is closed, close it properly
     346                if ( ( get_post_field( 'post_status', $topic_id ) === bbp_get_closed_status_id() ) || ( $topic_data['post_status'] === bbp_get_closed_status_id() ) ) {
     347
     348                        // Close the topic
     349                        bbp_close_topic( $topic_id );
     350                }
     351
    343352                /** Trash Check *******************************************************/
    344353
    345354                // If the forum is trash, or the topic_status is switched to
     
    27582767 *
    27592768 * @param int $topic_id Topic id
    27602769 * @uses bbp_get_topic() To get the topic
     2770 * @uses get_post_meta() To get the topic status meta
    27612771 * @uses do_action() Calls 'bbp_close_topic' with the topic id
    27622772 * @uses add_post_meta() To add the previous status to a meta
     2773 * @uses post_type_supports() To check if revisions are enabled
     2774 * @uses bbp_get_topic_post_type() To get the topic post type
     2775 * @uses remove_post_type_support() To temporarily remove topic revisions
     2776 * @uses add_post_type_support() To restore topic revisions
    27632777 * @uses wp_update_post() To update the topic with the new status
    27642778 * @uses do_action() Calls 'bbp_opened_topic' with the topic id
    27652779 * @return mixed False or {@link WP_Error} on failure, topic id on success
     
    27722786                return $topic;
    27732787        }
    27742788
    2775         // Bail if already closed
    2776         if ( bbp_get_closed_status_id() === $topic->post_status ) {
     2789        // Get previous topic status meta
     2790        $topic_status = get_post_meta( $topic_id, '_bbp_status', true );
     2791
     2792        // Bail if already closed and topic status meta exists
     2793        if ( bbp_get_closed_status_id() === $topic->post_status && ! empty( $topic_status ) ) {
    27772794                return false;
    27782795        }
    27792796
     2797        // Set status meta public
     2798        $topic_status = bbp_get_public_status_id();
     2799
    27802800        // Execute pre close code
    27812801        do_action( 'bbp_close_topic', $topic_id );
    27822802
    27832803        // Add pre close status
    2784         add_post_meta( $topic_id, '_bbp_status', $topic->post_status );
     2804        add_post_meta( $topic_id, '_bbp_status', $topic_status );
    27852805
    27862806        // Set closed status
    27872807        $topic->post_status = bbp_get_closed_status_id();
    27882808
    2789         // No revisions
    2790         remove_action( 'pre_post_update', 'wp_save_post_revision' );
     2809        // Toggle revisions off as we are not altering content
     2810        if ( post_type_supports( bbp_get_topic_post_type(), 'revisions' ) ) {
     2811                $revisions_removed = true;
     2812                remove_post_type_support( bbp_get_topic_post_type(), 'revisions' );
     2813        }
    27912814
    27922815        // Update topic
    27932816        $topic_id = wp_update_post( $topic );
    27942817
     2818        // Toggle revisions back on
     2819        if ( true === $revisions_removed ) {
     2820                $revisions_removed = false;
     2821                add_post_type_support( bbp_get_topic_post_type(), 'revisions' );
     2822        }
     2823
    27952824        // Execute post close code
    27962825        do_action( 'bbp_closed_topic', $topic_id );
    27972826