Skip to:
Content

bbPress.org

Ticket #2588: 2588.3.diff

File 2588.3.diff, 4.4 KB (added by johnjamesjacoby, 11 years ago)
  • includes/replies/functions.php

     
    249249                }
    250250        }
    251251
    252         /** Reply To **************************************************************/
    253 
    254         // Handle Reply To of the reply; $_REQUEST for non-JS submissions
    255         if ( isset( $_REQUEST['bbp_reply_to'] ) ) {
    256                 $reply_to = (int) $_REQUEST['bbp_reply_to'];
    257         }
    258 
    259         $reply_to = bbp_get_reply_id( $reply_to );
    260 
    261252        /** Unfiltered HTML *******************************************************/
    262253
    263254        // Remove kses filters from title and content for capable users and if the nonce is verified
     
    313304                $reply_status = bbp_get_public_status_id();
    314305        }
    315306
     307        /** Reply To **************************************************************/
     308
     309        // Handle Reply To of the reply; $_REQUEST for non-JS submissions
     310        if ( isset( $_REQUEST['bbp_reply_to'] ) ) {
     311                $reply_to = bbp_validate_reply_to( $_REQUEST['bbp_reply_to'] );
     312        }
     313
    316314        /** Topic Closed **********************************************************/
    317315
    318316        // If topic is closed, moderators can still reply
     
    562560
    563561        $forum_id = bbp_get_topic_forum_id( $topic_id );
    564562
    565         /** Reply To **************************************************************/
    566 
    567         $reply_to = bbp_get_reply_to( $reply_id );
    568 
    569563        // Forum exists
    570564        if ( !empty( $forum_id ) && ( $forum_id !== bbp_get_reply_forum_id( $reply_id ) ) ) {
    571565
     
    636630                $reply_status = $reply->post_status;
    637631        }
    638632
     633        /** Reply To **************************************************************/
     634
     635        // Handle Reply To of the reply; $_REQUEST for non-JS submissions
     636        if ( isset( $_REQUEST['bbp_reply_to'] ) ) {
     637                $reply_to = bbp_validate_reply_to( $_REQUEST['bbp_reply_to'] );
     638        }
     639
    639640        /** Topic Tags ************************************************************/
    640641
    641642        // Either replace terms
     
    793794        $reply_id = bbp_get_reply_id( $reply_id );
    794795        $topic_id = bbp_get_topic_id( $topic_id );
    795796        $forum_id = bbp_get_forum_id( $forum_id );
    796         $reply_to = bbp_get_reply_id( $reply_to );
     797        $reply_to = bbp_validate_reply_to( $reply_to );
    797798
    798799        // Bail if there is no reply
    799800        if ( empty( $reply_id ) )
     
    11121113
    11131114        // Validation
    11141115        $reply_id = bbp_get_reply_id( $reply_id );
    1115         $reply_to = bbp_get_reply_id( $reply_to );
     1116        $reply_to = bbp_validate_reply_to( $reply_to );
    11161117
    1117         // Return if no reply
    1118         if ( empty( $reply_id ) )
    1119                 return;
     1118        // Update or delete the `reply_to` postmeta
     1119        if ( ! empty( $reply_id ) ) {
    11201120
    1121         // Set the reply to
    1122         if ( !empty( $reply_to ) ) {
    1123                 update_post_meta( $reply_id, '_bbp_reply_to', $reply_to );
     1121                // Update the reply to
     1122                if ( !empty( $reply_to ) ) {
     1123                        update_post_meta( $reply_id, '_bbp_reply_to', $reply_to );
    11241124
    1125         // Delete the reply to
    1126         } else {
    1127                 delete_post_meta( $reply_id, '_bbp_reply_to' );
     1125                // Delete the reply to
     1126                } else {
     1127                        delete_post_meta( $reply_id, '_bbp_reply_to' );
     1128                }
    11281129        }
    11291130
    11301131        return (int) apply_filters( 'bbp_update_reply_to', (int) $reply_to, $reply_id );
     
    22182220        bbpress()->max_num_pages            = $walker->max_pages;
    22192221        bbpress()->reply_query->in_the_loop = false;
    22202222}
     2223
     2224/**
     2225 * Validate a `reply_to` field for hierarchical replies
     2226 *
     2227 * Checks for 2 scenarios:
     2228 * -- The reply to ID is actually a reply
     2229 * -- The reply to ID does not match the current reply
     2230 *
     2231 * @since bbPress (r5377)
     2232 *
     2233 * @param int $reply_to
     2234 * @param int $reply_id
     2235 *
     2236 * @return int $reply_to
     2237 */
     2238function bbp_validate_reply_to( $reply_to = 0, $reply_id = 0 ) {
     2239
     2240        // The parent reply must actually be a reply
     2241        if ( ! bbp_is_reply( $reply_to ) ) {
     2242                $reply_to = 0;
     2243        }
     2244
     2245        // The parent reply cannot be itself
     2246        if ( $reply_id === $reply_to ) {
     2247                $reply_to = 0;
     2248        }
     2249
     2250        return (int) $reply_to;
     2251}
  • includes/replies/template.php

     
    24652465
    24662466                // Get $_REQUEST data
    24672467                if ( isset( $_REQUEST['bbp_reply_to'] ) ) {
    2468                         $reply_to = (int) $_REQUEST['bbp_reply_to'];
     2468                        $reply_to = bbp_validate_reply_to( $_REQUEST['bbp_reply_to'] );
    24692469                }
    24702470
    24712471                // If empty, get from meta
  • includes/topics/functions.php

     
    16721672                        }
    16731673
    16741674                        // New topic from reply can't be a reply to
    1675                         if ( ( $from_reply->ID === $destination_topic->ID && $from_reply->ID === $reply_to ) ) {
     1675                        if ( ( $from_reply->ID === $destination_topic->ID ) && ( $from_reply->ID === $reply_to ) ) {
    16761676                                bbp_update_reply_to( $reply->ID, 0 );
    16771677                        }
    16781678