Skip to:
Content

bbPress.org

Ticket #3213: 3213.patch

File 3213.patch, 1.9 KB (added by johnjamesjacoby, 5 years ago)
  • notifications.php

     
    189189
    190190        // Get required data
    191191        $user_id  = bp_loggedin_user_id();
    192         $topic_id = intval( $_GET['topic_id'] );
     192        $topic_id = absint( $_GET['topic_id'] );
    193193
     194        // Redirect to this topic ID by default
     195        $redirect_id = $topic_id;
     196
    194197        // Check nonce
    195198        if ( ! bbp_verify_nonce_request( 'bbp_mark_topic_' . $topic_id ) ) {
    196199                bbp_add_error( 'bbp_notification_topic_id', __( '<strong>Error</strong>: Are you sure you wanted to do that?', 'bbpress' ) );
     
    203206        // Bail if we have errors
    204207        if ( ! bbp_has_errors() ) {
    205208
    206                 // Attempt to clear notifications for the current user from this topic
    207                 $success = bp_notifications_mark_notifications_by_item_id( $user_id, $topic_id, bbp_get_component_name(), 'bbp_new_reply' );
     209                // Get these once
     210                $post_type = bbp_get_reply_post_type();
     211                $component = bbp_get_component_name();
    208212
     213                // Attempt to clear notifications for this topic
     214                $success   = bp_notifications_mark_notifications_by_item_id( $user_id, $topic_id, $component, 'bbp_new_reply' );
     215
     216                // Get all reply IDs for the topic
     217                $replies   = bbp_get_all_child_ids( $topic_id, $post_type );
     218
     219                // If topic has replies
     220                if ( ! empty( $replies ) ) {
     221
     222                        // Loop through each reply and attempt to mark it
     223                        foreach ( $replies as $reply_id ) {
     224
     225                                // Attempt to mark notification for this reply ID
     226                                $success = bp_notifications_mark_notifications_by_item_id( $user_id, $reply_id, $component, 'bbp_new_reply' );
     227
     228                                // If marked, redirect to this reply ID
     229                                if ( ! empty( $success ) ) {
     230                                        $redirect_id = $reply_id;
     231                                }
     232                        }
     233                }
     234
    209235                // Do additional subscriptions actions
    210236                do_action( 'bbp_notifications_handler', $success, $user_id, $topic_id, $action );
    211237        }
    212238
    213239        // Redirect to the topic
    214         $redirect = bbp_get_reply_url( $topic_id );
     240        $redirect = bbp_get_reply_url( $redirect_id );
    215241
    216242        // Redirect
    217243        bbp_redirect( $redirect );