Skip to:
Content

bbPress.org

Changeset 7766


Ignore:
Timestamp:
10/02/2026 07:42:39 AM (6 weeks ago)
Author:
johnjamesjacoby
Message:

Subscriptions: Preserve subscriptions on admin edits.

Move topic-subscription handling out of the generic topic and reply update functions and into the front-end form actions. This prevents WordPress admin edits and programmatic updates from changing an author's subscription without an explicit form choice.

Remove the obsolete hidden admin metabox field and add regression coverage for topic and reply saves.

In branches/2.6, for 2.6.20.

Props wpturk.
Fixes #3362.

Location:
branches/2.6
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/2.6/CHANGELOG.md

    r7750 r7766  
    1313Development for the next bbPress release is in progress. See the active
    1414[Trac milestones](https://bbpress.trac.wordpress.org/roadmap) for planned work.
     15
     16### Fixed
     17
     18- Preserved topic subscriptions when topics and replies are edited in administration.
    1519
    1620## 2.6.19 - 2026-09-29
  • branches/2.6/src/includes/admin/metaboxes.php

    r7660 r7766  
    794794function bbp_topic_subscriptions_metabox( $post ) {
    795795
    796         // Current user subscription
    797         $input_value = bbp_is_user_subscribed( bbp_get_current_user_id(), $post->ID )
    798                 ? 'bbp_subscribe' // maintain existing subscription
    799                 : '';             // do not add or remove subscription
    800 
    801796        // Get user IDs
    802797        $user_ids = bbp_get_subscribers( $post->ID );
    803798
    804799        // Output
    805         ?>
    806         <input name="bbp_topic_subscription" id="bbp_topic_subscription" type="hidden" value="<?php echo esc_attr( $input_value ); ?>" />
    807         <p><?php
     800        ?><p><?php
    808801
    809802                // Relationships
  • branches/2.6/src/includes/core/actions.php

    r7672 r7766  
    211211add_action( 'bbp_new_reply',  'bbp_update_reply', 10, 7 );
    212212add_action( 'bbp_edit_reply', 'bbp_update_reply', 10, 7 );
     213add_action( 'bbp_new_reply',  'bbp_update_reply_subscription', 10, 5 );
     214add_action( 'bbp_edit_reply', 'bbp_update_reply_subscription', 10, 5 );
    213215
    214216// Before Delete/Trash/Untrash Reply
    … …  
    226228add_action( 'bbp_new_topic',  'bbp_update_topic', 10, 5 );
    227229add_action( 'bbp_edit_topic', 'bbp_update_topic', 10, 5 );
     230add_action( 'bbp_new_topic',  'bbp_update_topic_subscription', 10, 4 );
     231add_action( 'bbp_edit_topic', 'bbp_update_topic_subscription', 10, 4 );
    228232
    229233// Split/Merge Topic
  • branches/2.6/src/includes/replies/functions.php

    r7728 r7766  
    871871        }
    872872
    873         // Handle Subscription Checkbox
    874         if ( bbp_is_subscriptions_active() && ! empty( $author_id ) && ! empty( $topic_id ) ) {
    875 
    876                 // Check if subscribed
    877                 $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
    878 
    879                 // Check for action
    880                 $subscheck  = ( ! empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' === $_POST['bbp_topic_subscription'] ) )
    881                         ? true
    882                         : false;
    883 
    884                 // Subscribed and unsubscribing
    885                 if ( ( true === $subscribed ) && ( false === $subscheck ) ) {
    886                         bbp_remove_user_subscription( $author_id, $topic_id );
    887 
    888                 // Not subscribed and subscribing
    889                 } elseif ( ( false === $subscribed ) && ( true === $subscheck ) ) {
    890                         bbp_add_user_subscription( $author_id, $topic_id );
    891                 }
    892         }
    893 
    894873        // Reply meta relating to reply position in tree
    895874        bbp_update_reply_forum_id( $reply_id, $forum_id );
  • branches/2.6/src/includes/topics/functions.php

    r7732 r7766  
    821821        }
    822822
    823         // Handle Subscription Checkbox
    824         if ( bbp_is_subscriptions_active() && ! empty( $author_id ) ) {
    825 
    826                 // Check if subscribed
    827                 $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
    828 
    829                 // Check for action
    830                 $subscheck  = ( ! empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' === $_POST['bbp_topic_subscription'] ) )
    831                         ? true
    832                         : false;
    833 
    834                 // Subscribed and unsubscribing
    835                 if ( ( true === $subscribed ) && ( false === $subscheck ) ) {
    836                         bbp_remove_user_subscription( $author_id, $topic_id );
    837 
    838                 // Not subscribed and subscribing
    839                 } elseif ( ( false === $subscribed ) && ( true === $subscheck ) ) {
    840                         bbp_add_user_subscription( $author_id, $topic_id );
    841                 }
    842         }
    843 
    844823        // Update associated topic values if this is a new topic
    845824        if ( empty( $is_edit ) ) {
  • branches/2.6/src/includes/users/engagements.php

    r7667 r7766  
    855855
    856856        return true;
     857}
     858
     859/**
     860 * Apply a topic form's subscription choice for its author.
     861 *
     862 * @since 2.6.20 bbPress (r7766)
     863 *
     864 * @param int $author_id Topic or reply author ID.
     865 * @param int $topic_id Topic ID.
     866 */
     867function bbp_update_user_topic_subscription( $author_id = 0, $topic_id = 0 ) {
     868
     869        // Bail if subscriptions are disabled or the form has no valid target
     870        if ( ! bbp_is_subscriptions_active() || empty( $author_id ) || empty( $topic_id ) ) {
     871                return;
     872        }
     873
     874        $subscribed = bbp_is_user_subscribed( $author_id, $topic_id );
     875        $subscheck  = ! empty( $_POST['bbp_topic_subscription'] ) && ( 'bbp_subscribe' === $_POST['bbp_topic_subscription'] );
     876
     877        if ( $subscribed && ! $subscheck ) {
     878                bbp_remove_user_subscription( $author_id, $topic_id );
     879        } elseif ( ! $subscribed && $subscheck ) {
     880                bbp_add_user_subscription( $author_id, $topic_id );
     881        }
     882}
     883
     884/**
     885 * Apply a topic form's subscription choice after saving the topic.
     886 *
     887 * @since 2.6.20 bbPress (r7766)
     888 *
     889 * @param int   $topic_id Topic ID.
     890 * @param int   $forum_id Forum ID.
     891 * @param array $anonymous_data Anonymous author data.
     892 * @param int   $author_id Topic author ID.
     893 */
     894function bbp_update_topic_subscription( $topic_id = 0, $forum_id = 0, $anonymous_data = array(), $author_id = 0 ) {
     895        bbp_update_user_topic_subscription( $author_id, $topic_id );
     896}
     897
     898/**
     899 * Apply a reply form's subscription choice after saving the reply.
     900 *
     901 * @since 2.6.20 bbPress (r7766)
     902 *
     903 * @param int   $reply_id Reply ID.
     904 * @param int   $topic_id Topic ID.
     905 * @param int   $forum_id Forum ID.
     906 * @param array $anonymous_data Anonymous author data.
     907 * @param int   $author_id Reply author ID.
     908 */
     909function bbp_update_reply_subscription( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = array(), $author_id = 0 ) {
     910        bbp_update_user_topic_subscription( $author_id, $topic_id );
    857911}
    858912
Note: See TracChangeset for help on using the changeset viewer.